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