-
Notifications
You must be signed in to change notification settings - Fork 51
Init Scripts for Running mail_room
Tony Pitale edited this page Mar 21, 2015
·
2 revisions
By @matte
#!/bin/bash
#
# mail_room start up script to listen to imap for requests
# Source function library.
. /etc/rc.d/init.d/functions
prog=mail_room
start() {
# see if running
local pids=$(pgrep $prog)
if [ -n "$pids" ]; then
echo "$prog (pid $pids) is already running"
return 0
fi
echo -n $"Starting $prog: "
cd /var/www/r4/current/
# note RVM wrapper is required to load gems and mail_room script
# http://rvm.io/deployment/init-d
# nohup allows the script to run in a detached shell
nohup /usr/local/rvm/wrappers/mail_room/bundle exec mail_room -c /var/www/r4/current/config/mailbox.yml &> /var/www/r4/current/log/mail_room.log &
RETVAL=$?
PID=$!
echo $PID > /tmp/mail_room.pid
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
kill -15 $(cat /tmp/mail_room.pid) && rm -f /tmp/mail_room.pid
RETVAL=$?
return $RETVAL
}
reload() {
stop
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $prog
RETVAL=$?
;;
restart)
stop
start
;;
*)
echo $"Usage: $prog {start|stop|restart}"
RETVAL=2
esac
exit $RETVAL
# /etc/init/mail_room.conf
description "mail_room process"
# change to the user you want to run this ruby script as
setuid deploy
setgid deploy
# This starts upon bootup and stops on shutdown
# check runlevel of running system with `runlevel` command
start on runlevel [2345]
stop on runlevel [06]
# controls for respawning this process if it dies
respawn # yes, we want this to respawn
respawn limit 1 30 # only try 1x to respawn in 30 seconds
# change to the directory you want to run mail_room from
chdir /some/directory/
script
# give us a login shell to load rbenv/chruby, YMMV
exec /bin/bash -l <<EOT
export HOME="$(eval echo ~$(id -un))"
source /usr/local/share/chruby/chruby.sh
chruby 2.2.0 # change this to your ruby version!
# you may not need 'bundle exec' depending on your gem installation
exec bundle exec mail_room -c /path/to/config.yml
EOT
end script