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
. /etc/init.d/functions
STARTTIMEOUT=12
STOPTIMEOUT=60
# Cetus Settings
CETUS_HOME=/usr/local
CETUS_CONF=${CETUS_HOME}/conf/proxy.conf
CETUS_SBIN=${CETUS_HOME}/bin/cetus
CETUS_PID=${CETUS_HOME}/cetus.pid
CETUS_LOG=${CETUS_HOME}/cetus.log
CETUS_EXEC=${CETUS_HOME}/libexec/cetus
CETUS_DAEMON="0"
cetus_pid=`sed '/^pid-file=/!d;s/.*=//' ${CETUS_CONF}`
@ -21,29 +26,91 @@ if [ "$cetus_daemon" != "" ];then
CETUS_DAEMON=$cetus_daemon
fi
cetus_log=`sed '/^log-file=/!d;s/.*=//' ${CETUS_CONF}`
if [ "$cetus_log" != "" ];then
CETUS_LOG=$cetus_log
fi
start() {
echo -n $"Starting $prog ... "
if [ "${CETUS_DAEMON}" == "0" ];then
nohup ${CETUS_SBIN} --defaults-file=${CETUS_CONF} >/dev/null 2>&1 &
else
daemon ${CETUS_SBIN} --defaults-file=${CETUS_CONF}
fi
[ -x $CETUS_EXEC ] || exit 5
if [ -f "$CETUS_PID" ];then
CETUSPID=$(cat $CETUS_PID)
if [ -n "$CETUSPID" ];then
/bin/kill -0 "$CETUSPID" >/dev/null 2>&1
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() {
echo -n $"Stopping $prog ... "
if [ -e ${CETUS_PID} ]; then
daemon kill -INT $(cat ${CETUS_PID})
RETVAL=$?
if [ ! -f "$CETUS_PID" ];then
# not running
action $"Stopping $prog: " /bin/true
return 0
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(){
stop
sleep 1
start
}