Skip to content

Instantly share code, notes, and snippets.

@emanoelopes
Created October 18, 2016 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emanoelopes/b193a26c6d4a64f4c155c95487dff9d9 to your computer and use it in GitHub Desktop.
Save emanoelopes/b193a26c6d4a64f4c155c95487dff9d9 to your computer and use it in GitHub Desktop.
unicorn initialization script
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the unicorn app server
# Description: starts unicorn using start-stop-daemon
### END INIT INFO
set -e
USAGE="Usage: $0 <start|stop|restart|upgrade|rotate|force-stop>"
# app settings
USER="emanoel"
APP_NAME="votaprato"
APP_ROOT="/home/$USER/$APP_NAME"
ENV="production"
# environment settings
PATH="/home/$USER/.rbenv/shims:/home/$USER/.rbenv/bin:$PATH"
CMD="cd $APP_ROOT && bundle exec unicorn -c config/unicorn.rb -E $ENV -D"
PID="$APP_ROOT/shared/pids/unicorn.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
@emanoelopes
Copy link
Author

Unicorn Service result:

● unicorn_votaprato.service - LSB: starts the unicorn app server
Loaded: loaded (/etc/init.d/unicorn_votaprato; bad; vendor preset: enabled)
Active: failed (Result: exit-code) since Ter 2016-10-18 15:40:25 BRT; 33min ago
Docs: man:systemd-sysv-generator(8)
Process: 32412 ExecStart=/etc/init.d/unicorn_votaprato start (code=exited, status=1/FAILURE)

Out 18 15:40:25 Digitron unicorn_votaprato[32412]: /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundl
Out 18 15:40:25 Digitron unicorn_votaprato[32412]: /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundl
Out 18 15:40:25 Digitron unicorn_votaprato[32412]: /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundl
Out 18 15:40:25 Digitron unicorn_votaprato[32412]: /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundl
Out 18 15:40:25 Digitron unicorn_votaprato[32412]: /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_requ
Out 18 15:40:25 Digitron unicorn_votaprato[32412]: /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_requ
Out 18 15:40:25 Digitron systemd[1]: unicorn_votaprato.service: Control process exited, code=exited st
Out 18 15:40:25 Digitron systemd[1]: Failed to start LSB: starts the unicorn app server.
Out 18 15:40:25 Digitron systemd[1]: unicorn_votaprato.service: Unit entered failed state.
Out 18 15:40:25 Digitron systemd[1]: unicorn_votaprato.service: Failed with result 'exit-code'.

@timokleemann
Copy link

Just wondering if you've found a solution to this yet? I just ran into the exact same error here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment