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