This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
fidohub/start_daemon

24 lines
397 B
Bash
Executable File

#!/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"