Last active
December 27, 2015 12:49
-
-
Save kikumoto/7329032 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# | |
# MyApp | |
# chkconfig: 2345 82 55 | |
# processname: puma | |
# description: Runs puma for nginx integration. | |
# Include RedHat function library | |
. /etc/rc.d/init.d/functions | |
# The name of the service | |
NAME=myapp | |
# The username and path to the myapp source | |
USER=rails | |
APP_PATH=/home/$USER/myapp | |
# The PID and LOCK files used by puma and sidekiq | |
UPID=$APP_PATH/tmp/pids/puma.pid | |
ULOCK=/var/lock/subsys/puma | |
# The options to use when running puma | |
OPTS="-C $APP_PATH/config/puma.rb -e production" | |
# Ruby related path update | |
RUBY_PATH_PATCH="PATH=/home/$USER/.rbenv/shims:$PATH:/usr/local/bin:/usr/local/lib && export PATH && " | |
start() { | |
cd $APP_PATH | |
# Start puma | |
echo -n $"Starting puma: " | |
daemon --pidfile=$UPID --user=$USER "$RUBY_PATH_PATCH bundle exec puma $OPTS" | |
puma=$? | |
[ $puma -eq 0 ] && touch $ULOCK | |
echo | |
return $puma | |
} | |
stop() { | |
cd $APP_PATH | |
# Stop puma | |
echo -n $"Stopping puma: " | |
killproc -p $UPID | |
puma=$? | |
[ $puma -eq 0 ] && rm -f $ULOCK | |
echo | |
return $puma | |
} | |
restart() { | |
stop | |
start | |
} | |
get_status() { | |
status -p $UPID puma | |
} | |
query_status() { | |
get_status >/dev/null 2>&1 | |
} | |
case "$1" in | |
start) | |
query_status && exit 0 | |
start | |
;; | |
stop) | |
query_status || exit 0 | |
stop | |
;; | |
restart) | |
restart | |
;; | |
status) | |
get_status | |
;; | |
*) | |
N=/etc/init.d/$NAME | |
echo "Usage: $N {start|stop|restart|status}" >&2 | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment