Last active
July 28, 2017 14:47
-
-
Save josephbridgwaterrowe/26f64b39076cb72ad711 to your computer and use it in GitHub Desktop.
Promiscuous Subscriber init.d
This file contains hidden or 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
### BEGIN INIT INFO | |
# Provides: promiscuous subscribe | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Execute the promiscuous subscriber | |
# Description: Execute the promiscuous subscriber | |
### END INIT INFO | |
set -e | |
# Feel free to change any of the following variables for your app: | |
TIMEOUT=${TIMEOUT-60} | |
APP_ROOT=/var/www/current | |
PID=$APP_ROOT/tmp/pids/promiscuous_subscriber.pid | |
CMD="cd $APP_ROOT; RAILS_ENV=staging bundle exec promiscuous subscribe -D" | |
AS_USER=deploy | |
set -u | |
sig () { | |
test -s "$PID" && kill -$1 `cat $PID` | |
} | |
run () { | |
if [ "$(id -un)" = "$AS_USER" ]; then | |
eval $1 | |
else | |
su -c "$1" - $AS_USER | |
fi | |
} | |
case "$1" in | |
start) | |
sig 0 && echo >&2 "Already running" && exit 0 | |
run "$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" | |
run "$CMD" | |
;; | |
*) | |
echo >&2 "Usage: $0 <start|stop|restart|force-stop>" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was quick and dirty, I want to create another one based on a more appropriate script I use for Sidekiq.