Skip to content

Instantly share code, notes, and snippets.

@runeleaf
Created January 15, 2016 12:12
Show Gist options
  • Save runeleaf/c9afa8efdc08f2d958ca to your computer and use it in GitHub Desktop.
Save runeleaf/c9afa8efdc08f2d958ca to your computer and use it in GitHub Desktop.
/etc/init.d/puma
#!/bin/bash
#
# puma-myproject
# chkconfig: 2345 82 55
# processname: puma-myproject
# description: Runs puma-myproject for nginx integration.
# Include RedHat function library
. /etc/rc.d/init.d/functions
# The name of the service
NAME=puma
# The username and path to the myapp source
USER=deployer
APP_PATH=/var/www/vhost/uketoru-tracker/current
# The PID and LOCK files used by puma and sidekiq
UPID=$APP_PATH/tmp/pids/puma.pid
ULOCK=/var/lock/subsys/$NAME
# The options to use when running puma
OPTS="-F $APP_PATH/config/puma.rb"
# Ruby related path update
RUBY_PATH_PATCH="PATH=$PATH:/usr/local/bin:/usr/local/lib && export PATH && "
BUNDLE_CMD=bundle
PUMA_CMD=pumactl
. /etc/profile.d/rbenv.sh
start() {
cd $APP_PATH
# Start puma
echo -n $"Starting $NAME: "
daemon --pidfile=$UPID --user=$USER $BUNDLE_CMD exec $PUMA_CMD $OPTS start
puma=$?
[ $puma -eq 0 ] && touch $ULOCK
echo
return $puma
}
stop() {
cd $APP_PATH
# Stop puma
echo -n $"Stopping $NAME: "
killproc -p $UPID
puma=$?
[ $puma -eq 0 ] && rm -f $ULOCK
echo
return $puma
}
restart() {
stop
start
}
get_status() {
status -p $UPID $NAME
}
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
exit $?
;;
*)
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