]> git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/system/collectd
unbound: Drop certificates for local control connection
[ipfire-2.x.git] / src / initscripts / system / 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 if [ "${machine:0:7}" = "aarch64" ]; then
35 touch /etc/sysconfig/lm_sensors
36 fi
37
38 # At first run search for sensors with sensors-detect
39 if [ ! -e /etc/sysconfig/lm_sensors ]; then
40 boot_mesg "Searching for Sensors..."
41
42 # pre scan and try to load modules
43 "yes" | /usr/sbin/sensors-detect > /dev/null
44 if [ -e /etc/sysconfig/lm_sensors ]; then
45
46 # Module load
47 . /etc/sysconfig/lm_sensors
48 for modul in $BUS_MODULES $HWMON_MODULES ; do
49 modprobe $modul > /dev/null 2>&1;
50 done
51 fi
52
53 # Final scan
54 "yes" | /usr/sbin/sensors-detect > /dev/null
55 evaluate_retval
56
57 if [ ! -e /etc/sysconfig/lm_sensors ]; then
58 echo "#No Sensors detected " > /etc/sysconfig/lm_sensors
59 fi
60 fi
61
62 # Load sensor modules only first start
63 if [ ! -e /var/lock/sensors_modules ]; then
64 touch /var/lock/sensors_modules
65
66 boot_mesg -n "Loading Sensor Modules: "
67 . /etc/sysconfig/lm_sensors
68 for modul in $BUS_MODULES $HWMON_MODULES ; do
69 modprobe $modul > /dev/null 2>&1;
70 if [ ${?} = 0 ]; then
71 boot_mesg -n "$SUCCESS$modul$NORMAL ";
72 else
73 boot_mesg -n "$WARNING$modul$NORMAL ";
74 fi
75 done
76 boot_mesg;
77 echo_ok;
78 fi
79
80 # Enable sensors plugin if sensors found
81 if [ "$( sensors 2>&1 | grep 'No sensors found!' | wc -l )" == "1" ]; then
82 sed -i -e "s|^LoadPlugin sensors|#LoadPlugin sensors|g" /etc/collectd.conf
83 else
84 sed -i -e "s|^#LoadPlugin sensors|LoadPlugin sensors|g" /etc/collectd.conf
85 fi
86
87 # Enable thermal plugin if thermal_zone found
88 if [ ! -e /sys/class/thermal/thermal_zone0 ]; then
89 sed -i -e 's|^include "/etc/collectd.thermal"$|#include "/etc/collectd.thermal"|g' /etc/collectd.conf
90 else
91 sed -i -e 's|^#include "/etc/collectd.thermal"$|include "/etc/collectd.thermal"|g' /etc/collectd.conf
92 fi
93
94 # Enable cpufreq plugin if cpufreq found
95 if [ ! -e /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ]; then
96 sed -i -e "s|^LoadPlugin cpufreq|#LoadPlugin cpufreq|g" /etc/collectd.conf
97 else
98 sed -i -e "s|^#LoadPlugin cpufreq|LoadPlugin cpufreq|g" /etc/collectd.conf
99 fi
100
101 # Enable swap plugin if swap found
102 if [ "$(swapon -s | wc -l)" == "0" ]; then
103 sed -i -e "s|^LoadPlugin swap|#LoadPlugin swap|g" /etc/collectd.conf
104 else
105 sed -i -e "s|^#LoadPlugin swap|LoadPlugin swap|g" /etc/collectd.conf
106 fi
107
108 # sync after config update...
109 sync
110
111 if [ $(date +%Y) -gt 2011 ]; then
112 boot_mesg "Starting Collection daemon..."
113 /usr/sbin/collectd -C /etc/collectd.conf
114 evaluate_retval
115 else
116 boot_mesg "collectd: cannot start with incorrect time ($(date))."
117 echo_warning;
118 fi
119 ;;
120 stop)
121 boot_mesg "Stopping Collection daemon..."
122 killproc /usr/sbin/collectd
123 evaluate_retval
124
125 # Umount the ramdisk (if any)
126 umount_ramdisk "${RRDLOG}"
127 ;;
128 restart)
129 ${0} stop
130 sleep 1
131 ${0} start
132 ;;
133 status)
134 statusproc /usr/sbin/collectd
135 ;;
136
137 backup)
138 # Backup all data if ramdisk is used
139 if mountpoint "${RRDLOG}" &>/dev/null; then
140 ${0} restart
141 fi
142 ;;
143
144 *)
145 echo "Usage: $0 {start|stop|restart|status|backup}"
146 exit 1
147 ;;
148 esac
149
150 # End $rc_base/init.d/collectd