diff --git a/etc-init.d-swapfile b/etc-init.d-swapfile index b5f9773..24980a5 100644 --- a/etc-init.d-swapfile +++ b/etc-init.d-swapfile @@ -8,7 +8,8 @@ EXTRA_COMMANDS="status create" EXTRA_HELP=" status Check service status create Create a swapfile" -SWPATH="/mnt/routerdata/swapfile" +# default value, it'd be better to use other place than overlay +SWPATH="/overlay/swapfile" boot() { if [ -f $SWPATH ]; then @@ -56,7 +57,11 @@ stop() { create() { RAMTOTAL=`fgrep MemTotal /proc/meminfo | awk '{print $2}'` SWAPTOTAL=`fgrep SwapTotal /proc/meminfo | awk '{print $2}'` - if [ $SWAPTOTAL != 0 ]; then + OVERLAYSIZE=`df | grep overlayfs | awk '{print $3}'` + if [ $OVERLAYSIZE < $RAMTOTAL ]; then + echo "ERROR: Not enough storage for a swapfile, quitting..." + exit 1 + elif [ $SWAPTOTAL != 0 ]; then echo "ERROR: Swap already in use, quitting..." else dd if=/dev/zero of=$SWFILE bs=1024 count=$RAMTOTAL