Created
January 23, 2017 03:14
-
-
Save kuoruan/20238397c770cc7aa6bac29e152b64c5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
### BEGIN INIT INFO | |
# Provides: circusd | |
# Required-Start: $remote_fs $network | |
# Required-Stop: $remote_fs $network | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: circus master control daemon | |
# Description: This is a daemon that controls the circus minions | |
### END INIT INFO | |
# Author: Roman Imankulov <[email protected]> | |
PATH=/sbin:/usr/sbin:/bin:/usr/bin | |
DESC="circus daemon" | |
NAME=circusd | |
DAEMON=/usr/bin/circusd | |
PIDFILE=/var/run/$NAME.pid | |
CONFIG=/etc/circus/circusd.ini | |
DAEMON_ARGS="--daemon --pidfile $PIDFILE $CONFIG" | |
SCRIPTNAME=/etc/init.d/$NAME | |
# Exit if the package is not installed | |
[ -x "$DAEMON" ] || exit 0 | |
# Read configuration variable file if it is present | |
[ -r /etc/default/$NAME ] && . /etc/default/$NAME | |
. /lib/init/vars.sh | |
. /lib/lsb/init-functions | |
do_start() { | |
pid=$(pidofproc -p $PIDFILE $DAEMON) | |
if [ -n "$pid" ] ; then | |
log_begin_msg "$DESC already running." | |
log_end_msg 0 | |
exit 0 | |
fi | |
log_daemon_msg "Starting circusd daemon: " | |
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS | |
log_end_msg $? | |
} | |
do_stop() { | |
log_begin_msg "Stopping $DESC ..." | |
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE | |
RC=$? | |
[ $RC -eq 0 ] && rm -f $PIDFILE | |
log_end_msg $RC | |
} | |
case "$1" in | |
start) | |
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" | |
do_start | |
case "$?" in | |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; | |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; | |
esac | |
;; | |
stop) | |
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" | |
do_stop | |
case "$?" in | |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; | |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; | |
esac | |
;; | |
status) | |
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? | |
;; | |
#reload) | |
# not implemented | |
#;; | |
restart|force-reload) | |
log_daemon_msg "Restarting $DESC" "$NAME" | |
do_stop | |
case "$?" in | |
0|1) | |
do_start | |
case "$?" in | |
0) log_end_msg 0 ;; | |
1) log_end_msg 1 ;; # Old process is still running | |
*) log_end_msg 1 ;; # Failed to start | |
esac | |
;; | |
*) | |
# Failed to stop | |
log_end_msg 1 | |
;; | |
esac | |
;; | |
*) | |
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 | |
exit 3 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment