gitlab-org--gitlab-foss/bin/mail_room
Jacob Vosmaer 1081a322f1 Properly daemonize the mail_room process
The old invocation only worked by accident because we have a '&'
somewhere in the init script for expediency. When ran from a terminal,
the mail_room daemon process ended up in the session of the terminal.
This commit adds a small wrapper that tries to do the textbook
daemonization steps (double fork, setsid etc.) while also taking
care that the pidfile is written before the 'start' process exits.
2015-08-27 16:35:00 +02:00

50 lines
753 B
Bash
Executable file

#!/bin/sh
cd $(dirname $0)/..
app_root=$(pwd)
mail_room_pidfile="$app_root/tmp/pids/mail_room.pid"
mail_room_logfile="$app_root/log/mail_room.log"
mail_room_config="$app_root/config/mail_room.yml"
get_mail_room_pid()
{
local pid=$(cat $mail_room_pidfile)
if [ -z "$pid" ] ; then
echo "Could not find a PID in $mail_room_pidfile"
exit 1
fi
mail_room_pid=$pid
}
start()
{
bin/daemon_with_pidfile $mail_room_pidfile bundle exec mail_room -q -c $mail_room_config >> $mail_room_logfile 2>&1
}
stop()
{
get_mail_room_pid
kill -TERM $mail_room_pid
}
restart()
{
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
;;
esac