Monitoring service under Ubuntu

Monitor the service under Ubuntu. This solution is based on the port number. If the port number is inactive, the service is considered to be stopped, and then the service is restarted.

#!/bin/bash
cur_dateTime=`date +%Y-%m-%d,%H:%m:%S`
a=`lsof -i:8082 | wc -l`

if [ "$a" -gt "0" ];then
    /bin/bash /opt/cook-prod/backend/restart.sh
    echo "$cur_dateTime cook running" >> /opt/job/log/cook_restart.job
else
    echo "$cur_dateTime restart job" >> /opt/job/log/cook_restart.job
fi

 

Guess you like

Origin www.cnblogs.com/roostinghawk/p/12710624.html