Skip to content

Instantly share code, notes, and snippets.

@r6m
Created November 8, 2015 04:57
Show Gist options
  • Save r6m/946d190107fc0a35fe23 to your computer and use it in GitHub Desktop.
Save r6m/946d190107fc0a35fe23 to your computer and use it in GitHub Desktop.
#!/bin/sh
### BEGIN INIT INFO
# Provides: puma app runner
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the puma web server
# Description: starts the puma web server
### END INIT INFO
# app settings
USER="user"
APP_NAME="app"
APP_ROOT="/home/$USER/apps/$APP_NAME"
PID="$APP_ROOT/tmp/puma/puma.pid"
STATE="$APP_ROOT/tmp/puma/puma.state"
# make sure the app exists
cd $APP_ROOT || exit 1
case "$1" in
start)
echo "Starting $APP_NAME"
sudo -u $USER -H bash -l -c "bundle exec puma -C config/puma.rb -e production -d"
;;
stop)
echo "Stopping $APP_NAME"
sudo -u $USER -H bash -l -c "bundle exec pumactl -S $STATE stop"
;;
restart)
echo "Restarting $APP_NAME"
sudo -u $USER -H bash -l -c "bundle exec pumactl -S $STATE restart"
;;
status)
echo "$APP_NAME Status"
sudo -u $USER -H bash -l -c "bundle exec pumactl -S $STATE status"
;;
force-stop)
echo "Terminating $APP_NAME"
sudo -u $USER -H bash -l -c "bundle exec pumactl -S $STATE halt"
;;
*)
echo "Usage: $0 {start|stop|force-stop|restart|status}"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment