Last active
April 23, 2017 02:01
-
-
Save ggoral/129b40515acb2d1c1c5e 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/sh | |
### BEGIN INIT INFO | |
# Provides: puma | |
# Required-Start: $all | |
# Required-Stop: $all | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: starts the puma app server | |
# Description: starts puma using start-stop-daemon | |
### END INIT INFO | |
set -e | |
USAGE="Usage: $0 <start|stop|restart|upgrade|rotate|force-stop>" | |
# app settings | |
USER="admin" | |
APP_NAME="myapp" | |
APP_ROOT="/home/$USER/apps/$APP_NAME/current" | |
ENV="production" | |
# environment settings | |
PATH="/home/$USER/.rbenv/shims:/home/$USER/.rbenv/bin:$PATH" | |
CMD="cd $APP_ROOT; bundle exec unicorn -c config/puma.rb -E $ENV -D" | |
PID="$APP_ROOT/tmp/pids/puma.pid" | |
OLD_PID="$PID.oldbin" | |
# make sure the app exists | |
cd $APP_ROOT || exit 1 | |
sig () { | |
test -s "$PID" && kill -$1 `cat $PID` | |
} | |
oldsig () { | |
test -s $OLD_PID && kill -$1 `cat $OLD_PID` | |
} | |
case $1 in | |
start) | |
sig 0 && echo >&2 "Already running" && exit 0 | |
echo "Starting $APP_NAME" | |
su - $USER -c "$CMD" | |
;; | |
stop) | |
echo "Stopping $APP_NAME" | |
sig QUIT && exit 0 | |
echo >&2 "Not running" | |
;; | |
force-stop) | |
echo "Force stopping $APP_NAME" | |
sig TERM && exit 0 | |
echo >&2 "Not running" | |
;; | |
restart|reload|upgrade) | |
sig USR2 && echo "reloaded $APP_NAME" && exit 0 | |
echo >&2 "Couldn't reload, starting '$CMD' instead" | |
$CMD | |
;; | |
rotate) | |
sig USR1 && echo rotated logs OK && exit 0 | |
echo >&2 "Couldn't rotate logs" && exit 1 | |
;; | |
*) | |
echo >&2 $USAGE | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm really suspicious of the line in this script
I'm pretty sure it should be
I used a similar script, and everything seemed fine, but rails had no idea it was production because the environment wasn't set correctly.