Skip to content

Instantly share code, notes, and snippets.

@holysoros holysoros/sushi.sh

Created Mar 22, 2019
Embed
What would you like to do?
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
You can’t perform that action at this time.