#!/bin/bash # Stop a service and wait until it's really down SERVICE=$1 TIMEOUT=$2 if ! [ -e "$SERVICE/run" ]; then exit 0 fi if [ "$TIMEOUT" == "" ]; then TIMEOUT=90 fi svc -d $SERVICE sleep .1 while ! svstat $SERVICE | grep ': down' >/dev/null; do svc -d $SERVICE if [ "$TIMEOUT" == "0" ]; then exit 1 fi ((TIMEOUT--)) #with 30 seconds left, we send an interupt. #This is a forcefull shutdown without waiting for clients for most services if [ "$TIMEOUT" == 30 ]; then echo -n "sending interrupt " svc -i $SERVICE fi #with 10 seconds lefts, we just kill it if [ "$TIMEOUT" == 10 ]; then echo -n "KILLING " svc -k $SERVICE fi sleep 1 echo -n "." done exit 0