]> git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/init.d/collectd
Merge remote-tracking branch 'mfischer/expat' into next
[ipfire-2.x.git] / src / initscripts / init.d / collectd
1 #!/bin/sh
2 # Begin $rc_base/init.d/collecd
3
4
5 . /etc/sysconfig/rc
6 . $rc_functions
7
8 eval $(/usr/local/bin/readhash /var/ipfire/main/settings)
9
10 if [ "$RRDLOG" = '' ]; then
11 RRDLOG=/var/log/rrd
12 fi
13
14 case "$1" in
15 start)
16 # If run from init and collectd alrady started then exit silent
17 if [ "$(basename $0)" != "collectd" ]; then
18 if [ "$(ps -A | grep " collectd$")" != "" ]; then
19 exit 0
20 fi
21 fi
22
23 # ARM does not support to scan for sensors. In that case,
24 # we create an empty configuration file.
25 machine=$(uname -m)
26 if [ "${machine:0:3}" = "arm" ]; then
27 touch /etc/sysconfig/lm_sensors
28 fi
29
30 # At first run search for sensors with sensors-detect
31 if [ ! -e /etc/sysconfig/lm_sensors ]; then
32 boot_mesg "Searching for Sensors..."
33
34 # pre scan and try to load modules
35 "yes" | /usr/sbin/sensors-detect > /dev/null
36 if [ -e /etc/sysconfig/lm_sensors ]; then
37
38 # Module load
39 . /etc/sysconfig/lm_sensors
40 for modul in $BUS_MODULES $HWMON_MODULES ; do
41 modprobe $modul > /dev/null 2>&1;
42 done
43 fi
44
45 # Final scan
46 "yes" | /usr/sbin/sensors-detect > /dev/null
47 evaluate_retval
48
49 if [ ! -e /etc/sysconfig/lm_sensors ]; then
50 echo "#No Sensors detected " > /etc/sysconfig/lm_sensors
51 fi
52 fi
53
54 # Load sensor modules only first start
55 if [ ! -e /var/lock/sensors_modules ]; then
56 touch /var/lock/sensors_modules
57
58 boot_mesg -n "Loading Sensor Modules: "
59 . /etc/sysconfig/lm_sensors
60 for modul in $BUS_MODULES $HWMON_MODULES ; do
61 modprobe $modul > /dev/null 2>&1;
62 if [ ${?} = 0 ]; then
63 boot_mesg -n "$SUCCESS$modul$NORMAL ";
64 else
65 boot_mesg -n "$WARNING$modul$NORMAL ";
66 fi
67 done
68 boot_mesg;
69 echo_ok;
70 fi
71
72 # Enable sensors plugin if sensors found
73 if [ "$( sensors 2>&1 | grep 'No sensors found!' | wc -l )" == "1" ]; then
74 sed -i -e "s|^LoadPlugin sensors|#LoadPlugin sensors|g" /etc/collectd.conf
75 else
76 sed -i -e "s|^#LoadPlugin sensors|LoadPlugin sensors|g" /etc/collectd.conf
77 fi
78
79 # Enable thermal plugin if thermal_zone found
80 if [ ! -e /sys/class/thermal/thermal_zone0 ]; then
81 sed -i -e 's|^include "/etc/collectd.thermal"$|#include "/etc/collectd.thermal"|g' /etc/collectd.conf
82 else
83 sed -i -e 's|^#include "/etc/collectd.thermal"$|include "/etc/collectd.thermal"|g' /etc/collectd.conf
84 fi
85
86 # Enable swap plugin if swap found
87 if [ "$(swapon -s | wc -l)" == "0" ]; then
88 sed -i -e "s|^LoadPlugin swap|#LoadPlugin swap|g" /etc/collectd.conf
89 else
90 sed -i -e "s|^#LoadPlugin swap|LoadPlugin swap|g" /etc/collectd.conf
91 fi
92
93 # sync after config update...
94 sync
95
96 if [ $(date +%Y) -gt 2011 ]; then
97 boot_mesg "Starting Collection daemon..."
98 /usr/sbin/collectd -C /etc/collectd.conf
99 evaluate_retval
100 else
101 boot_mesg "collectd: cannot start with incorrect time ($(date))."
102 echo_warning;
103 fi
104 ;;
105 stop)
106 boot_mesg "Stopping Collection daemon..."
107 killproc /usr/sbin/collectd
108 evaluate_retval
109 # Save the ramdisk at manual stop but not at shutdown
110 if [ "$(basename $0)" == "collectd" ]; then
111 /etc/init.d/tmpfs backup
112 fi
113 # sync after backup...
114 sync
115 ;;
116 restart)
117 ${0} stop
118 sleep 1
119 ${0} start
120 ;;
121 status)
122 statusproc /usr/sbin/collectd
123 ;;
124
125 *)
126 echo "Usage: $0 {start|stop|restart|status}"
127 exit 1
128 ;;
129 esac
130
131 # End $rc_base/init.d/collectd