]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/initscripts/system/collectd
suricata: use KILL is suricata not shut down normal.
[people/pmueller/ipfire-2.x.git] / src / initscripts / system / collectd
CommitLineData
a332b303
CS
1#!/bin/sh
2# Begin $rc_base/init.d/collecd
3
a332b303
CS
4. /etc/sysconfig/rc
5. $rc_functions
6
1c163c04
CS
7eval $(/usr/local/bin/readhash /var/ipfire/main/settings)
8
f6b79dd2
CS
9if [ "$RRDLOG" = '' ]; then
10 RRDLOG=/var/log/rrd
11fi
12
a332b303
CS
13case "$1" in
14 start)
ee3dec50 15 if use_ramdisk; then
6146d190
MT
16 boot_mesg "Mounting RRD ramdisk..."
17 mount_ramdisk "${RRDLOG}"
18 evaluate_retval
c4a451ee 19 fi
c4a451ee 20
366aa0cb 21 # If run from init and collectd alrady started then exit silent
f950f258
AF
22 if [ "$(basename $0)" != "collectd" ]; then
23 if [ "$(ps -A | grep " collectd$")" != "" ]; then
24 exit 0
25 fi
26 fi
27
dc652b88
MT
28 # ARM does not support to scan for sensors. In that case,
29 # we create an empty configuration file.
30 machine=$(uname -m)
31 if [ "${machine:0:3}" = "arm" ]; then
32 touch /etc/sysconfig/lm_sensors
33 fi
c8dfbfab
AF
34 if [ "${machine:0:7}" = "aarch64" ]; then
35 touch /etc/sysconfig/lm_sensors
36 fi
dc652b88 37
aab33d48
MT
38 # Do not search for sensors when running on AWS
39 if [ -e "/var/run/aws-instance-id" ]; then
40 touch /etc/sysconfig/lm_sensors
41 fi
42
a68a74cb 43 # At first run search for sensors with sensors-detect
a3f2742f 44 if [ ! -e /etc/sysconfig/lm_sensors ]; then
1c163c04 45 boot_mesg "Searching for Sensors..."
5b55f2f8 46
888541fc 47 # pre scan and try to load modules
5b55f2f8 48 "yes" | /usr/sbin/sensors-detect > /dev/null
888541fc 49 if [ -e /etc/sysconfig/lm_sensors ]; then
dd6c9bb9 50
888541fc 51 # Module load
dd6c9bb9
AF
52 . /etc/sysconfig/lm_sensors
53 for modul in $BUS_MODULES $HWMON_MODULES ; do
888541fc
AF
54 modprobe $modul > /dev/null 2>&1;
55 done
56 fi
5b55f2f8 57
888541fc 58 # Final scan
1c163c04
CS
59 "yes" | /usr/sbin/sensors-detect > /dev/null
60 evaluate_retval
61
62 if [ ! -e /etc/sysconfig/lm_sensors ]; then
63 echo "#No Sensors detected " > /etc/sysconfig/lm_sensors
1c163c04 64 fi
a3f2742f
AF
65 fi
66
f950f258 67 # Load sensor modules only first start
366aa0cb
AF
68 if [ ! -e /var/lock/sensors_modules ]; then
69 touch /var/lock/sensors_modules
dd6c9bb9 70
f950f258 71 boot_mesg -n "Loading Sensor Modules: "
dd6c9bb9
AF
72 . /etc/sysconfig/lm_sensors
73 for modul in $BUS_MODULES $HWMON_MODULES ; do
f950f258
AF
74 modprobe $modul > /dev/null 2>&1;
75 if [ ${?} = 0 ]; then
76 boot_mesg -n "$SUCCESS$modul$NORMAL ";
77 else
78 boot_mesg -n "$WARNING$modul$NORMAL ";
79 fi
80 done
81 boot_mesg;
82 echo_ok;
83 fi
a3f2742f 84
a68a74cb 85 # Enable sensors plugin if sensors found
28ec28bc 86 if [ "$( sensors 2>&1 | grep 'No sensors found!' | wc -l )" == "1" ]; then
a68a74cb
AF
87 sed -i -e "s|^LoadPlugin sensors|#LoadPlugin sensors|g" /etc/collectd.conf
88 else
89 sed -i -e "s|^#LoadPlugin sensors|LoadPlugin sensors|g" /etc/collectd.conf
90 fi
91
92 # Enable thermal plugin if thermal_zone found
93 if [ ! -e /sys/class/thermal/thermal_zone0 ]; then
366aa0cb 94 sed -i -e 's|^include "/etc/collectd.thermal"$|#include "/etc/collectd.thermal"|g' /etc/collectd.conf
a68a74cb 95 else
366aa0cb 96 sed -i -e 's|^#include "/etc/collectd.thermal"$|include "/etc/collectd.thermal"|g' /etc/collectd.conf
a68a74cb 97 fi
6cc7c2a3
AF
98
99 # Enable cpufreq plugin if cpufreq found
79bcc6f7 100 if [ ! -e /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ]; then
6cc7c2a3
AF
101 sed -i -e "s|^LoadPlugin cpufreq|#LoadPlugin cpufreq|g" /etc/collectd.conf
102 else
103 sed -i -e "s|^#LoadPlugin cpufreq|LoadPlugin cpufreq|g" /etc/collectd.conf
104 fi
a68a74cb
AF
105
106 # Enable swap plugin if swap found
893ef99e 107 if [ "$(swapon -s | wc -l)" == "0" ]; then
a68a74cb
AF
108 sed -i -e "s|^LoadPlugin swap|#LoadPlugin swap|g" /etc/collectd.conf
109 else
110 sed -i -e "s|^#LoadPlugin swap|LoadPlugin swap|g" /etc/collectd.conf
111 fi
08215cb5
AF
112
113 # sync after config update...
114 sync
a68a74cb 115
15eb7e0a
AF
116 if [ $(date +%Y) -gt 2011 ]; then
117 boot_mesg "Starting Collection daemon..."
118 /usr/sbin/collectd -C /etc/collectd.conf
119 evaluate_retval
120 else
121 boot_mesg "collectd: cannot start with incorrect time ($(date))."
122 echo_warning;
123 fi
a332b303 124 ;;
a332b303 125 stop)
4c89f6d4
AF
126 boot_mesg "Stopping Collection daemon..."
127 killproc /usr/sbin/collectd
128 evaluate_retval
6146d190
MT
129
130 # Umount the ramdisk (if any)
131 umount_ramdisk "${RRDLOG}"
a332b303 132 ;;
a332b303 133 restart)
1c163c04 134 ${0} stop
a332b303 135 sleep 1
1c163c04
CS
136 ${0} start
137 ;;
a332b303
CS
138 status)
139 statusproc /usr/sbin/collectd
140 ;;
141
08729f79
MT
142 backup)
143 # Backup all data if ramdisk is used
144 if mountpoint "${RRDLOG}" &>/dev/null; then
145 ${0} restart
146 fi
147 ;;
148
a332b303 149 *)
08729f79 150 echo "Usage: $0 {start|stop|restart|status|backup}"
a332b303
CS
151 exit 1
152 ;;
153esac
154
155# End $rc_base/init.d/collectd