Last active
December 15, 2015 08:39
-
-
Save kerphi/5232109 to your computer and use it in GitHub Desktop.
This file contains 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 | |
### BEGIN INIT INFO | |
# Provides: log.io-harvester | |
# Required-Start: $local_fs $remote_fs $network $syslog | |
# Required-Stop: $local_fs $remote_fs $network $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Start and stop the log.io-harvester daemon | |
### END INIT INFO | |
export HOME="/root" | |
. /etc/profile | |
[ -z "$SCRIPT_NAME" ] && SCRIPT_NAME="log.io-harvester" | |
[ -z "$SCRIPT_CMD" ] && SCRIPT_CMD="`which $SCRIPT_NAME`" | |
[ -z "$SCRIPT_PIDFILE" ] && SCRIPT_PIDFILE="/var/run/$SCRIPT_NAME.pid" | |
[ -z "$FOREVER_CMD" ] && FOREVER_CMD="`which forever`" | |
daemon_start() { | |
$FOREVER_CMD start --pidFile $SCRIPT_PIDFILE $SCRIPT_CMD 1>/dev/null | |
} | |
daemon_stop() { | |
$FOREVER_CMD stop $SCRIPT_CMD 1>/dev/null | |
} | |
daemon_restart() { | |
$FOREVER_CMD restart $SCRIPT_CMD 1>/dev/null | |
} | |
case $1 in | |
start) | |
if [[ -f $SCRIPT_PIDFILE && -d /proc/`cat $SCRIPT_PIDFILE` ]]; then | |
echo "$SCRIPT_NAME is already running." | |
exit 0 | |
else | |
daemon_start | |
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do | |
if [ -f $SCRIPT_PIDFILE ]; then | |
break | |
fi | |
sleep 1 | |
done | |
if [ -d /proc/`cat $SCRIPT_PIDFILE` ]; then | |
echo "$SCRIPT_NAME started." | |
exit 0 | |
else | |
echo "$SCRIPT_NAME cannot be started." | |
exit 1 | |
fi | |
fi | |
;; | |
stop) | |
if [[ ! -f $SCRIPT_PIDFILE || ! -d /proc/`cat $SCRIPT_PIDFILE` ]]; then | |
echo "$SCRIPT_NAME is already stopped." | |
exit 0 | |
else | |
daemon_stop | |
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do | |
if [ ! -d /proc/`cat $SCRIPT_PIDFILE` ]; then | |
break | |
fi | |
sleep 1 | |
done | |
if [ -d /proc/`cat $SCRIPT_PIDFILE` ]; then | |
echo "$SCRIPT_NAME cannot be stopped." | |
exit 1 | |
else | |
echo "$SCRIPT_NAME is stopped." | |
rm -f $SCRIPT_PIDFILE 2>/dev/null | |
exit 0 | |
fi | |
fi | |
;; | |
restart | reload | force-reload) | |
if [[ ! -f $SCRIPT_PIDFILE || ! -d /proc/`cat $SCRIPT_PIDFILE` ]]; then | |
PID=0 | |
daemon_start | |
else | |
PID=`cat $SCRIPT_PIDFILE` | |
daemon_restart | |
fi | |
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do | |
if [[ -f $SCRIPT_PIDFILE && "$PID" != "`cat $SCRIPT_PIDFILE`" ]]; then | |
break | |
fi | |
sleep 1 | |
done | |
if [ -d /proc/`cat $SCRIPT_PIDFILE` ]; then | |
echo "$SCRIPT_NAME has been restarted." | |
exit 0 | |
else | |
echo "$SCRIPT_NAME cannot be restarted." | |
exit 1 | |
fi | |
;; | |
status) | |
if [[ -f $SCRIPT_PIDFILE && -d /proc/`cat $SCRIPT_PIDFILE` ]]; then | |
echo "$SCRIPT_NAME is running." | |
exit 0 | |
else | |
echo "$SCRIPT_NAME is not running." | |
exit 1 | |
fi | |
;; | |
*) | |
echo "Usage: $0 {start|stop|restart|status}" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment