Thomas R. Stegelmann

Technology, Business and Innovation

Bash to check if service is running and restart

first-aid

This is a quick and dirty bash script to relaunch a process under Linux. If the query term php is not found within the list of processes running, the script starts the process. Please spend a couple of minutes to add a logging method to this script to track failures.

 

#!/bin/sh
QUERY='php'

if ps ax | grep -v grep | grep $QUERY > /dev/null
then
    echo "$QUERY service running, everything is fine"
else
    echo "$QUERY is not running"
    php /root/init.php
fi

 

Comments [0]