1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #!/bin/bash
- #
- # Process watchdog timer daemon: monitor the processes to ensure the applications are running
- #
- CONF_FILE="/etc/proc-wdtd.conf"
- # check if the configure file exists
- if [[ -f ${CONF_FILE} ]]; then
- echo "proc-wdtd: load configure file '${CONF_FILE}'"
- else
- echo "proc-wdtd: ERROR: can not find file '${CONF_FILE}'"
- exit 1
- fi
- # load configuration
- CONF=$(cat ${CONF_FILE} 2>/dev/null | sed 's/#.*//' | \
- sed 's/^[[:blank:]]*//' | sed 's/[[:blank:]]*$//' | sed '/^$/d' | \
- sed 's/[[:blank:]]*=[[:blank:]]*/=/')
- # get application name list
- APPS=$(echo "${CONF}" | awk -F'=' '{print$1}')
- sleep 60
- while true; do
- for app in ${APPS}; do
- # check native program
- pid=$(pidof ${app})
- if [[ "${pid}" != "" ]]; then
- echo "proc-wdtd: '${app}' is running (${pid})"
- continue
- fi
- # check python script
- pid=$(ps aux | grep python | grep -v grep | grep ${app} | awk '{print$1}')
- if [[ "${pid}" != "" ]]; then
- echo "proc-wdtd: '${app}' python script is running (${pid})"
- continue
- fi
- # the program is not running, execute the command to lunch it
- echo "proc-wdtd: '${app}' is not running"
- cmd=$(echo "${CONF}" | grep "^${app}=" | head -n 1 | \
- cut -d "=" -s -f2- | sed 's/^"//' | sed 's/"$//')
- echo "proc-wdtd: execute command '${cmd}'"
- ${cmd} &>/dev/null &
- done
- sleep 60
- done
|