refactor cetus.service

This commit is contained in:
tsthght 2018-10-22 22:16:45 +08:00
parent cc35f360b8
commit 604401e1f2

View File

@ -4,11 +4,16 @@
# Source Function Library # Source Function Library
. /etc/init.d/functions . /etc/init.d/functions
STARTTIMEOUT=12
STOPTIMEOUT=60
# Cetus Settings # Cetus Settings
CETUS_HOME=/usr/local CETUS_HOME=/usr/local
CETUS_CONF=${CETUS_HOME}/conf/proxy.conf CETUS_CONF=${CETUS_HOME}/conf/proxy.conf
CETUS_SBIN=${CETUS_HOME}/bin/cetus CETUS_SBIN=${CETUS_HOME}/bin/cetus
CETUS_PID=${CETUS_HOME}/cetus.pid CETUS_PID=${CETUS_HOME}/cetus.pid
CETUS_LOG=${CETUS_HOME}/cetus.log
CETUS_EXEC=${CETUS_HOME}/libexec/cetus
CETUS_DAEMON="0" CETUS_DAEMON="0"
cetus_pid=`sed '/^pid-file=/!d;s/.*=//' ${CETUS_CONF}` cetus_pid=`sed '/^pid-file=/!d;s/.*=//' ${CETUS_CONF}`
@ -21,29 +26,91 @@ if [ "$cetus_daemon" != "" ];then
CETUS_DAEMON=$cetus_daemon CETUS_DAEMON=$cetus_daemon
fi fi
cetus_log=`sed '/^log-file=/!d;s/.*=//' ${CETUS_CONF}`
if [ "$cetus_log" != "" ];then
CETUS_LOG=$cetus_log
fi
start() { start() {
echo -n $"Starting $prog ... " [ -x $CETUS_EXEC ] || exit 5
if [ "${CETUS_DAEMON}" == "0" ];then if [ -f "$CETUS_PID" ];then
nohup ${CETUS_SBIN} --defaults-file=${CETUS_CONF} >/dev/null 2>&1 & CETUSPID=$(cat $CETUS_PID)
else if [ -n "$CETUSPID" ];then
daemon ${CETUS_SBIN} --defaults-file=${CETUS_CONF} /bin/kill -0 "$CETUSPID" >/dev/null 2>&1
fi
RETVAL=$? RETVAL=$?
echo if [ $RETVAL -eq 0 ];then
# already running
action $"Starting $prog: " /bin/true
return $RETVAL
fi
fi
fi
if [ "${CETUS_DAEMON}" == "0" ];then
${CETUS_SBIN} --defaults-file=${CETUS_CONF} >/dev/null 2>&1 &
else
${CETUS_SBIN} --defaults-file=${CETUS_CONF} >/dev/null 2>&1
fi
TIMEOUT="$STARTTIMEOUT"
while [ $TIMEOUT -gt 0 ]; do
CETUSPID=$(cat $CETUS_PID)
/bin/kill -0 "$CETUSPID" >/dev/null 2>&1
RETVAL=$?
if [ $RETVAL -eq 0 ];then
break
fi
sleep 0.5
let TIMEOUT=${TIMEOUT}-1
done
if [ $TIMEOUT -eq 0 ];then
echo "Timeout error occurred trying to start Cetus"
fi
if [ $RETVAL -eq 0 ];then
action $"Starting $prog: " /bin/true
else
echo "please see ${CETUS_LOG}"
action $"Starting $prog: " /bin/false
fi
return $RETVAL
} }
stop() { stop() {
echo -n $"Stopping $prog ... " if [ ! -f "$CETUS_PID" ];then
if [ -e ${CETUS_PID} ]; then # not running
daemon kill -INT $(cat ${CETUS_PID}) action $"Stopping $prog: " /bin/true
RETVAL=$? return 0
fi fi
echo CETUSPID=$(cat $CETUS_PID)
if [ -n "$CETUSPID" ];then
/bin/kill "$CETUSPID" >/dev/null 2>&1
RETVAL=$?
if [ $RETVAL -eq 0 ] ;then
TIMEOUT="$STOPTIMEOUT"
while [ $TIMEOUT -gt 0 ]; do
/bin/kill -0 "$CETUSPID" >/dev/null 2>&1 ||break
sleep 0.5
let TIMEOUT=${TIMEOUT} -1
done
if [ $TIMEOUT -eq 0 ];then
echo "Timeout error occurred trying to stop Cetus."
RETVAL=1
action $"Stopping $prog: " /bin/false
else
action $"Stopping $prog: " /bin/true
fi
else
echo "kill cetus(pid=$CETUSPID) failed, cetus may not be running"
action $"Stopping $prog: " /bin/false
fi
else
echo "cetus's pidfile is null, $CETUS_PID"
action $"Stopping $prog: " /bin/false
RETVAL=4
fi
return $RETVAL
} }
restart(){ restart(){
stop stop
sleep 1
start start
} }