Subversion Repositories ALCASAR

Rev

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

Rev 2878 Rev 2967
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
# $Id: alcasar-daemon.sh 2878 2020-11-01 21:48:35Z rexy $
2
# $Id: alcasar-daemon.sh 2967 2021-07-08 09:47:39Z 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
# With the option "-after-update" checks if services or system need to be restarted after a RPM update
8
# See /etc/cron.d/alcasar-daemon-watchdog for config the time
9
# See /etc/cron.d/alcasar-daemon-watchdog for config the time
9
 
10
 
10
conf_file="/usr/local/etc/alcasar.conf"
11
conf_file="/usr/local/etc/alcasar.conf"
11
SSH=`grep ^SSH= $conf_file|cut -d"=" -f2`				# sshd active (on/off)
12
SSH=`grep ^SSH= $conf_file|cut -d"=" -f2`				# sshd active (on/off)
12
SSH=${SSH:=off}
13
SSH=${SSH:=off}
Line 34... Line 35...
34
	else
35
	else
35
		nb_srv=$((nb_srv+1))
36
		nb_srv=$((nb_srv+1))
36
	fi
37
	fi
37
}
38
}
38
 
39
 
39
for NIC in $EXTIF $INTIF
-
 
40
do
-
 
41
	if [ `/usr/sbin/ip a show $NIC|grep DOWN|wc -l` -eq "1" ]
40
usage="Usage: alcasar-daemon.sh {-after-update}"
42
	then
41
case $1 in
43
		echo "The network interface card '$NIC' is down! Try to enable it"
42
	-\? | -h* | --h*)
44
		/usr/sbin/ifup $NIC
43
		echo "$usage"
45
	fi
44
		exit 0
46
done
45
		;;
47
 
-
 
48
nb_srv=0
46
	-after-update)
-
 
47
		# TODO : check precisely which processes should be restarted (reboot the system or restart alcasar processes)
-
 
48
		# extract processes name : for i in `dnf needs-restarting|cut -d " " -f3|sort -u|tr -d ":"|rev|cut -d"/" -f1|rev`;do;echo $i;done
-
 
49
		# system_processes=`dnf needs-restarting|egrep 'dbus|python|systemd|agetty'|wc -l` # processes to be restarted after glibc update 
49
for service in $SERVICES; do
50
		nb_processes=`dnf needs-restarting|wc -l`
50
	if [ $service == 'sshd' ]; then
51
		if [ $nb_processes -ne 0 ]; then
51
		if [ $SSH != "ON" ] && [ $SSH != "on" ] && [ $SSH != "On" ]; then
-
 
52
			nb_available_srv=$((nb_available_srv-1))
-
 
53
			continue
52
			reboot
54
		fi
53
		fi
-
 
54
		;;
-
 
55
	*)
-
 
56
		for NIC in $EXTIF $INTIF
-
 
57
		do
-
 
58
			if [ `/usr/sbin/ip a show $NIC|grep DOWN|wc -l` -eq "1" ]; then
-
 
59
				echo "The network interface card '$NIC' is down! Try to enable it"
-
 
60
				/usr/sbin/ifup $NIC
-
 
61
			fi
-
 
62
		done
-
 
63
		
-
 
64
		nb_srv=0
-
 
65
		for service in $SERVICES; do
-
 
66
			if [ $service == 'sshd' ]; then
-
 
67
				if [ $SSH != "ON" ] && [ $SSH != "on" ] && [ $SSH != "On" ]; then
-
 
68
					nb_available_srv=$((nb_available_srv-1))
-
 
69
					continue
-
 
70
				fi
55
	elif [ $service == 'gammu-smsd' ]; then
71
			elif [ $service == 'gammu-smsd' ]; then
56
		if [ $SMS != "ON" ] && [ $SMS != "on" ] && [ $SMS != "On" ]; then
72
				if [ $SMS != "ON" ] && [ $SMS != "on" ] && [ $SMS != "On" ]; then
57
			nb_available_srv=$((nb_available_srv-1))
73
					nb_available_srv=$((nb_available_srv-1))
58
			continue
74
					continue
-
 
75
				fi
-
 
76
			fi
-
 
77
			ServiceTest $service
-
 
78
		done
-
 
79
		
-
 
80
		if [ $nb_available_srv -ne $nb_srv ]; then
-
 
81
			echo "Restart this script to know if all is ok"
-
 
82
		else
-
 
83
			echo "$nb_srv services needed by ALCASAR are started."
59
		fi
84
		fi
60
	fi
85
		
61
	ServiceTest $service
-
 
62
done
-
 
63
 
-
 
64
if [ $nb_available_srv -ne $nb_srv ]
-
 
65
then
-
 
66
	echo "Restart this script to know if all is ok"
-
 
67
else
-
 
68
	echo "$nb_srv services needed by ALCASAR are started."
-
 
69
fi
-
 
70
 
-
 
71
if [ `cat /proc/modules|grep -c ^ipt_NETFLOW` == 0 ]
86
		if [ `cat /proc/modules|grep -c ^ipt_NETFLOW` == 0 ]; then
72
then
-
 
73
	logger -t alcasar-daemon -i "ipt_netflow is inactive."
87
			logger -t alcasar-daemon -i "ipt_netflow is inactive."
74
	echo "The Log system is disabled! try to know why (modprobe ipt_NETFLOW)"
88
			echo "The Log system is disabled! try to know why (modprobe ipt_NETFLOW)"
75
else
89
		else
76
	echo "The Log system is active"
90
			echo "The Log system is active"
77
fi
91
		fi
78
if [ ! -e /etc/raddb/mods-enabled/ldap ]
92
		if [ ! -e /etc/raddb/mods-enabled/ldap ]; then
79
then
-
 
80
	if [ $LDAP == "ON" ] || [ $LDAP == "on" ] || [ $LDAP == "On" ]
93
			if [ $LDAP == "ON" ] || [ $LDAP == "on" ] || [ $LDAP == "On" ]; then
81
	then
-
 
82
		echo "Enabling LDAP..."
94
				echo "Enabling LDAP..."
83
		/usr/local/bin/alcasar-ldap.sh -on
95
				/usr/local/bin/alcasar-ldap.sh -on
84
	fi
96
			fi
85
fi
97
		fi
86
 
98
	;;
-
 
99
esac