-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcheckService.sh
More file actions
executable file
·56 lines (48 loc) · 1.45 KB
/
checkService.sh
File metadata and controls
executable file
·56 lines (48 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
export PATH=/bin:/usr/bin:/sbin:/usr/sbin
#CONFIGURE FOR YOUR NEEDS
FULLPATH=/var/bin/ServiceCheck
FILEPATH=$FULLPATH/services/*.serv
#DO NOT MODIFY BELOW
function CheckIfRunning {
#echo Parameter1: $1
#echo Parameter2: $2
currenttime=`date +%Y-%m-%d/%H:%M:%S`
if ps ax | grep -v grep | grep $1 > /dev/null
then
echo "($currenttime) NOTICE: $1 service is running"
if [[ -s $FULLPATH/services/$1.check ]] ; then
#Corresponding check file has data, try to run it
echo "Additional checks mandatory for $1"
$FULLPATH/services/$1.check
else
echo "($currenttime) NOTICE: $1 passed checks and is running"
fi ;
else
logger -s "($currenttime) ERROR: $1 is not running"
#try to run the serv file to do the necessary corrections
if [[ -s $2 ]] ; then
#Corresponding serv file has data, try to run it
$FULLPATH/services/$1.serv
else
#Corresponding serv file is empty, try to restart the service
systemctl restart $1
fi ;
fi
}
if !(systemctl -q is-active multi-user.target)
then
exit 1
fi
#continue only if multi-user target has been reached to prevent restarting services too early/late during boot/shutdown
cd $FULLPATH
for filename in $FILEPATH
do
#echo "Parsing $filename"
ext=${filename##*.}
temp=`basename $filename $ext`
#get rid of leading .
SERVICENAME=${temp%.}
#echo Checking Service: $SERVICENAME
CheckIfRunning $SERVICENAME $filename
done;