dsmcad

#!/bin/sh
### BEGIN INIT INFO
# Provides: skeleton
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: dsmcad initscript
# Description: Starts and stops ISP client acceptor daemon (CAD)
### END INIT INFO
#
# 21.02.2013
# Update : 05.05.2015
# new: export LC_CTYPE=...
# update : 16.12.2016
# new: variable INSTRLOG_FUER_DSMCAD,
# dsmcad calls extended with variable INSTRLOG_FUER_DSMCAD
# update : 13.12.2017
# Location of log files
# Update : 25.05.2018
# more comments


# language environment for ISP client acceptor
# -------------------------------------------
# adjust LANG and LC_CTYPE if necessary
#
export LANG=en_US
export LC_CTYPE=en_US


# Location of log files for ISP client acceptor/ISP client scheduler
# ---------------------------------------------------------------------
# adjust errorlogname and instrlogname if necessary
# - dsmerror.log: Error messages of the ISP scheduler
# - dsminstr.log: Instrumentation log file
# - dsmsched.log: Messages of the ISP scheduler
# - dsmwebcl.log: Messages of the ISP Client Acceptor (CAD)
#
# option 'errorlogname' defines location for dsmerror.log, dsmwebcl.log
# If option 'schedlogname' not set, also for dsmsched.log
# option 'instrlogname' sets location for dsminstr.log
#
# Missing directories are created

LOG_FILES_PFAD="/usr/local/tsm/log"
ERRORLOG_FUER_DSMCAD="${LOG_FILE_PFAD}/dsmerror.log"
INSTRLOG_FUER_DSMCAD="${LOG_DATEIEN_PFAD}/dsminstr.log"

mkdir -p ${LOG_FILE_PFAD} >/dev/null 2>/dev/null


# location and name of ISP client acceptor or CLI (scheduler)
# ----------------------------------------------------------
DSM_DIR="/usr/bin"
cad_name="dsmcad"
cli_name="dsmc"
daemon="${DSM_DIR}/${cad_name}"
scheduler="${DSM_DIR}/${cli_name}"
init_script_name="${cad_name}"

# existence tests
# ------------------
[ -f ${scheduler} ] || exit 0
[ -f ${daemon} ] || exit 0

# exit script when dsmcad is started from /etc/inetd.conf
# --------------------------------------------------------------
if [ -f /etc/inetd.conf ] && grep "${cad_name}" /etc/inetd.conf >/dev/null 2>/dev/null
then
exit 0
fi

var_run_pid="/var/run/${cad_name}.pid"

case "$1" in

status) echo -n "Status Tivoli CAD: "
start-stop-daemon --start \
--pidfile ${var_run_pid} \
--make-pidfile \
--test \
--startas ${daemon} -- -errorlogname=${ERRORLOG_FUER_DSMCAD} \
-instrlogname=${INSTRLOG_FUER_DSMCAD}
if [ $? -eq 1 ]
then
echo "PID:`cat ${var_run_pid}`"
fi
echo "${init_script_name}."
;;

start) echo -n "Starting Tivoli CAD: "
start-stop-daemon --start \
--pidfile ${var_run_pid} \
--make-pidfile \
--startas ${daemon} -- -errorlogname=${ERRORLOG_FUER_DSMCAD} \
-instrlogname=${INSTRLOG_FUER_DSMCAD}
pid=$(pidof -x ${daemon})
if [ "${pid}" != "" ]
then
echo ${pid} > ${var_run_pid}
else
rm ${var_run_pid}
fi
echo "${init_script_name}."
;;

stop) echo -n "Stopping Tivoli CAD: "
start-stop-daemon --stop \
--pidfile ${var_run_pid} \
--oknodo \
--retry 30
if [ -f ${var_run_pid} ]
then
rm ${var_run_pid}
fi
echo "${init_script_name}."
;;

restart) echo -n "Restarting Tivoli CAD: "
start-stop-daemon --stop \
--pidfile ${var_run_pid} \
--oknodo \
--retry 30
if [ -f ${var_run_pid} ]
then
rm ${var_run_pid}
fi
start-stop-daemon --start \
--pidfile ${var_run_pid} \
--make-pidfile \
--startas ${daemon} -- -errorlogname=${ERRORLOG_FUER_DSMCAD} \
-instrlogname=${INSTRLOG_FUER_DSMCAD}
pid=$(pidof -x ${daemon})
if [ "${pid}" != "" ]
then
echo ${pid} > ${var_run_pid}
else
rm ${var_run_pid}
fi
echo "${init_script_name}."
;;

*) echo "Usage: /etc/init.d/${init_script_name} {start|stop|restart|status}"
exit 1
;;

esac

exit 0