]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/initscripts/system/collectd
cloud-init: Launch custom script when detecting Google Cloud
[people/pmueller/ipfire-2.x.git] / src / initscripts / system / collectd
CommitLineData
a332b303
CS
1#!/bin/sh
2# Begin $rc_base/init.d/collecd
3
a332b303
CS
4. /etc/sysconfig/rc
5. $rc_functions
6
1c163c04
CS
7eval $(/usr/local/bin/readhash /var/ipfire/main/settings)
8
a3b07005
AF
9scan_for_sensors() {
10 touch /var/lock/sensors_search
11 # pre scan and try to load modules
12 "yes" | /usr/sbin/sensors-detect > /dev/null
13 if [ -e /etc/sysconfig/lm_sensors ]; then
14
15 # Module load
16 . /etc/sysconfig/lm_sensors
17 for modul in $BUS_MODULES $HWMON_MODULES ; do
18 modprobe $modul > /dev/null 2>&1;
19 done
20 fi
21
22 # Final scan
23 "yes" | /usr/sbin/sensors-detect > /dev/null
24
25 if [ ! -e /etc/sysconfig/lm_sensors ]; then
26 echo "#No Sensors detected " > /etc/sysconfig/lm_sensors
27 fi
28 rm /var/lock/sensors_search
29}
30
f6b79dd2
CS
31if [ "$RRDLOG" = '' ]; then
32 RRDLOG=/var/log/rrd
33fi
34
a332b303
CS
35case "$1" in
36 start)
ee3dec50 37 if use_ramdisk; then
6146d190
MT
38 boot_mesg "Mounting RRD ramdisk..."
39 mount_ramdisk "${RRDLOG}"
40 evaluate_retval
c4a451ee 41 fi
c4a451ee 42
366aa0cb 43 # If run from init and collectd alrady started then exit silent
f950f258
AF
44 if [ "$(basename $0)" != "collectd" ]; then
45 if [ "$(ps -A | grep " collectd$")" != "" ]; then
46 exit 0
47 fi
48 fi
49
dc652b88
MT
50 # ARM does not support to scan for sensors. In that case,
51 # we create an empty configuration file.
52 machine=$(uname -m)
53 if [ "${machine:0:3}" = "arm" ]; then
54 touch /etc/sysconfig/lm_sensors
55 fi
c8dfbfab
AF
56 if [ "${machine:0:7}" = "aarch64" ]; then
57 touch /etc/sysconfig/lm_sensors
58 fi
dc652b88 59
aab33d48
MT
60 # Do not search for sensors when running on AWS
61 if [ -e "/var/run/aws-instance-id" ]; then
62 touch /etc/sysconfig/lm_sensors
63 fi
64
a68a74cb 65 # At first run search for sensors with sensors-detect
a3f2742f 66 if [ ! -e /etc/sysconfig/lm_sensors ]; then
a3b07005
AF
67 # Don't run at next boot again
68 touch /etc/sysconfig/lm_sensors
69 boot_mesg -n "Searching for Sensors..."
70 scan_for_sensors &
71 sleep 2
72 fi
1c163c04 73
a3b07005
AF
74 if [ -e /var/lock/sensors_search ]; then
75 for (( i=1; i<30; i++)) do
76 if [ ! -e /var/lock/sensors_search ]; then
77 break;
78 fi
79 boot_mesg -n "."
80 sleep 2
81 done
a3f2742f 82 fi
a3b07005 83 boot_mesg ""
a3f2742f 84
f950f258 85 # Load sensor modules only first start
366aa0cb
AF
86 if [ ! -e /var/lock/sensors_modules ]; then
87 touch /var/lock/sensors_modules
dd6c9bb9 88
f950f258 89 boot_mesg -n "Loading Sensor Modules: "
dd6c9bb9
AF
90 . /etc/sysconfig/lm_sensors
91 for modul in $BUS_MODULES $HWMON_MODULES ; do
f950f258
AF
92 modprobe $modul > /dev/null 2>&1;
93 if [ ${?} = 0 ]; then
94 boot_mesg -n "$SUCCESS$modul$NORMAL ";
95 else
96 boot_mesg -n "$WARNING$modul$NORMAL ";
97 fi
98 done
99 boot_mesg;
100 echo_ok;
101 fi
a3f2742f 102
a68a74cb 103 # Enable sensors plugin if sensors found
28ec28bc 104 if [ "$( sensors 2>&1 | grep 'No sensors found!' | wc -l )" == "1" ]; then
a68a74cb
AF
105 sed -i -e "s|^LoadPlugin sensors|#LoadPlugin sensors|g" /etc/collectd.conf
106 else
107 sed -i -e "s|^#LoadPlugin sensors|LoadPlugin sensors|g" /etc/collectd.conf
108 fi
109
110 # Enable thermal plugin if thermal_zone found
111 if [ ! -e /sys/class/thermal/thermal_zone0 ]; then
366aa0cb 112 sed -i -e 's|^include "/etc/collectd.thermal"$|#include "/etc/collectd.thermal"|g' /etc/collectd.conf
a68a74cb 113 else
366aa0cb 114 sed -i -e 's|^#include "/etc/collectd.thermal"$|include "/etc/collectd.thermal"|g' /etc/collectd.conf
a68a74cb 115 fi
6cc7c2a3
AF
116
117 # Enable cpufreq plugin if cpufreq found
79bcc6f7 118 if [ ! -e /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ]; then
6cc7c2a3
AF
119 sed -i -e "s|^LoadPlugin cpufreq|#LoadPlugin cpufreq|g" /etc/collectd.conf
120 else
121 sed -i -e "s|^#LoadPlugin cpufreq|LoadPlugin cpufreq|g" /etc/collectd.conf
122 fi
a68a74cb
AF
123
124 # Enable swap plugin if swap found
893ef99e 125 if [ "$(swapon -s | wc -l)" == "0" ]; then
a68a74cb
AF
126 sed -i -e "s|^LoadPlugin swap|#LoadPlugin swap|g" /etc/collectd.conf
127 else
128 sed -i -e "s|^#LoadPlugin swap|LoadPlugin swap|g" /etc/collectd.conf
129 fi
08215cb5
AF
130
131 # sync after config update...
132 sync
a68a74cb 133
15eb7e0a
AF
134 if [ $(date +%Y) -gt 2011 ]; then
135 boot_mesg "Starting Collection daemon..."
136 /usr/sbin/collectd -C /etc/collectd.conf
137 evaluate_retval
138 else
139 boot_mesg "collectd: cannot start with incorrect time ($(date))."
140 echo_warning;
141 fi
a332b303 142 ;;
a332b303 143 stop)
4c89f6d4
AF
144 boot_mesg "Stopping Collection daemon..."
145 killproc /usr/sbin/collectd
146 evaluate_retval
6146d190
MT
147
148 # Umount the ramdisk (if any)
149 umount_ramdisk "${RRDLOG}"
a332b303 150 ;;
a332b303 151 restart)
1c163c04 152 ${0} stop
a332b303 153 sleep 1
1c163c04
CS
154 ${0} start
155 ;;
a332b303
CS
156 status)
157 statusproc /usr/sbin/collectd
158 ;;
159
08729f79
MT
160 backup)
161 # Backup all data if ramdisk is used
162 if mountpoint "${RRDLOG}" &>/dev/null; then
163 ${0} restart
164 fi
165 ;;
166
a332b303 167 *)
08729f79 168 echo "Usage: $0 {start|stop|restart|status|backup}"
a332b303
CS
169 exit 1
170 ;;
171esac
172
173# End $rc_base/init.d/collectd