Subversion Repositories ALCASAR

Rev

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

Rev 2583 Rev 2601
Line 1... Line 1...
1
#!/bin/sh
1
#!/bin/bash
2
# $Id: alcasar-daemon.sh 2583 2018-07-27 10:01:29Z rexy $
2
# $Id: alcasar-daemon.sh 2601 2018-08-19 23:58:27Z tom.houdayer $
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 12... Line 12...
12
SSH=${SSH:=off}
12
SSH=${SSH:=off}
13
LDAP=`grep ^LDAP= $conf_file|cut -d"=" -f2`				# ldap active (on/off)
13
LDAP=`grep ^LDAP= $conf_file|cut -d"=" -f2`				# ldap active (on/off)
14
LDAP=${LDAP:=off}
14
LDAP=${LDAP:=off}
15
INTIF=`grep ^INTIF= $conf_file|cut -d"=" -f2`				# INTIF name
15
INTIF=`grep ^INTIF= $conf_file|cut -d"=" -f2`				# INTIF name
16
EXTIF=`grep ^EXTIF= $conf_file|cut -d"=" -f2`				# EXTIF name
16
EXTIF=`grep ^EXTIF= $conf_file|cut -d"=" -f2`				# EXTIF name
17
SERVICES="mysqld lighttpd php-fpm ntpd havp dnsmasq dnsmasq-blacklist dnsmasq-whitelist dnsmasq-blackhole radiusd tinyproxy nfsen e2guardian freshclam ulogd-ssh ulogd-traceability ulogd-ext-access chilli fail2ban sshd vnstat"
17
SERVICES="mysqld lighttpd php-fpm ntpd havp dnsmasq dnsmasq-blacklist dnsmasq-whitelist dnsmasq-blackhole radiusd tinyproxy nfsen e2guardian freshclam ulogd-ssh ulogd-traceability ulogd-ext-access chilli fail2ban sshd vnstat gammu-smsd"
18
nb_available_srv=`echo $SERVICES|wc -w`
18
nb_available_srv=`echo $SERVICES|wc -w`
19
 
19
 
20
function ServiceTest () {
20
function ServiceTest () {
21
	CMD=`/usr/bin/systemctl is-active $s`
21
	service=$1
22
	if [ $CMD != "active" ]
22
	if [ $(/usr/bin/systemctl is-active $service) != "active" ]; then
23
	then
-
 
24
		logger -t alcasar-daemon -i "$s is inactive. Activation attempt"
23
		logger -t alcasar-daemon -i "$service is inactive. Activation attempt"
25
		echo "the $s service is disabled! trying to start it..."
24
		echo "the $service service is disabled! trying to start it..."
26
		/usr/bin/systemctl start $s.service
25
		/usr/bin/systemctl start $service.service
27
	else
26
	else
28
		nb_srv=$((nb_srv+1))
27
		nb_srv=$((nb_srv+1))
29
	fi
28
	fi
30
}
29
}
31
 
30
 
Line 37... Line 36...
37
		/usr/sbin/ifup $NIC
36
		/usr/sbin/ifup $NIC
38
	fi
37
	fi
39
done
38
done
40
 
39
 
41
nb_srv=0
40
nb_srv=0
42
for s in $SERVICES
41
for service in $SERVICES; do
43
do
-
 
44
	if [ $s != "sshd" ]
42
	if [ $service == 'sshd' ]; then
45
	then
-
 
46
		ServiceTest
-
 
47
	else
-
 
48
		{
-
 
49
		if [ $SSH == "ON" ] || [ $SSH == "on" ] || [ $SSH == "On" ]
43
		if [ $SSH != "ON" ] && [ $SSH != "on" ] && [ $SSH != "On" ]; then
50
		then
-
 
51
			ServiceTest
-
 
52
		else
-
 
53
			nb_available_srv=$((nb_available_srv-1))
44
			nb_available_srv=$((nb_available_srv-1))
-
 
45
			continue
-
 
46
		fi
-
 
47
	elif [ $service == 'gammu-smsd' ]; then
-
 
48
		if [ $(grep '^SMS=' $conf_file | cut -d'=' -f2-) != 'on' ]; then
-
 
49
			nb_available_srv=$((nb_available_srv-1))
-
 
50
			continue
54
		fi
51
		fi
55
		}
-
 
56
	fi
52
	fi
-
 
53
 
-
 
54
	ServiceTest $service
57
done
55
done
58
 
56
 
59
if [ $nb_available_srv -ne $nb_srv ]
57
if [ $nb_available_srv -ne $nb_srv ]
60
then
58
then
61
	echo "Restart this script to know if all is ok"
59
	echo "Restart this script to know if all is ok"