mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-24 06:22:31 -05:00
df65371d72
sleep 0.1 and file test were expensive compared to a signal every second
39 lines
798 B
Bash
Executable file
39 lines
798 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
|
|
sleep 10
|
|
curl $LOCAL_WEB &> /dev/null
|
|
NEW_UNICORN_PID=`ps -f --ppid $UNICORN_PID | grep unicorn | grep -v worker | awk '{ print $2 }'`
|
|
kill $UNICORN_PID
|
|
echo "Old pid is: $UNICORN_PID New pid is: $NEW_UNICORN_PID"
|
|
UNICORN_PID=$NEW_UNICORN_PID
|
|
}
|
|
|
|
export UNICORN_SUPERVISOR_PID=$$
|
|
|
|
trap on_exit EXIT
|
|
trap on_reload USR2
|
|
|
|
unicorn $@ &
|
|
UNICORN_PID=$!
|
|
|
|
echo "supervisor pid: $UNICORN_SUPERVISOR_PID unicorn pid: $UNICORN_PID"
|
|
|
|
while kill -0 $UNICORN_PID
|
|
do
|
|
sleep 1
|
|
done
|