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