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