#!/bin/sh PIDDIR=/var/run SLEEP=5 DAEMON=${1} shift PROG=$(basename $DAEMON) echo "* Starting daemon [${PROG}]" ${DAEMON} pidof ${PROG} > ${PIDDIR}/$PROG DAEMON_RUN=true while ${DAEMON_RUN}; do for pid in $(cat ${PIDDIR}/$PROG); do #echo "- Checking PID [${pid}]" ( ps -p ${pid} > /dev/null && sleep ${SLEEP} ) || DAEMON_RUN=false done done echo "* Daemon [${PROG}] no longer running"