diff options
-rwxr-xr-x | bin/ncp-diag | 1 | ||||
-rw-r--r-- | etc/nextcloudpi-config.d/nc-swapfile.sh | 25 |
2 files changed, 20 insertions, 6 deletions
diff --git a/bin/ncp-diag b/bin/ncp-diag index 6289fb98..e58afe72 100755 --- a/bin/ncp-diag +++ b/bin/ncp-diag @@ -32,6 +32,7 @@ echo "datadir|$DATADIR$DIRINFO" echo "data disk usage|$( df -h "$DATADIR" | tail -1 | awk '{ print $3"/"$2 }')" } echo "rootfs usage|$( df -h / | tail -1 | awk '{ print $3"/"$2 }')" +echo "swapfile|$( swapon | tail -1 | awk '{ print $1 }' )" # Nextcloud VERSION="$( sudo -u www-data php /var/www/nextcloud/occ status | grep "version:" | awk '{ print $3 }' )" diff --git a/etc/nextcloudpi-config.d/nc-swapfile.sh b/etc/nextcloudpi-config.d/nc-swapfile.sh index cd0a23fb..7587847b 100644 --- a/etc/nextcloudpi-config.d/nc-swapfile.sh +++ b/etc/nextcloudpi-config.d/nc-swapfile.sh @@ -26,21 +26,34 @@ is_active() configure() { - local ORIG=$( grep -oP "CONF_SWAPFILE=.*" /etc/dphys-swapfile | cut -f2 -d= ) - [[ "$ORIG" == "$SWAPFILE_" ]] && return - test -d "$SWAPFILE_" && { echo "$SWAPFILE_ is a directory. Abort"; return 1; } + local ORIG="$( swapon | tail -1 | awk '{ print $1 }' )" + local DSTDIR="$( dirname "$SWAPFILE_" )" + [[ "$ORIG" == "$SWAPFILE_" ]] && { echo "nothing to do"; return 0; } + [[ -d "$SWAPFILE_" ]] && { echo "$SWAPFILE_ is a directory. Abort"; return 1; } + [[ -d "$DSTDIR" ]] || { echo "$DSTDIR Doesn't exist. Abort"; return 1; } - [[ $( stat -fc%d / ) == $( stat -fc%d $( dirname "$SWAPFILE_" ) ) ]] && \ + [[ "$( stat -fc%T "$DSTDIR" )" == "btrfs" ]] && { + echo "BTRFS doesn't support swapfiles" + return 1 + } + + [[ $( stat -fc%d / ) == $( stat -fc%d "$DSTDIR" ) ]] && \ echo -e "INFO: moving swapfile to another place in the same SD card\nIf you want to use an external mount, make sure it is properly set up" sed -i "s|#\?CONF_SWAPFILE=.*|CONF_SWAPFILE=$SWAPFILE_|" /etc/dphys-swapfile sed -i "s|#\?CONF_SWAPSIZE=.*|CONF_SWAPSIZE=$SWAPSIZE_|" /etc/dphys-swapfile - grep -q vm.swappiness /etc/sysctl.conf || echo "vm.swappiness = 10" >> /etc/sysctl.conf && sysctl --load + grep -q vm.swappiness /etc/sysctl.conf || echo "vm.swappiness = 10" >> /etc/sysctl.conf && sysctl --load &>/dev/null # workaround for automount, systemd doesn't get the order right grep -q sleep /etc/init.d/dphys-swapfile || sed -i "/\<start)/asleep 15" /etc/init.d/dphys-swapfile - service dphys-swapfile restart && swapoff "$ORIG" && rm -f "$ORIG" + dphys-swapfile setup && dphys-swapfile swapon && { + [[ -f "$ORIG" ]] && swapoff "$ORIG" && rm -f "$ORIG" + echo "swapfile moved successfully" + return 0 + } + echo "moving swapfile failed" + return 1 } install() { :; } |