Initial commit for restart_service

This commit is contained in:
Yavuz Aydın 2021-10-06 15:59:56 +02:00
parent 5310804998
commit 0ed7a16eaf
1 changed files with 32 additions and 0 deletions

32
restart_service Normal file
View File

@ -0,0 +1,32 @@
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
while getopts "s:t:a:S:" opt; do
case $opt in
s)
servicestate=$OPTARG
;;
t)
servicestatetype=$OPTARG
;;
a)
serviceattempt=$OPTARG
;;
S)
service=$OPTARG
;;
esac
done
if ( [ -z $servicestate ] || [ -z $servicestatetype ] || [ -z $serviceattempt ] || [ -z $service ] ); then
echo "USAGE: $0 -s servicestate -z servicestatetype -a serviceattempt -S service"
exit 3;
else
# Only restart on the third attempt of a critical event
if ( [ $servicestate == "CRITICAL" ] && [ $servicestatetype == "SOFT" ] && [ $serviceattempt -eq 3 ] ); then
if [ pidof systemd >/dev/null ]; then
sudo systemctl restart $service
else
sudo service $service restart
fi
fi
fi