]> git.ipfire.org Git - people/jschlag/ipfire-2.x.git/commitdiff
ramdisk: Avoid copying data if no ramdisk is used
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 3 Dec 2015 16:03:29 +0000 (16:03 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 3 Dec 2015 16:03:29 +0000 (16:03 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/initscripts/init.d/collectd
src/initscripts/init.d/functions
src/initscripts/init.d/vnstat

index 24187d21583649ef684eba6bc4289d6482cffa13..e5c35950d2dfdb4bf78d100472d6a3882e468e9b 100644 (file)
@@ -13,20 +13,9 @@ fi
 case "$1" in
        start)
                if use_ramdisk; 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
-
-                               #restore old values to ramdisk if exist
-                               restore_ramdisk "$RRDLOG"
-                       fi
-               else
-                       restore_ramdisk "$RRDLOG"
+                       boot_mesg "Mounting RRD ramdisk..."
+                       mount_ramdisk "${RRDLOG}"
+                       evaluate_retval
                fi
 
                # If run from init and collectd alrady started then exit silent
@@ -122,10 +111,9 @@ case "$1" in
                boot_mesg "Stopping Collection daemon..."
                killproc /usr/sbin/collectd
                evaluate_retval
-               backup_ramdisk "$RRDLOG"
-               umount_ramdisk "$RRDLOG"
-               # sync after backup...
-               sync
+
+               # Umount the ramdisk (if any)
+               umount_ramdisk "${RRDLOG}"
                ;;
        restart)
                ${0} stop
index bd2c946e0de6ae62217e5a7235492e63fd81b4f9..fc4d8a4b9aff01f43884b60f55d169d3f93a5b98 100644 (file)
@@ -743,29 +743,45 @@ use_ramdisk() {
 }
 
 mount_ramdisk() {
-       mount -t tmpfs none $1
-}
+       local path="${1}"
+       local path_tmpfs="${path}.tmpfs"
 
-umount_ramdisk() {
-       if mountpoint $1 &>/dev/null; then
-               umount $1
+       # Check if the ramdisk is already mounted
+       if mountpoint "${path}" &>/dev/null; then
+               return 0
        fi
-}
 
-backup_ramdisk() {
-       if [ ! -e $1.bak ]; then
-               mkdir -p $1.bak
-       fi
+       # Create ramdisk
+       mkdir -p "${path_tmpfs}"
+       mount -t tmpfs none "${path_tmpfs}"
+
+       # Restore ramdisk content
+       cp -pR "${path}/*" "${path_tmpfs}"
 
-       cp -pR $1/* $1.bak/
-       rm -rf $1/*
+       # Move ramdisk to final destination
+       mount --move "${path_tmpfs}" "${path}"
+       rm -f "${path_tmpfs}"
 }
 
-restore_ramdisk() {
-       if [ -e $1.bak ];then
-               cp -pR $1.bak/* $1/
-               rm -rf $1.bak/*
+umount_ramdisk() {
+       local path="${1}"
+       local path_tmpfs="${path}.tmpfs"
+
+       # Check if a ramdisk is actually mounted
+       if ! mountpoint "${path}" &>/dev/null; then
+               return 0
        fi
+
+       # Move the ramdisk
+       mkdir -p "${path_tmpfs}"
+       mount --move "${path}" "${path_tmpfs}"
+
+       # Backup ramdisk content
+       cp -pR "${path_tmpfs}/*" "${path}"
+
+       # Destroy the ramdisk
+       umount "${path_tmpfs}"
+       rm -f "${path_tmpfs}"
 }
 
 # End $rc_base/init.d/functions
index 2593afe4db358c87af01ae2eda06d7a2c1c47314..05c35eefcdcd88104d248bbd5cddd11d80a816df 100755 (executable)
@@ -13,31 +13,16 @@ fi
 case "$1" in
        start)
                if use_ramdisk; 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"
+                       boot_mesg "Mounting vnstat ramdisk..."
+                       mount_ramdisk "${VNSTATLOG}"
+                       evaluate_retval
                fi
                ;;
        stop)
-               $0 backup
-               umount_ramdisk "$VNSTATLOG"
-               ;;
-       backup)
-               backup_ramdisk "$VNSTATLOG"
-               ;;
-       restore)
-               restore_ramdisk "$VNSTATLOG"
+               umount_ramdisk "${VNSTATLOG}"
                ;;
        *)
-               echo "Usage: $0 {start|stop|backup}"
+               echo "Usage: $0 {start|stop}"
                exit 1
                ;;
 esac