Skip to content

Instantly share code, notes, and snippets.

@jfuerth
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save jfuerth/556252f9961d7c855f83 to your computer and use it in GitHub Desktop.

Select an option

Save jfuerth/556252f9961d7c855f83 to your computer and use it in GitHub Desktop.
control script with restart protection
#!/bin/bash
RUN_DIR=/var/vcap/sys/run/hello-go
LOG_DIR=/var/vcap/sys/log/hello-go
PIDFILE=${RUN_DIR}/pid
case $1 in
start)
mkdir -p $RUN_DIR $LOG_DIR
chown -R vcap:vcap $RUN_DIR $LOG_DIR
if [ -f $PIDFILE ]; then
pid=`head -1 $PIDFILE`
if ps awwx | grep "^${pid}[ ].*hello-go"; then
echo "hello-go is already running with PID $pid"
exit 0
fi
fi
echo $$ > $PIDFILE
cd /var/vcap/packages/hello-go
exec /var/vcap/packages/hello-go/bin/hello-go \
>> $LOG_DIR/hello-go.stdout.log \
2>> $LOG_DIR/hello-go.stderr.log
;;
stop)
kill -9 `cat $PIDFILE`
rm -f $PIDFILE
;;
*)
echo "Usage: ctl {start|stop}" ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment