Last active
January 8, 2016 22:47
-
-
Save jim80net/6ca031823ae84764e361 to your computer and use it in GitHub Desktop.
BOSH102 app_ctl
This file contains hidden or 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 | |
| JOB_NAME=app | |
| RUN_DIR=/var/vcap/sys/run/$JOB_NAME | |
| LOG_DIR=/var/vcap/sys/log/$JOB_NAME | |
| CONFIG_DIR=/var/vcap/jobs/$JOB_NAME/config | |
| EPHEMERAL=/var/vcap/data/$JOB_NAME | |
| PERSISTENT=/var/vcap/store/$JOB_NAME | |
| PIDFILE=$RUN_DIR/$JOB_NAME.pid | |
| RUNAS=vcap | |
| exec 1>> $LOG_DIR/$JOB_NAME.stdout.log | |
| exec 2>> $LOG_DIR/$JOB_NAME.stderr.log | |
| case $1 in | |
| start) | |
| mkdir -p $RUN_DIR $LOG_DIR $EPHEMERAL | |
| chown -R $RUNAS:$RUNAS $RUN_DIR $LOG_DIR $EPHEMERAL $PERSISTENT | |
| ## Start Code Here | |
| PATH=$PATH:/var/vcap/packages/ruby/bin/ | |
| gem install sinatra | |
| echo $$ > $PIDFILE | |
| exec ruby /var/vcap/packages/app/app.rb -o 0.0.0.0 -p 80 | |
| ;; | |
| stop) | |
| PID=$(cat $PIDFILE) | |
| if [ -n $PID ]; then | |
| SIGNAL=TERM | |
| N=1 | |
| while kill -$SIGNAL $PID 2>/dev/null; do | |
| if [ $N -eq 1 ]; then | |
| echo "waiting for pid $PID to die" | |
| fi | |
| if [ $N -eq 11 ]; then | |
| echo "giving up on pid $PID with kill -TERM; trying -KILL" | |
| SIGNAL=KILL | |
| fi | |
| if [ $N -gt 20 ]; then | |
| echo "giving up on pid $PID" | |
| break | |
| fi | |
| N=$(($N+1)) | |
| sleep 1 | |
| done | |
| fi | |
| ;; | |
| *) | |
| echo "Usage: app_ctl {start|stop}" ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment