discourse/config/unicorn_launcher
Guo Xiang Tan 09d0216e84 Avoid hardcoded value in unicorn_launcher.
On slower instances, spinning up a new master process
can take more than 10 secs.
2018-10-04 15:44:13 +08:00

53 lines
1022 B
Bash
Executable File

#!/bin/bash
# This is a helper script you can use to supervise unicorn, it allows you to perform a live restart
# by sending it a USR2 signal
LOCAL_WEB="http://127.0.0.1:3000/"
function on_exit()
{
kill $UNICORN_PID
echo "exiting"
}
function on_reload()
{
echo "Reloading unicorn"
kill -s USR2 $UNICORN_PID
while [ -z "$NEW_UNICORN_PID" ]; do
echo "waiting for new unicorn master pid"
NEW_UNICORN_PID=`ps -f --ppid $UNICORN_PID | grep 'unicorn master' | grep -v worker | awk '{ print $2 }'`
sleep 1
done
curl $LOCAL_WEB &> /dev/null
kill -s QUIT $UNICORN_PID
echo "Old pid is: $UNICORN_PID New pid is: $NEW_UNICORN_PID"
UNICORN_PID=$NEW_UNICORN_PID
}
function on_reopenlogs()
{
echo "Reopening logs"
kill -s USR1 $UNICORN_PID
}
export UNICORN_SUPERVISOR_PID=$$
trap on_exit EXIT
trap on_reload USR2 HUP
trap on_reopenlogs USR1
unicorn $@ &
UNICORN_PID=$!
echo "supervisor pid: $UNICORN_SUPERVISOR_PID unicorn pid: $UNICORN_PID"
while kill -0 $UNICORN_PID
do
sleep 1
done