Commit 61b4f9a5 authored by Erick Hitter's avatar Erick Hitter
Browse files

Improve init script by supporting all LSB requirements

parent fde89251
DEPLOY_DIR="/var/www/cron-control-runner"
CMD="${DEPLOY_DIR}/runner"
CMD_ARGS="-workers-run 10"
# DAEMON_ARGS="-workers-run 10"
......@@ -2,69 +2,86 @@
### BEGIN INIT INFO
# Provides: cron-control-runner
# Required-Start: $network $local_fs
# Required-Stop:
# Required-Stop: $network $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Runner for Cron Control events
# Description: Automattic Inc
#### END INIT INFO
# Description: Runner for Cron Control events
### END INIT INFO
. /lib/lsb/init-functions
NAME=cron-control-runner
USER=www-data
DEPLOY_DIR="/var/lib/cron_control_runner"
CMD="${DEPLOY_DIR}/runner"
CMD_ARGS=""
########## Common
PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH
SSD=start-stop-daemon
PID=/var/run/${NAME}.pid
DAEMON="/usr/local/bin/${NAME}"
DAEMON_ARGS=""
PIDFILE="/var/run/${NAME}.pid"
########## Overrides
# Overrides
[ -f "/etc/default/$NAME" ] && . /etc/default/$NAME
start () {
echo "Starting $NAME"
$SSD --start --chuid $USER --pidfile $PID --make-pidfile --background -d $DEPLOY_DIR --exec $CMD -- $CMD_ARGS
RETVAL=$?
echo
return $RETVAL
}
stop () {
echo "Stopping $NAME"
$SSD --stop --oknodo --pidfile $PID
RETVAL=$?
echo
return $RETVAL
}
restart () {
stop
sleep 1
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
echo "not supported"
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
# If the daemon is not there, then exit.
test -x $DAEMON || exit 5
exit $RETVAL
case $1 in
start)
# Checked the PID file exists and check the actual status of process
if [ -e $PIDFILE ]; then
status_of_proc -p $PIDFILE $DAEMON "$NAME process" && status="0" || status="$?"
# If the status is SUCCESS then don't need to start again.
if [ $status = "0" ]; then
exit # Exit
fi
fi
# Start the daemon.
log_daemon_msg "Starting the process" "$NAME"
# Start the daemon with the help of start-stop-daemon
# Log the message appropriately
if start-stop-daemon --start --chuid $USER --background --oknodo --pidfile $PIDFILE --make-pidfile --exec $DAEMON -- $DAEMON_ARGS; then
log_end_msg 0
else
log_end_msg 1
fi
;;
stop)
# Stop the daemon.
if [ -e $PIDFILE ]; then
status_of_proc -p $PIDFILE $DAEMON "Stoppping the $NAME process" && status="0" || status="$?"
if [ "$status" = 0 ]; then
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
/bin/rm -rf $PIDFILE
fi
else
log_daemon_msg "$NAME process is not running"
log_end_msg 0
fi
;;
restart)
# Restart the daemon.
$0 stop && sleep 2 && $0 start
;;
status)
# Check the status of the process.
if [ -e $PIDFILE ]; then
status_of_proc -p $PIDFILE $DAEMON "$NAME process" && exit 0 || exit $?
else
log_daemon_msg "$NAME Process is not running"
log_end_msg 0
fi
;;
reload)
# Reload the process. Basically sending some signal to a daemon to reload
# it configurations.
if [ -e $PIDFILE ]; then
start-stop-daemon --stop --signal USR1 --quiet --pidfile $PIDFILE --name $NAME
log_success_msg "$NAME process reloaded successfully"
else
log_failure_msg "$PIDFILE does not exists"
fi
;;
*)
# For invalid arguments, print the usage message.
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 2
;;
esac
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment