Skip to content

Instantly share code, notes, and snippets.

@holysoros
Created March 22, 2019 08:24
Show Gist options
  • Save holysoros/36d6039b58fec60186c3dd1dab43caca to your computer and use it in GitHub Desktop.
Save holysoros/36d6039b58fec60186c3dd1dab43caca to your computer and use it in GitHub Desktop.
A linux daemon init script
#!/bin/sh
set -e
DEPLOY_DIR="$( cd "$( dirname $0 )" && pwd )"
NAME=sushi
PIDFILE=${DEPLOY_DIR}/tmp/$NAME.pid
#This is the command to be run, give the full pathname
DAEMON=${DEPLOY_DIR}/${NAME}
getLatestAvroModel() {
ls -cA1 ${MODEL_PATH}/avro/* | head -n1
}
case "$1" in
start)
echo -n "Starting daemon: "$NAME
MODEL_FILE=$(getLatestAvroModel)
start-stop-daemon --start --quiet --make-pidfile --pidfile $PIDFILE --background --exec $DAEMON ${MODEL_FILE} ${DEPLOY_DIR}/sushi.log
echo "."
;;
stop)
echo -n "Stopping daemon: "$NAME
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
rm -f $PIDFILE
echo "."
;;
restart)
echo -n "Restarting daemon: "$NAME
start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $PIDFILE
rm -f $PIDFILE
start-stop-daemon --start --quiet --make-pidfile --pidfile $PIDFILE --background --exec $DAEMON
echo "."
;;
*)
echo "Usage: "$1" {start|stop|restart}"
exit 1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment