Skip to content

Instantly share code, notes, and snippets.

@keith-miller
Last active August 29, 2015 14:06
Show Gist options
  • Save keith-miller/df2e89d0bf97951290f6 to your computer and use it in GitHub Desktop.
Save keith-miller/df2e89d0bf97951290f6 to your computer and use it in GitHub Desktop.
Play 2.x service script
#!/bin/sh
DESC="Play application service"
NAME=play-application-service
PIDFILE=/opt/$NAME/RUNNING_PID
# result of operation
result=0
# Load the helper fuctions
. /etc/init.d/functions
# Load the command line params
. /etc/$NAME/app.args
confirm() {
if [ $1 == 0 ]; then
success
else
failure
fi
}
start() {
if [ -f $PIDFILE ] ; then
echo -n "$NAME already started!"
result=1
else
echo -n "Starting $DESC: $NAME"
nohup bash -c "/opt/$NAME/start $APP_ARGS -Dconfig.file=/etc/$NAME/application.conf &> /var/log/$NAME 2>&1" &> /var/log/$NAME &
result=$?
confirm $result
fi
}
stop() {
if [ ! -f $PIDFILE ] ; then
echo -n "$NAME not started!"
result=1
else
pid=`cat $PIDFILE 2> /dev/null`
if [ "$pid" == "" ]; then
echo -n "$NAME not started!"
result=1
else
echo -n "Stopping $DESC: $NAME"
kill $pid
result=$?
confirm $result
fi
fi
}
status() {
if [ -f $PIDFILE ] ; then
echo -n "$NAME is running!"
result=0
else
echo -n "$NAME not started!"
result=1
fi
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
if [ -f $PIDFILE ] ; then
echo -n "Restarting $DESC: $NAME"
stop
sleep 1
start
else
echo -n "$NAME not started!"
result=1
fi
;;
status)
status
;;
*)
echo "usage: $NAME {start|stop|restart|status}"
result=1
;;
esac
echo
exit $result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment