#!/bin/bash
#------------------------------------------------------------
# 1C:Enterprise server configuration parameters
#------------------------------------------------------------
### BEGIN INIT INFO
# Provides: srv1cv83
# Required-Start: $local_fs $network $remote_fs $time
# Required-Stop: $local_fs $network $remote_fs $time
# Should-Start: $syslog
# Should-Stop: $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: 1C:Enterprise 8.3 server
### END INIT INFO
# 1C:Enterprise server keytab file.
# default - usr1cv83.keytab file in 1C:Enterprise server
# installation directory
#
#SRV1CV8_KEYTAB=
# Number of the cluster port created by default during first
# launch of ragent
#
# default - 1540
#
#SRV1CV8_PORT=
# Number of cluster agent main port. This port is used by the
# cluster console to address the central server. Cluster agent
# port is also specified as the IP port of the working server.
#
# default - 1541
#
#SRV1CV8_REGPORT=
# Port range for connection pool
# example values:
# 45:49
# 45:67,70:72,77:90
#
# default - 1560:1691
#
#SRV1CV8_RANGE=
# 1C:Enterprise server configuration debug mode
# 0 - default - off
# 1 - on
#
#SRV1CV8_DEBUG=
# Path to directory with claster data
# default - $HOMEDIR/.1cv83/1C/1Cv83
#
#SRV1CV8_DATA=
# Security level:
# 0 - default - unprotected connections
# 1 - protected connections only for the time of user
# authentication
# 2 - permanently protected connections
#
#SRV1CV8_SECLEV=
#------------------------------------------------------------
# end of config
#------------------------------------------------------------
#########################################
########### init starts here ############
#########################################
# chkconfig: 35 74 36
# description: Starts and stops the 1C:Enterprise daemons
#------------------------------------------------------------
# global macros. generated by install script
#------------------------------------------------------------
G_CONF_STYLE=deb
G_VER_ARCH=x86_64
G_VER_MAJOR=8
G_VER_MINOR=3
G_VER_BUILD=5
G_VER_RELEASE=1248
G_BINDIR="/opt/1C/v${G_VER_MAJOR}.${G_VER_MINOR}/${G_VER_ARCH}"
#------------------------------------------------------------
G_VER_SHORT=${G_VER_MAJOR}.${G_VER_MINOR}
G_TITLE="1C:Enterprise ${G_VER_SHORT} server"
#------------------------------------------------------------
# this values can be passed from outside, so perform "z-check"
#------------------------------------------------------------
[ -z "$SRV1CV8_USER" ] && SRV1CV8_USER=usr1cv8
[ -z "$SRV1CV8_BINDIR" ] && SRV1CV8_BINDIR="$G_BINDIR"
[ -z "$SRV1CV8_PIDFILE" ] && SRV1CV8_PIDFILE="/var/run/srv1cv${G_VER_MAJOR}${G_VER_MINOR}.pid"
[ -z "$SRV1CV8_KEYTAB" ] && SRV1CV8_KEYTAB="$SRV1CV8_BINDIR/$SRV1CV8_USER.keytab"
[ -z "$SRV1CV8_WAITSTART" ] && SRV1CV8_WAITSTART=5
[ -z "$SRV1CV8_WAITSTOP" ] && SRV1CV8_WAITSTOP=5
#------------------------------------------------------------
# builds ragent's command line from configuration parameters
#------------------------------------------------------------
function buildCommandLine() {
local cmdline="$SRV1CV8_BINDIR/ragent -daemon"
[ ! -z "$SRV1CV8_PORT" ] && cmdline="$cmdline -port $SRV1CV8_PORT"
[ ! -z "$SRV1CV8_REGPORT" ] && cmdline="$cmdline -regport $SRV1CV8_REGPORT"
[ ! -z "$SRV1CV8_DATA" ] && cmdline="$cmdline -d \"$SRV1CV8_DATA\""
[ ! -z "$SRV1CV8_RANGE" ] && cmdline="$cmdline -range $SRV1CV8_RANGE"
[ ! -z "$SRV1CV8_SECLEV" ] && cmdline="$cmdline -seclev $SRV1CV8_SECLEV"
[ "x$SRV1CV8_DEBUG" == "x1" ] && cmdline="$cmdline -debug"
echo $cmdline
}
#------------------------------------------------------------
# checks if process with passed pid exists
#------------------------------------------------------------
function checkpid() {
ps -p $* > /dev/null
}
#------------------------------------------------------------
# waits SRV1CV8_WAITSTOP seconds for process termination,
# then kills it
#------------------------------------------------------------
function delayedkill() {
local mypid=$1
local delay=$2
kill $mypid 2>/dev/null
checkpid $mypid && sleep $delay || return 0
if checkpid $mypid; then
kill -9 $mypid
logWarning "Process refused to die... So it was killed. May be you should increase SRV1CV8_WAITSTOP variable?";
fi
return 0
}
#------------------------------------------------------------
# extracts specified param from value from given command-line
#------------------------------------------------------------
function extractParam() {
local param=$1
shift
local tmp=$*
if [ ! -z "$*" ]; then
if [ ${tmp:0:1} == "-" ]; then
tmp=${tmp:1}
local val=${tmp#*$param }
# if old and new strings are equal
# we don't have needed param in cmdline
# so return
[ "$val" == "$tmp" ] && return;
val=${val%% -*}
echo "$val"
fi
fi
}
#------------------------------------------------------------
# call it when something fails
#------------------------------------------------------------
function failure() {
[ "$BOOTUP" != "verbose" -a -z "$LSB" ] && echo FAILED
return 0
}
#------------------------------------------------------------
# extracts data dir from ragent's command line or (if it's
# empty), builds it from users's home dir
#------------------------------------------------------------
function getDataDir() {
local cmdline=`getRagentRealCmdLine`
local datadir="$SRV1CV8_DATA"
[ ! -z "$cmdline" ] && datadir=`extractParam d $cmdline`
if [ -z "$datadir" ]; then
local line=`grep ^$SRV1CV8_USER: /etc/passwd`
local homedir=${line#*:*:*:*:*:}
homedir=${homedir%:*}
datadir="$homedir/.1cv${G_VER_MAJOR}${G_VER_MINOR}/1C/1Cv${G_VER_MAJOR}${G_VER_MINOR}"
fi
echo $datadir
}
#------------------------------------------------------------
# returns ragent configuration debug flag
#------------------------------------------------------------
function getDebugStatus() {
local cmdline=`getRagentRealCmdLine`
local debugFlag="$SRV1CV8_DEBUG"
echo "$cmdline" | grep "\-debug" >/dev/null && debugFlag="1"
[ ! -z "$debugFlag" ] && echo $debugFlag || echo "0"
}
#------------------------------------------------------------
# returns ragent port range
#------------------------------------------------------------
function getPortRange() {
local cmdline=`getRagentRealCmdLine`
local range="$SRV1CV8_RANGE"
[ ! -z "$cmdline" ] && range=`extractParam range $cmdline`
[ ! -z "$range" ] && echo $range || echo 1560:1591
}
#------------------------------------------------------------
# returns ragent main port
#------------------------------------------------------------
function getRagentPort() {
local cmdline=`getRagentRealCmdLine`
local port="$SRV1CV8_PORT"
[ ! -z "$cmdline" ] && port=`extractParam port $cmdline`
[ ! -z "$port" ] && echo $port || echo 1540
}
#------------------------------------------------------------
# get's running ragent command-line
#------------------------------------------------------------
function getRagentRealCmdLine() {
local cmdline=`buildCommandLine`
local mypid=`getRagentPid "$SRV1CV8_USER" "$cmdline"`
local result=""
[ ! -z "$mypid" ] && result=`ps --pid $mypid -o cmd= | sed -e "s/.*-daemon//"`
echo "$result"
}
#------------------------------------------------------------
# tries to get pid of ragent process, started by this script
#------------------------------------------------------------