-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsarls
26 lines (23 loc) · 1.15 KB
/
sarls
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
#!/bin/bash
# Script SARLS (Simple Auto Restart Linux Service) by Indoworx
# www.indoworx.com
# Get Data from input
read -p "Enter linux service name to monitor: " procname
read -p "Enter notification if the service is stopped (example: not running): " procnote
# Create cron auto restart file for auto restart the service
if [ ! -d "/etc/sarls" ]; then
mkdir /etc/sarls
fi
rm -f /etc/sarls/$procname
echo '#! /bin/sh' >> /etc/sarls/$procname
echo 'if /etc/init.d/'$procname' status | grep -q "'$procnote'";' >> /etc/sarls/$procname
echo 'then' >> /etc/sarls/$procname
echo 'echo "service '$procname' is not running, restarting.."' >> /etc/sarls/$procname
echo '/etc/init.d/'$procname' restart' >> /etc/sarls/$procname
echo 'else' >> /etc/sarls/$procname
echo 'echo "service '$procname' is running."' >> /etc/sarls/$procname
echo 'fi' >> /etc/sarls/$procname
# Create crontab for running auto restart file, run every 5 minutes
( crontab -l | { grep -v -F "sh /etc/sarls/$procname" ; echo "*/5 * * * * sh /etc/sarls/$procname > /dev/null 2>&1"; } ) | crontab -
echo "Cron Script Simple Auto Restart Linux Service Is Finish"
echo "Cron file placed in /etc/sarls/$procname"