payrepmc_app/config/unicorn_init_d
2018-08-03 01:08:08 +02:00

64 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
set -u
set -e
# Change these to match your app:
APP_NAME=payrepmc_app
APP_RUBY=ruby-2.3.0
APP_ROOT="/srv/www/web/payrepmc_app/current"
PID="/srv/www/web/payrepmc_app/shared/unicorn.pid"
ENV=production
GEM_HOME="/srv/www/web/.rvm/gems/ruby-$APP_RUBY"
UNICORN_OPTS="-D -E $ENV -c $APP_ROOT/config/unicorn.rb"
SET_PATH="cd $APP_ROOT; rvm $APP_RUBY"
CMD="$SET_PATH; bundle exec unicorn $UNICORN_OPTS"
old_pid="$PID.oldbin"
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-help} in
start)
sig 0 && echo >&2 "Already running" && exit 0
su - web -c "$CMD"
;;
stop)
sig QUIT && exit 0
echo >&2 "Not running"
;;
force-stop)
sig TERM && exit 0
echo >&2 "Not running"
;;
restart|reload)
sig HUP && echo reloaded OK && exit 0
echo >&2 "Couldn't reload, starting '$CMD' instead"
su - web -c "$CMD"
;;
upgrade)
sig USR2 && exit 0
echo >&2 "Couldn't upgrade, starting '$CMD' instead"
su - web -c "$CMD"
;;
rotate)
sig USR1 && echo rotated logs OK && exit 0
echo >&2 "Couldn't rotate logs" && exit 1
;;
*)
echo >&2 "Usage: $0 "
exit 1
;;
esac