ramdisk: Make usage of ramdisk configurable

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
Michael Tremer
2015-12-03 14:41:49 +00:00
parent 5258a65dea
commit ee3dec50a3
4 changed files with 37 additions and 6 deletions

View File

@@ -61,8 +61,8 @@ $(TARGET) :
-rm -rf /etc/init.d
ln -svf rc.d/init.d /etc/init.d
#create ramdiskfile to force ramdiskcreation if FORCE=1
echo "FORCE=0" > /etc/sysconfig/ramdisk
# Create default ramdisk configuration
echo "RAMDISK_MODE=0" > /etc/sysconfig/ramdisk
for i in $(DIR_SRC)/src/initscripts/init.d/*; do \
install -v -m 754 $$i /etc/rc.d/init.d/; \

View File

@@ -1,12 +1,10 @@
#!/bin/sh
# Begin $rc_base/init.d/collecd
. /etc/sysconfig/rc
. $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
@@ -14,7 +12,7 @@ fi
case "$1" in
start)
if [ "$FORCE" == '1' ] || [ "$(mem_amount)" -gt "490" ];then
if use_ramdisk; then
#mount ramdisk
if ! mountpoint $RRDLOG &>/dev/null; then
boot_mesg "Mount rrd Ramdisk..."

View File

@@ -709,6 +709,39 @@ mem_amount() {
echo "$(( ${pagesize} * ${pages} / 1024 / 1024 ))"
}
use_ramdisk() {
eval $(/usr/local/bin/readhash /etc/sysconfig/ramdisk)
case "${RAMDISK_MODE}" in
# Don't use ramdisk
0)
return 1
;;
# Always use ramdisk
1)
return 0
;;
# Automatic mode - use ramdisk if sufficient
# memory is available
2)
local mem_avail="$(mem_amount)"
if [ ${mem_avail} -ge 490 ]; then
return 0
else
return 1
fi
;;
# Fail for everything else
*)
return 2
;;
esac
}
mount_ramdisk() {
mount -t tmpfs none $1
}

View File

@@ -12,7 +12,7 @@ fi
case "$1" in
start)
if [ "$FORCE" == '1' ] || [ "$(mem_amount)" -gt "490" ];then
if use_ramdisk; then
if ! mountpoint $VNSTATLOG &>/dev/null; then
boot_mesg "Mount vnstat ramdisk..."
if [ $(find "$VNSTATLOG" | wc -l) -ne 1 ]; then