]>
Commit | Line | Data |
---|---|---|
a332b303 | 1 | #!/bin/sh |
66c36198 PM |
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 | ############################################################################### | |
a332b303 | 21 | |
a332b303 CS |
22 | . /etc/sysconfig/rc |
23 | . $rc_functions | |
24 | ||
1c163c04 CS |
25 | eval $(/usr/local/bin/readhash /var/ipfire/main/settings) |
26 | ||
a3b07005 AF |
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 | |
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 | |
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 | ||
f6b79dd2 CS |
49 | if [ "$RRDLOG" = '' ]; then |
50 | RRDLOG=/var/log/rrd | |
51 | fi | |
52 | ||
a332b303 CS |
53 | case "$1" in |
54 | start) | |
ee3dec50 | 55 | if use_ramdisk; then |
6146d190 MT |
56 | boot_mesg "Mounting RRD ramdisk..." |
57 | mount_ramdisk "${RRDLOG}" | |
58 | evaluate_retval | |
c4a451ee | 59 | fi |
c4a451ee | 60 | |
366aa0cb | 61 | # If run from init and collectd alrady started then exit silent |
f950f258 AF |
62 | if [ "$(basename $0)" != "collectd" ]; then |
63 | if [ "$(ps -A | grep " collectd$")" != "" ]; then | |
64 | exit 0 | |
65 | fi | |
66 | fi | |
67 | ||
dc652b88 MT |
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 | |
c8dfbfab AF |
74 | if [ "${machine:0:7}" = "aarch64" ]; then |
75 | touch /etc/sysconfig/lm_sensors | |
76 | fi | |
dc652b88 | 77 | |
aab33d48 MT |
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 | ||
a68a74cb | 83 | # At first run search for sensors with sensors-detect |
a3f2742f | 84 | if [ ! -e /etc/sysconfig/lm_sensors ]; then |
a3b07005 AF |
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 | |
1c163c04 | 91 | |
a3b07005 AF |
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 | |
a3f2742f | 100 | fi |
a3b07005 | 101 | boot_mesg "" |
a3f2742f | 102 | |
f950f258 | 103 | # Load sensor modules only first start |
366aa0cb AF |
104 | if [ ! -e /var/lock/sensors_modules ]; then |
105 | touch /var/lock/sensors_modules | |
dd6c9bb9 | 106 | |
f950f258 | 107 | boot_mesg -n "Loading Sensor Modules: " |
dd6c9bb9 AF |
108 | . /etc/sysconfig/lm_sensors |
109 | for modul in $BUS_MODULES $HWMON_MODULES ; do | |
f950f258 AF |
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 | |
a3f2742f | 120 | |
a68a74cb | 121 | # Enable sensors plugin if sensors found |
28ec28bc | 122 | if [ "$( sensors 2>&1 | grep 'No sensors found!' | wc -l )" == "1" ]; then |
a68a74cb AF |
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 | |
366aa0cb | 130 | sed -i -e 's|^include "/etc/collectd.thermal"$|#include "/etc/collectd.thermal"|g' /etc/collectd.conf |
a68a74cb | 131 | else |
366aa0cb | 132 | sed -i -e 's|^#include "/etc/collectd.thermal"$|include "/etc/collectd.thermal"|g' /etc/collectd.conf |
a68a74cb | 133 | fi |
6cc7c2a3 AF |
134 | |
135 | # Enable cpufreq plugin if cpufreq found | |
79bcc6f7 | 136 | if [ ! -e /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ]; then |
6cc7c2a3 AF |
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 | |
a68a74cb AF |
141 | |
142 | # Enable swap plugin if swap found | |
893ef99e | 143 | if [ "$(swapon -s | wc -l)" == "0" ]; then |
a68a74cb AF |
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 | |
66c36198 | 148 | |
08215cb5 AF |
149 | # sync after config update... |
150 | sync | |
a68a74cb | 151 | |
15eb7e0a AF |
152 | if [ $(date +%Y) -gt 2011 ]; then |
153 | boot_mesg "Starting Collection daemon..." | |
154 | /usr/sbin/collectd -C /etc/collectd.conf | |
155 | evaluate_retval | |
156 | else | |
157 | boot_mesg "collectd: cannot start with incorrect time ($(date))." | |
158 | echo_warning; | |
159 | fi | |
a332b303 | 160 | ;; |
a332b303 | 161 | stop) |
4c89f6d4 AF |
162 | boot_mesg "Stopping Collection daemon..." |
163 | killproc /usr/sbin/collectd | |
164 | evaluate_retval | |
6146d190 MT |
165 | |
166 | # Umount the ramdisk (if any) | |
167 | umount_ramdisk "${RRDLOG}" | |
a332b303 | 168 | ;; |
a332b303 | 169 | restart) |
1c163c04 | 170 | ${0} stop |
a332b303 | 171 | sleep 1 |
1c163c04 CS |
172 | ${0} start |
173 | ;; | |
a332b303 CS |
174 | status) |
175 | statusproc /usr/sbin/collectd | |
176 | ;; | |
177 | ||
08729f79 MT |
178 | backup) |
179 | # Backup all data if ramdisk is used | |
180 | if mountpoint "${RRDLOG}" &>/dev/null; then | |
181 | ${0} restart | |
182 | fi | |
183 | ;; | |
184 | ||
a332b303 | 185 | *) |
08729f79 | 186 | echo "Usage: $0 {start|stop|restart|status|backup}" |
a332b303 CS |
187 | exit 1 |
188 | ;; | |
189 | esac |