Skip to content

Instantly share code, notes, and snippets.

@didip
Created December 13, 2012 16:57
Show Gist options
  • Select an option

  • Save didip/4277907 to your computer and use it in GitHub Desktop.

Select an option

Save didip/4277907 to your computer and use it in GitHub Desktop.
Rolling restart supervisord watched processes. Since every restart it waits for "$status" == "RUNNING", it's safer that simply running /etc/init.d/supervisor restart
#!/bin/bash
#
# Usage: ./supervisor-rolling-restart [supervised-process-name]
#
PROGRAM=$1
# Time in seconds.
TIME_BETWEEN_RUNNING_CHECKS=0.5
TIME_BETWEEN_RESTARTS=1
for f in `supervisorctl status | grep "$PROGRAM" | awk '{print $1}'`; do
supervisorctl restart $f
while [ 1 ]; do
sleep $TIME_BETWEEN_RUNNING_CHECKS
status=`supervisorctl status $f | awk '{print $2}'`
if [ "$status" == "RUNNING" ] ; then
echo $f restarted
break
elif [ "$status" == "FATAL" ] ; then
echo "Error during restart of $f ($status). Stopping rolling update."
exit 1
else
echo "Now: $status"
fi
done
sleep $TIME_BETWEEN_RESTARTS
done
@daiguoliangfirst
Copy link
Copy Markdown

hope that supervisor support rolling restart one day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment