#! /usr/bin/env bash set -eu pidfile=/var/run/asterisk/asterisk.pid command=/usr/sbin/fwconsole function kill_app(){ $command stop exit $? } trap "kill_app" SIGINT SIGTERM $command chown $command start -q sleep 2 while [ -f $pidfile ] && kill -0 $(cat $pidfile) ; do sleep 5 done exit 1000