Subversion Repositories ALCASAR

Rev

Rev 1574 | Rev 1791 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 1574 Rev 1596
Line 1... Line 1...
1
#!/bin/sh
1
#!/bin/sh
2
# $Id: alcasar-daemon.sh 1574 2015-03-01 23:17:07Z richard $
2
# $Id: alcasar-daemon.sh 1596 2015-03-16 23:07:55Z richard $
3
 
3
 
4
# alcasar-daemon.sh
4
# alcasar-daemon.sh
5
# by Franck BOUIJOUX & Rexy
5
# by Franck BOUIJOUX & Rexy
6
# This script is distributed under the Gnu General Public License (GPL)
6
# This script is distributed under the Gnu General Public License (GPL)
7
# Watchdog of Services
7
# Watchdog of Services
Line 9... Line 9...
9
 
9
 
10
conf_file="/usr/local/etc/alcasar.conf"
10
conf_file="/usr/local/etc/alcasar.conf"
11
SSH=`grep SSH= $conf_file|cut -d"=" -f2`				# sshd active (on/off)
11
SSH=`grep SSH= $conf_file|cut -d"=" -f2`				# sshd active (on/off)
12
SSH=${SSH:=off}
12
SSH=${SSH:=off}
13
SERVICES="mysqld httpd ntpd iptables dnsmasq dnsmasq-blacklist dnsmasq-whitelist dnsmasq-blackhole radiusd nfsen dansguardian freshclam ulogd-ssh ulogd-traceability ulogd-ext-access chilli fail2ban sshd"
13
SERVICES="mysqld httpd ntpd iptables dnsmasq dnsmasq-blacklist dnsmasq-whitelist dnsmasq-blackhole radiusd nfsen dansguardian freshclam ulogd-ssh ulogd-traceability ulogd-ext-access chilli fail2ban sshd"
-
 
14
nb_available_srv=`echo $SERVICES|wc -w`
14
 
15
 
15
function ServiceTest () {
16
function ServiceTest () {
16
	 CMD=`/usr/bin/systemctl is-active $s`
17
	CMD=`/usr/bin/systemctl is-active $s`
17
	 if [ $CMD != "active" ]
18
	if [ $CMD != "active" ]
18
	 then
19
	then
19
		logger -i "!! $s is inactive. Activation attempt"
20
		logger -i "!! $s is inactive. Activation attempt"
-
 
21
		echo "the $s service is disabled! trying to start it..."
20
		/usr/bin/systemctl start $s.service
22
	       	/usr/bin/systemctl start $s.service
-
 
23
	else
-
 
24
		nb_srv=$((nb_srv+1))
21
	 fi
25
	fi
22
}
26
}
23
 
27
 
24
 
28
nb_srv=0
25
for s in $SERVICES
29
for s in $SERVICES
26
do
30
do
27
	if [ $s != "sshd" ] 
31
	if [ $s != "sshd" ] 
28
	then
32
	then
29
	    ServiceTest
33
		ServiceTest
30
	else
34
	else
31
	{
35
		{
32
	    if [ $SSH == "ON" ] | [ $SSH == "on" ] | [ $SSH == "On" ]
36
		if [ $SSH == "ON" ] || [ $SSH == "on" ] || [ $SSH == "On" ]
33
	    then
37
	    	then
34
		  ServiceTest
38
			ServiceTest
-
 
39
		else
-
 
40
			nb_available_srv=$((nb_available_srv-1))		
35
	    fi
41
		fi
36
	}
42
		}
37
	fi
43
	fi
38
done
44
done
-
 
45
if [ $nb_available_srv -ne $nb_srv ]
-
 
46
	then
-
 
47
	echo "restart this script to know if all is ok"
-
 
48
else
-
 
49
	echo "$nb_srv services are started. All is ok"
-
 
50
fi