Created
May 28, 2015 18:26
-
-
Save andrewsomething/5d21e17b9ddb4507ed22 to your computer and use it in GitHub Desktop.
unicorn init script
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: unicorn | |
# Required-Start: $local_fs $remote_fs | |
# Required-Stop: $local_fs $remote_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: unicorn initscript | |
# Description: unicorn | |
### END INIT INFO | |
set -e | |
NAME=unicorn | |
DESC="Unicorn web server" | |
. /lib/lsb/init-functions | |
if [ -f /etc/default/unicorn ]; then | |
. /etc/default/unicorn | |
fi | |
PID=${PID-/run/unicorn.pid} | |
run_by_init() { | |
([ "${previous-}" ] && [ "${runlevel-}" ]) || [ "${runlevel-}" = S ] | |
} | |
exit_with_message() { | |
if ! run_by_init; then | |
log_action_msg "$1 Not starting." | |
fi | |
exit 0 | |
} | |
check_config() { | |
if [ $CONFIGURED != "yes" ]; then | |
exit_with_message "Unicorn is not configured (see /etc/default/unicorn)." | |
fi | |
} | |
check_app_root() { | |
if ! [ -d $APP_ROOT ]; then | |
exit_with_message "Application directory $APP_ROOT is not exist." | |
fi | |
} | |
set -u | |
case "$1" in | |
start) | |
check_config | |
check_app_root | |
log_daemon_msg "Starting $DESC" $NAME || true | |
if start-stop-daemon --start --quiet --oknodo --pidfile $PID --exec $DAEMON -- $UNICORN_OPTS; then | |
log_end_msg 0 || true | |
else | |
log_end_msg 1 || true | |
fi | |
;; | |
stop) | |
log_daemon_msg "Stopping $DESC" $NAME || true | |
if start-stop-daemon --stop --signal QUIT --quiet --oknodo --pidfile $PID; then | |
log_end_msg 0 || true | |
else | |
log_end_msg 1 || true | |
fi | |
;; | |
force-stop) | |
log_daemon_msg "Forcing stop of $DESC" $NAME || true | |
if start-stop-daemon --stop --quiet --oknodo --pidfile $PID; then | |
log_end_msg 0 || true | |
else | |
log_end_msg 1 || true | |
fi | |
;; | |
restart|force-reload) | |
log_daemon_msg "Restarting $DESC" $NAME || true | |
start-stop-daemon --stop --quiet --oknodo --pidfile $PID | |
sleep 1 | |
if start-stop-daemon --start --quiet --oknodo --pidfile $PID --exec $DAEMON -- $UNICORN_OPTS; then | |
log_end_msg 0 || true | |
else | |
log_end_msg 1 || true | |
fi | |
;; | |
reload) | |
log_daemon_msg "Reloading $DESC" $NAME || true | |
if start-stop-daemon --stop --signal HUP --quiet --oknodo --pidfile $PID; then | |
log_end_msg 0 || true | |
else | |
log_end_msg 1 || true | |
fi | |
;; | |
reopen-logs) | |
log_daemon_msg "Relopening log files of $DESC" $NAME || true | |
if start-stop-daemon --stop --signal USR1 --quiet --oknodo --pidfile $PID; then | |
log_end_msg 0 || true | |
else | |
log_end_msg 1 || true | |
fi | |
;; | |
status) | |
status_of_proc -p $PID $DAEMON $NAME && exit 0 || exit $? | |
;; | |
*) | |
log_action_msg "Usage: $0 <start|stop|restart|force-reload|reload|force-stop|reopen-logs|status>" || true | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment