#!/bin/sh GROONGA_HTTPD=groonga-httpd PIDFILE=/var/run/groonga/${GROONGA_HTTPD}.pid OLD_PIDFILE=$PIDFILE.oldbin TIMEOUT=3 # Source function library. if [ -f /lib/lsb/init-functions ]; then . /lib/lsb/init-functions elif [ -f /etc/init.d/functions ]; then . /etc/init.d/functions fi wait_until_file_is_created () { timeout $TIMEOUT tail -F $1 --quiet 2> /dev/null | read 2> /dev/null } wait_until_process_is_finished () { timeout $TIMEOUT tail -F /dev/null --pid=$1 } if [ "$1" = "try-restart" ]; then if [ ! -f "$PIDFILE" ]; then exit 0 fi fi killproc -p $PIDFILE ${GROONGA_HTTPD} -USR2 wait_until_file_is_created $OLD_PIDFILE if [ ! -f "$OLD_PIDFILE" ]; then echo "Failed to start new groonga-httpd master." exit 1 fi OLD_PID=`cat $OLD_PIDFILE` # Switch worker process. kill -WINCH `cat $OLD_PIDFILE` wait_until_file_is_created $PIDFILE if [ ! -f "$PIDFILE" ]; then echo "Failed to switch worker process." exit 2 fi PID=`cat $PIDFILE` OLD_WORKER_PROCESS=`pgrep -P $OLD_PID | grep -v $PID` for pid in $OLD_WORKER_PROCESS; do wait_until_process_is_finished $pid done OLD_WORKER_PROCESS=`pgrep -P $OLD_PID | grep -v $PID` if [ -n "$OLD_WORKER_PROCESS" ]; then echo "Failed to stop old groonga-httpd worker process." killproc -p $PIDFILE ${GROONGA_HTTPD} -QUIT echo "Rollback to old groonga-httpd master." exit 2 fi # Stop old master process. killproc -p $OLD_PIDFILE ${GROONGA_HTTPD} -QUIT exit $?