Need to start application service only when other services are up and running
I am new to Linux but need a help with script that will restart the naming service when it's down only if other app services are up and running and do nothing if other service are down. That's in case when there is a app maintenance or Linux servers patching going on. here is what I came up so far:
#!/bin/bash
###edit the following
service=orbadmin ns
email=test@company.com
###stop editing
host=`host -f`
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
echo "$service is running"
else
/etc/init.d/$service start
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
subject="$service at $host has been started"
echo "$service at $host wasn't running and has been started" | mail -s "$subject" $email
else
subject="$service at $host is not running"
echo "$service at $host is stopped and cannot be started!!!" | mail -s "$subject" $email
fi
fi
|