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