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