]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/initscripts/system/collectd
suricata: Change midstream policy to "pass-flow"
[people/pmueller/ipfire-2.x.git] / src / initscripts / system / collectd
1 #!/bin/sh
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 . /etc/sysconfig/rc
23 . $rc_functions
24
25 eval $(/usr/local/bin/readhash /var/ipfire/main/settings)
26
27 scan_for_sensors() {
28 touch /var/lock/sensors_search
29 # pre scan and try to load modules
30 "yes" | /usr/sbin/sensors-detect > /dev/null 2>&1
31 if [ -e /etc/sysconfig/lm_sensors ]; then
32
33 # Module load
34 . /etc/sysconfig/lm_sensors
35 for modul in $BUS_MODULES $HWMON_MODULES ; do
36 modprobe $modul > /dev/null 2>&1;
37 done
38 fi
39
40 # Final scan
41 "yes" | /usr/sbin/sensors-detect > /dev/null 2>&1
42
43 if [ ! -e /etc/sysconfig/lm_sensors ]; then
44 echo "#No Sensors detected " > /etc/sysconfig/lm_sensors
45 fi
46 rm /var/lock/sensors_search
47 }
48
49 if [ "$RRDLOG" = '' ]; then
50 RRDLOG=/var/log/rrd
51 fi
52
53 case "$1" in
54 start)
55 if use_ramdisk; then
56 boot_mesg "Mounting RRD ramdisk..."
57 mount_ramdisk "${RRDLOG}"
58 evaluate_retval
59 fi
60
61 # If run from init and collectd alrady started then exit silent
62 if [ "$(basename $0)" != "collectd" ]; then
63 if [ "$(ps -A | grep " collectd$")" != "" ]; then
64 exit 0
65 fi
66 fi
67
68 # ARM does not support to scan for sensors. In that case,
69 # we create an empty configuration file.
70 machine=$(uname -m)
71 if [ "${machine:0:3}" = "arm" ]; then
72 touch /etc/sysconfig/lm_sensors
73 fi
74 if [ "${machine:0:7}" = "aarch64" ]; then
75 touch /etc/sysconfig/lm_sensors
76 fi
77
78 # Do not search for sensors when running on AWS
79 if [ -e "/var/run/aws-instance-id" ]; then
80 touch /etc/sysconfig/lm_sensors
81 fi
82
83 # At first run search for sensors with sensors-detect
84 if [ ! -e /etc/sysconfig/lm_sensors ]; then
85 # Don't run at next boot again
86 touch /etc/sysconfig/lm_sensors
87 boot_mesg -n "Searching for Sensors..."
88 scan_for_sensors &
89 sleep 2
90 fi
91
92 if [ -e /var/lock/sensors_search ]; then
93 for (( i=1; i<30; i++)) do
94 if [ ! -e /var/lock/sensors_search ]; then
95 break;
96 fi
97 boot_mesg -n "."
98 sleep 2
99 done
100 fi
101 boot_mesg ""
102
103 # Load sensor modules only first start
104 if [ ! -e /var/lock/sensors_modules ]; then
105 touch /var/lock/sensors_modules
106
107 boot_mesg -n "Loading Sensor Modules: "
108 . /etc/sysconfig/lm_sensors
109 for modul in $BUS_MODULES $HWMON_MODULES ; do
110 modprobe $modul > /dev/null 2>&1;
111 if [ ${?} = 0 ]; then
112 boot_mesg -n "$SUCCESS$modul$NORMAL ";
113 else
114 boot_mesg -n "$WARNING$modul$NORMAL ";
115 fi
116 done
117 boot_mesg;
118 echo_ok;
119 fi
120
121 # Enable sensors plugin if sensors found
122 if [ "$( sensors 2>&1 | grep 'No sensors found!' | wc -l )" == "1" ]; then
123 sed -i -e "s|^LoadPlugin sensors|#LoadPlugin sensors|g" /etc/collectd.conf
124 else
125 sed -i -e "s|^#LoadPlugin sensors|LoadPlugin sensors|g" /etc/collectd.conf
126 fi
127
128 # Enable thermal plugin if thermal_zone found
129 if [ ! -e /sys/class/thermal/thermal_zone0 ]; then
130 sed -i -e 's|^include "/etc/collectd.thermal"$|#include "/etc/collectd.thermal"|g' /etc/collectd.conf
131 else
132 sed -i -e 's|^#include "/etc/collectd.thermal"$|include "/etc/collectd.thermal"|g' /etc/collectd.conf
133 fi
134
135 # Enable cpufreq plugin if cpufreq found
136 if [ ! -e /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ]; then
137 sed -i -e "s|^LoadPlugin cpufreq|#LoadPlugin cpufreq|g" /etc/collectd.conf
138 else
139 sed -i -e "s|^#LoadPlugin cpufreq|LoadPlugin cpufreq|g" /etc/collectd.conf
140 fi
141
142 # Enable swap plugin if swap found
143 if [ "$(swapon -s | wc -l)" == "0" ]; then
144 sed -i -e "s|^LoadPlugin swap|#LoadPlugin swap|g" /etc/collectd.conf
145 else
146 sed -i -e "s|^#LoadPlugin swap|LoadPlugin swap|g" /etc/collectd.conf
147 fi
148
149 if [ $(date +%Y) -gt 2011 ]; then
150 boot_mesg "Starting Collection daemon..."
151 /usr/sbin/collectd -C /etc/collectd.conf
152 evaluate_retval
153 else
154 boot_mesg "collectd: cannot start with incorrect time ($(date))."
155 echo_warning;
156 fi
157 ;;
158 stop)
159 boot_mesg "Stopping Collection daemon..."
160 killproc /usr/sbin/collectd
161 evaluate_retval
162
163 # Umount the ramdisk (if any)
164 umount_ramdisk "${RRDLOG}"
165 ;;
166 restart)
167 ${0} stop
168 sleep 1
169 ${0} start
170 ;;
171 status)
172 statusproc /usr/sbin/collectd
173 ;;
174
175 backup)
176 # Backup all data if ramdisk is used
177 if mountpoint "${RRDLOG}" &>/dev/null; then
178 ${0} restart
179 fi
180 ;;
181
182 *)
183 echo "Usage: $0 {start|stop|restart|status|backup}"
184 exit 1
185 ;;
186 esac