Subversion Repositories ALCASAR

Rev

Rev 3043 | Rev 3170 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
2601 tom.houday 1
#!/bin/bash
825 franck 2
# $Id: alcasar-daemon.sh 3099 2022-12-28 11:30:30Z rexy $
807 franck 3
 
824 franck 4
# alcasar-daemon.sh
1474 richard 5
# by Franck BOUIJOUX & Rexy
807 franck 6
# This script is distributed under the Gnu General Public License (GPL)
7
# Watchdog of Services
2967 rexy 8
# With the option "-after-update" checks if services or system need to be restarted after a RPM update
807 franck 9
# See /etc/cron.d/alcasar-daemon-watchdog for config the time
10
 
824 franck 11
conf_file="/usr/local/etc/alcasar.conf"
2620 rexy 12
SMS=`grep ^SMS= $conf_file|cut -d"=" -f2`				# SMS active (on/off)
13
SMS=${SMS:=off}
2572 rexy 14
LDAP=`grep ^LDAP= $conf_file|cut -d"=" -f2`				# ldap active (on/off)
2574 rexy 15
LDAP=${LDAP:=off}
2583 rexy 16
INTIF=`grep ^INTIF= $conf_file|cut -d"=" -f2`				# INTIF name
17
EXTIF=`grep ^EXTIF= $conf_file|cut -d"=" -f2`				# EXTIF name
3099 rexy 18
SERVICES="mysqld lighttpd php-fpm ntpd unbound unbound-blacklist unbound-whitelist unbound-blackhole radiusd nfcapd e2guardian clamav-daemon clamav-freshclam ulogd-ssh ulogd-traceability ulogd-ext-access chilli fail2ban sshd vnstat gammu-smsd"
1596 richard 19
nb_available_srv=`echo $SERVICES|wc -w`
807 franck 20
 
824 franck 21
function ServiceTest () {
2601 tom.houday 22
	service=$1
23
	if [ $(/usr/bin/systemctl is-active $service) != "active" ]; then
24
		logger -t alcasar-daemon -i "$service is inactive. Activation attempt"
25
		echo "the $service service is disabled! trying to start it..."
2875 rexy 26
		if [ $service == 'gammu-smsd' ]; then
27
			/usr/local/bin/alcasar-sms.sh --start
28
		fi
2878 rexy 29
		if [ $service == 'sshd' ]; then
30
			[ -s /etc/ssh/ssh_host_rsa_key ] || rm -f /etc/ssh/ssh_host_* # sometimes sshd doesn't initialise its keys
31
		fi	
32
		/usr/bin/systemctl start $service.service
1596 richard 33
	else
34
		nb_srv=$((nb_srv+1))
35
	fi
824 franck 36
}
807 franck 37
 
2967 rexy 38
usage="Usage: alcasar-daemon.sh {-after-update}"
39
case $1 in
40
	-\? | -h* | --h*)
41
		echo "$usage"
42
		exit 0
43
		;;
44
	-after-update)
45
		# TODO : check precisely which processes should be restarted (reboot the system or restart alcasar processes)
46
		# 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
47
		# system_processes=`dnf needs-restarting|egrep 'dbus|python|systemd|agetty'|wc -l` # processes to be restarted after glibc update 
48
		nb_processes=`dnf needs-restarting|wc -l`
49
		if [ $nb_processes -ne 0 ]; then
50
			reboot
1596 richard 51
		fi
2967 rexy 52
		;;
53
	*)
54
		for NIC in $EXTIF $INTIF
55
		do
56
			if [ `/usr/sbin/ip a show $NIC|grep DOWN|wc -l` -eq "1" ]; then
57
				echo "The network interface card '$NIC' is down! Try to enable it"
58
				/usr/sbin/ifup $NIC
59
			fi
60
		done
61
 
62
		nb_srv=0
63
		for service in $SERVICES; do
3043 rexy 64
			if [ $service == 'gammu-smsd' ]; then
2967 rexy 65
				if [ $SMS != "ON" ] && [ $SMS != "on" ] && [ $SMS != "On" ]; then
66
					nb_available_srv=$((nb_available_srv-1))
67
					continue
68
				fi
69
			fi
70
			ServiceTest $service
71
		done
72
 
73
		if [ $nb_available_srv -ne $nb_srv ]; then
74
			echo "Restart this script to know if all is ok"
75
		else
76
			echo "$nb_srv services needed by ALCASAR are started."
2601 tom.houday 77
		fi
2967 rexy 78
 
79
		if [ `cat /proc/modules|grep -c ^ipt_NETFLOW` == 0 ]; then
80
			logger -t alcasar-daemon -i "ipt_netflow is inactive."
81
			echo "The Log system is disabled! try to know why (modprobe ipt_NETFLOW)"
82
		else
83
			echo "The Log system is active"
84
		fi
85
		if [ ! -e /etc/raddb/mods-enabled/ldap ]; then
86
			if [ $LDAP == "ON" ] || [ $LDAP == "on" ] || [ $LDAP == "On" ]; then
87
				echo "Enabling LDAP..."
88
				/usr/local/bin/alcasar-ldap.sh -on
89
			fi
90
		fi
91
	;;
92
esac