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