Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
case "$1" in
start)
if use_ramdisk; then
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
fi
# If run from init and collectd alrady started then exit silent
boot_mesg "Stopping Collection daemon..."
killproc /usr/sbin/collectd
evaluate_retval
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}"
- 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
-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
+
+ # 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
}
# End $rc_base/init.d/functions
case "$1" in
start)
if use_ramdisk; then
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
- $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}"