Subversion Repositories ALCASAR

Rev

Rev 2864 | Rev 2878 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2864 Rev 2875
1
#!/bin/bash
1
#!/bin/bash
2
# $Id: alcasar-daemon.sh 2864 2020-10-18 09:06:17Z rexy $
2
# $Id: alcasar-daemon.sh 2875 2020-11-01 10:50:57Z rexy $
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
8
# See /etc/cron.d/alcasar-daemon-watchdog for config the time
8
# See /etc/cron.d/alcasar-daemon-watchdog for config the time
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
SMS=`grep ^SMS= $conf_file|cut -d"=" -f2`				# SMS active (on/off)
13
SMS=`grep ^SMS= $conf_file|cut -d"=" -f2`				# SMS active (on/off)
14
SMS=${SMS:=off}
14
SMS=${SMS:=off}
15
LDAP=`grep ^LDAP= $conf_file|cut -d"=" -f2`				# ldap active (on/off)
15
LDAP=`grep ^LDAP= $conf_file|cut -d"=" -f2`				# ldap active (on/off)
16
LDAP=${LDAP:=off}
16
LDAP=${LDAP:=off}
17
INTIF=`grep ^INTIF= $conf_file|cut -d"=" -f2`				# INTIF name
17
INTIF=`grep ^INTIF= $conf_file|cut -d"=" -f2`				# INTIF name
18
EXTIF=`grep ^EXTIF= $conf_file|cut -d"=" -f2`				# EXTIF name
18
EXTIF=`grep ^EXTIF= $conf_file|cut -d"=" -f2`				# EXTIF name
19
SERVICES="mysqld lighttpd php-fpm ntpd unbound unbound-blacklist unbound-whitelist dnsmasq-whitelist unbound-blackhole radiusd nfcapd e2guardian clamav-daemon clamav-freshclam ulogd-ssh ulogd-traceability ulogd-ext-access chilli fail2ban sshd vnstat gammu-smsd"
19
SERVICES="mysqld lighttpd php-fpm ntpd unbound unbound-blacklist unbound-whitelist dnsmasq-whitelist unbound-blackhole radiusd nfcapd e2guardian clamav-daemon clamav-freshclam ulogd-ssh ulogd-traceability ulogd-ext-access chilli fail2ban sshd vnstat gammu-smsd"
20
nb_available_srv=`echo $SERVICES|wc -w`
20
nb_available_srv=`echo $SERVICES|wc -w`
21
 
21
 
22
function ServiceTest () {
22
function ServiceTest () {
23
	service=$1
23
	service=$1
24
	if [ $(/usr/bin/systemctl is-active $service) != "active" ]; then
24
	if [ $(/usr/bin/systemctl is-active $service) != "active" ]; then
25
		logger -t alcasar-daemon -i "$service is inactive. Activation attempt"
25
		logger -t alcasar-daemon -i "$service is inactive. Activation attempt"
26
		echo "the $service service is disabled! trying to start it..."
26
		echo "the $service service is disabled! trying to start it..."
-
 
27
		if [ $service == 'gammu-smsd' ]; then
-
 
28
			/usr/local/bin/alcasar-sms.sh --start
-
 
29
		else
27
		/usr/bin/systemctl start $service.service
30
			/usr/bin/systemctl start $service.service
-
 
31
		fi
28
	else
32
	else
29
		nb_srv=$((nb_srv+1))
33
		nb_srv=$((nb_srv+1))
30
	fi
34
	fi
31
}
35
}
32
 
36
 
33
for NIC in $EXTIF $INTIF
37
for NIC in $EXTIF $INTIF
34
do
38
do
35
	if [ `/usr/sbin/ip a show $NIC|grep DOWN|wc -l` -eq "1" ]
39
	if [ `/usr/sbin/ip a show $NIC|grep DOWN|wc -l` -eq "1" ]
36
	then
40
	then
37
		echo "The network interface card '$NIC' is down! Try to enable it"
41
		echo "The network interface card '$NIC' is down! Try to enable it"
38
		/usr/sbin/ifup $NIC
42
		/usr/sbin/ifup $NIC
39
	fi
43
	fi
40
done
44
done
41
 
45
 
42
nb_srv=0
46
nb_srv=0
43
for service in $SERVICES; do
47
for service in $SERVICES; do
44
	if [ $service == 'sshd' ]; then
48
	if [ $service == 'sshd' ]; then
45
		if [ $SSH != "ON" ] && [ $SSH != "on" ] && [ $SSH != "On" ]; then
49
		if [ $SSH != "ON" ] && [ $SSH != "on" ] && [ $SSH != "On" ]; then
46
			nb_available_srv=$((nb_available_srv-1))
50
			nb_available_srv=$((nb_available_srv-1))
47
			continue
51
			continue
48
		fi
52
		fi
49
	elif [ $service == 'gammu-smsd' ]; then
53
	elif [ $service == 'gammu-smsd' ]; then
50
		if [ $SMS != "ON" ] && [ $SMS != "on" ] && [ $SMS != "On" ]; then
54
		if [ $SMS != "ON" ] && [ $SMS != "on" ] && [ $SMS != "On" ]; then
51
			nb_available_srv=$((nb_available_srv-1))
55
			nb_available_srv=$((nb_available_srv-1))
52
			continue
56
			continue
53
		fi
57
		fi
54
	fi
58
	fi
55
	ServiceTest $service
59
	ServiceTest $service
56
done
60
done
57
 
61
 
58
if [ $nb_available_srv -ne $nb_srv ]
62
if [ $nb_available_srv -ne $nb_srv ]
59
then
63
then
60
	echo "Restart this script to know if all is ok"
64
	echo "Restart this script to know if all is ok"
61
else
65
else
62
	echo "$nb_srv services needed by ALCASAR are started."
66
	echo "$nb_srv services needed by ALCASAR are started."
63
fi
67
fi
64
 
68
 
65
if [ `cat /proc/modules|grep -c ^ipt_NETFLOW` == 0 ]
69
if [ `cat /proc/modules|grep -c ^ipt_NETFLOW` == 0 ]
66
then
70
then
67
	logger -t alcasar-daemon -i "ipt_netflow is inactive."
71
	logger -t alcasar-daemon -i "ipt_netflow is inactive."
68
	echo "The Log system is disabled! try to know why (modprobe ipt_NETFLOW)"
72
	echo "The Log system is disabled! try to know why (modprobe ipt_NETFLOW)"
69
else
73
else
70
	echo "The Log system is active"
74
	echo "The Log system is active"
71
fi
75
fi
72
if [ ! -e /etc/raddb/mods-enabled/ldap ]
76
if [ ! -e /etc/raddb/mods-enabled/ldap ]
73
then
77
then
74
	if [ $LDAP == "ON" ] || [ $LDAP == "on" ] || [ $LDAP == "On" ]
78
	if [ $LDAP == "ON" ] || [ $LDAP == "on" ] || [ $LDAP == "On" ]
75
	then
79
	then
76
	echo "Enable LDAP..."
80
		echo "Enabling LDAP..."
77
	/usr/local/bin/alcasar-ldap.sh -on
81
		/usr/local/bin/alcasar-ldap.sh -on
78
	fi
82
	fi
79
fi
83
fi
80
 
84
 
81
 
85