Remove ramdisks for RRD databases

Ramdisks are very limited in space and as new graphs
are generated for OpenVPN N2N connections, etc. more
space is necessary.

This patch will enable ramdisks for all systems with more
than 490M of memory and allows the user to force using
a ramdisk on systems with less memory.

Signed-off-by: Alexander Marx <alexander.marx@ipfire.org>
Acked-by: Arne Fitzenreiter <arne.fitzenreiter@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
Alexander Marx
2015-12-03 13:14:23 +00:00
committed by Michael Tremer
parent 74e5c32e19
commit c4a451eead
10 changed files with 162 additions and 110 deletions

View File

@@ -77,7 +77,36 @@ case "${1}" in
rm -rf /var/run
ln -s ../run /var/run
fi
#
# create some folders
#
if [ ! -e /var/lock/subsys ]; then
mkdir -p /var/lock/subsys
fi
if [ ! -e /var/lock/time ]; then
mkdir -p /var/lock/time
chown nobody.root /var/lock/time
fi
if [ ! -e /var/run/clamav ]; then
mkdir -p /var/run/clamav
chown clamav:clamav /var/run/clamav
fi
if [ ! -e /var/run/cups ]; then
mkdir -p /var/run/cups
fi
if [ ! -e /var/run/dbus ]; then
mkdir -p /var/run/dbus
fi
if [ ! -e /var/run/mysql ]; then
mkdir -p /var/run/mysql
chown mysql:mysql /var/run/mysql
fi
if [ ! -e /var/run/saslauthd ]; then
mkdir -p /var/run/saslauthd
fi
if [ ! -e /var/log/vnstat ]; then
mkdir -p /var/log/vnstat
fi
boot_mesg -n "Cleaning file systems:" ${INFO}
boot_mesg -n " /tmp" ${NORMAL}

View File

@@ -6,6 +6,7 @@
. $rc_functions
eval $(/usr/local/bin/readhash /var/ipfire/main/settings)
eval $(/usr/local/bin/readhash /etc/sysconfig/ramdisk)
if [ "$RRDLOG" = '' ]; then
RRDLOG=/var/log/rrd
@@ -13,6 +14,35 @@ fi
case "$1" in
start)
if [ "$FORCE" == '1' ] || [ "$(mem_amount)" -gt "490" ];then
#mount ramdisk
if ! mountpoint $RRDLOG &>/dev/null; then
boot_mesg "Mount rrd Ramdisk..."
if [ $(find "$RRDLOG" | wc -l) -ne 1 ]; then
backup_ramdisk "$RRDLOG"
fi
mount_ramdisk "$RRDLOG"
evaluate_retval
#cleanup cron
if [ -e $RRDLOG.bak/cron/new.root ]; then
if [ -e $RRDLOG.bak/cron/root ]; then
rm -f $RRDLOG.bak/cron/new.root
fi
fi
#restore old values to ramdisk if exist
restore_ramdisk "$RRDLOG"
fi
else
restore_ramdisk "$RRDLOG"
fi
#
# Move /var/spool/cron to ramdisk and make a symlink
#
if [ ! -L /var/spool/cron ]; then
mv /var/spool/cron /var/log/rrd/cron
ln -s /var/log/rrd/cron /var/spool/cron
fi
# If run from init and collectd alrady started then exit silent
if [ "$(basename $0)" != "collectd" ]; then
if [ "$(ps -A | grep " collectd$")" != "" ]; then
@@ -106,10 +136,8 @@ case "$1" in
boot_mesg "Stopping Collection daemon..."
killproc /usr/sbin/collectd
evaluate_retval
# Save the ramdisk at manual stop but not at shutdown
if [ "$(basename $0)" == "collectd" ]; then
/etc/init.d/tmpfs backup
fi
backup_ramdisk "$RRDLOG"
umount_ramdisk "$RRDLOG"
# sync after backup...
sync
;;

View File

@@ -702,4 +702,35 @@ run_subdir() {
done
}
mem_amount() {
local pagesize="$(getconf PAGESIZE)"
local pages="$(getconf _PHYS_PAGES)"
echo "$(( ${pagesize} * ${pages} / 1024 / 1024 ))"
}
mount_ramdisk() {
mount -t tmpfs none $1
}
umount_ramdisk() {
if mountpoint $1 &>/dev/null; then
umount $1
fi
}
backup_ramdisk() {
if [ ! -e $1.bak ]; then
mkdir -p $1.bak
fi
cp -pR $1/* $1.bak/
rm -rf $1/*
}
restore_ramdisk() {
if [ -e $1.bak ];then
cp -pR $1.bak/* $1/
rm -rf $1.bak/*
fi
}
# End $rc_base/init.d/functions

View File

@@ -1,93 +0,0 @@
#!/bin/sh
# Begin $rc_base/init.d/tmpfs
. /etc/sysconfig/rc
. $rc_functions
eval $(/usr/local/bin/readhash /var/ipfire/main/settings)
if [ "$RRDLOG" = '' ]; then
RRDLOG=/var/log/rrd
fi
case "$1" in
start)
$0 restore
if [ ! -e $RRDLOG.bak/vnstat ]; then
mkdir -p $RRDLOG.bak/vnstat
fi
if [ ! -e $RRDLOG/vnstat ]; then
mkdir -p $RRDLOG/vnstat
fi
#
# create some folders
#
if [ ! -e /var/lock/subsys ]; then
mkdir -p /var/lock/subsys
fi
if [ ! -e /var/lock/time ]; then
mkdir -p /var/lock/time
chown nobody.root /var/lock/time
fi
if [ ! -e /var/run/clamav ]; then
mkdir -p /var/run/clamav
chown clamav:clamav /var/run/clamav
fi
if [ ! -e /var/run/cups ]; then
mkdir -p /var/run/cups
fi
if [ ! -e /var/run/dbus ]; then
mkdir -p /var/run/dbus
fi
if [ ! -e /var/run/mysql ]; then
mkdir -p /var/run/mysql
chown mysql:mysql /var/run/mysql
fi
if [ ! -e /var/run/saslauthd ]; then
mkdir -p /var/run/saslauthd
fi
#
# Move /var/spool/cron to ramdisk and make a symlink
#
if [ ! -L /var/spool/cron ]; then
cp -pR /var/spool/cron /var/log/rrd.bak/cron
mv /var/spool/cron /var/log/rrd/cron
ln -s /var/log/rrd/cron /var/spool/cron
fi
echo_ok
;;
stop)
$0 backup
;;
backup)
boot_mesg "Save ramdisk..."
cp -pR $RRDLOG/* $RRDLOG.bak/
evaluate_retval
;;
restore)
if ! mountpoint $RRDLOG &>/dev/null; then
mount -t tmpfs -o size=64M none "$RRDLOG"
fi
if [ -e $RRDLOG.bak/cron/new.root ]; then
if [ -e $RRDLOG.bak/cron/root ]; then
rm -f $RRDLOG.bak/cron/new.root
fi
fi
if [ -e $RRDLOG.bak ];then
boot_mesg "Restore ramdisk..."
cp -pR $RRDLOG.bak/* $RRDLOG/
fi
;;
*)
echo "Usage: $0 {start|stop|backup}"
exit 1
;;
esac
# End $rc_base/init.d/tmpfs

45
src/initscripts/init.d/vnstat Executable file
View File

@@ -0,0 +1,45 @@
#!/bin/sh
# Begin $rc_base/init.d/vnstat
. /etc/sysconfig/rc
. $rc_functions
eval $(/usr/local/bin/readhash /var/ipfire/main/settings)
if [ "$VNSTATLOG" = '' ]; then
VNSTATLOG=/var/log/vnstat
fi
case "$1" in
start)
if [ "$FORCE" == '1' ] || [ "$(mem_amount)" -gt "490" ];then
if ! mountpoint $VNSTATLOG &>/dev/null; then
boot_mesg "Mount vnstat ramdisk..."
if [ $(find "$VNSTATLOG" | wc -l) -ne 1 ]; then
backup_ramdisk "$VNSTATLOG"
fi
mount_ramdisk "$VNSTATLOG"
evaluate_retval
$0 restore
fi
else
restore_ramdisk "$VNSTATLOG"
fi
;;
stop)
$0 backup
umount_ramdisk "$VNSTATLOG"
;;
backup)
backup_ramdisk "$VNSTATLOG"
;;
restore)
restore_ramdisk "$VNSTATLOG"
;;
*)
echo "Usage: $0 {start|stop|backup}"
exit 1
;;
esac
# End $rc_base/init.d/vnstat