Created
July 28, 2014 15:59
-
-
Save piavlo/2ae33622b7c4281a725c to your computer and use it in GitHub Desktop.
alternative uchiwa init.d script - depends on http://software.clapper.org/daemonize/
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/bash | |
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin | |
DESC="Uchiwa Sensu Dashboard" | |
UCHIWA_USER=uchiwa | |
DAEMON=/opt/uchiwa/embedded/bin/node | |
CONFIG="/etc/sensu/uchiwa.js" | |
LOGDIR="/var/log/uchiwa" | |
SCRIPTNAME=/etc/init.d/uchiwa | |
PIDFILE="/var/run/uchiwa.pid" | |
LOCKFILE="/var/run/lock/uchiwa" | |
WORKDIR=/opt/uchiwa/usr/src/uchiwa | |
SHUTDOWN_TIMEOUT=1 | |
[ -e /etc/default/uchiwa ] && . /etc/default/uchiwa | |
CMD="${DAEMON} app.js --config $CONFIG" | |
. /lib/lsb/init-functions | |
start() { | |
log_daemon_msg "Starting $DESC: " | |
daemonize -c $WORKDIR -u $UCHIWA_USER -p $PIDFILE -l $LOCKFILE -o $LOGDIR/stdout -e $LOGDIR/stderr $CMD | |
log_end_msg $? | |
} | |
stop(){ | |
[ -e "$PIDFILE" ] && [ ! -z "$(cat $PIDFILE)" ] && test -d "/proc/$(cat $PIDFILE)" && kill -SIGTERM $(cat $PIDFILE) | |
log_daemon_msg "Stopping $DESC: " | |
flock --exclusive --timeout $SHUTDOWN_TIMEOUT $LOCKFILE --command "echo -n" | |
log_end_msg $? | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
stop | |
sleep 0.1 | |
start | |
;; | |
*) | |
echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2 | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment