littlebizzy / slickstack

Lightning-fast WordPress on Nginx
https://slickstack.io
GNU General Public License v3.0
629 stars 112 forks source link

Can't update or reinstall due to "swapfile already exists" error #135

Closed skilver-io closed 2 years ago

skilver-io commented 2 years ago

Hi @jessuppi ,

Unfortunately, the SS can't be updated or installed again once the swapfile was created. The install process will exit:

Running ss-install-ubuntu-swapfile: Reinstalls the Ubuntu (OS) swap file as backup virtual memory (idempotent)...
Exiting ss-install-ubuntu-swapfile: Swapfile already exists and active so exiting the script now...

I tried some workarounds without success:

  1. Removing swapfile: Permission denied
  2. Setting variable SS_SWAPFILE_SIZE="false" in ss-config: No effect
  3. Sudo bash /var/www/ss-install-ubuntu-swapfile; Swapfile already exist error

The existing swapfile is not taken into account in the slickstack/bash/ss-install-ubuntu-swapfile.txt

####################################################################################################
#### C. SS-Install-Ubuntu-Swapfile: Check If Swapfile Exists Before Proceeding #####################
####################################################################################################

if [[ -n $(grep "swapfile" /etc/fstab) ]]; then
    echo -e "${COLOR_WARN}Exiting ss-install-ubuntu-swapfile: Swapfile already exists and active so exiting the script now... ${NOCOLOR}"
    swapon --show
    exit 1
fi

Is there any workaround for now?

Best, Den

jessuppi commented 2 years ago

Thanks for the feedback @skilver-io

I haven't tested this since your report however the purpose of that snippet is that ss-install-ubuntu-swapfile will not try to install any swapfile if an existing swapfile is detected in /etc/fstab

So the ss-install routine (etc) should still be able to continue fine, at least in theory.

This snippet was added a few days ago because I noticed some cloud providers like Vultr seem to now be adding swapfiles automatically in some cases under /swapfile filepath, which means that SlickStack literally cannot install a new swap using our own scripts in those situations.

jessuppi commented 2 years ago

Sorry I think I understand what you're saying now, the exit 1 stops the entire ss-install from running?

Ref: https://unix.stackexchange.com/questions/217650/call-a-script-for-another-script-but-dont-exit-the-parent-if-the-child-calls-e

Ref: https://unix.stackexchange.com/questions/460099/how-can-i-skip-the-rest-of-a-script-without-exiting-the-invoking-shell-when-sou

I've never played with the return function (instead of exit) because from my understanding, that would mean scripts such as ss-install-ubuntu-swapfile can no longer be called as independent scripts.

And wrapping the entire script in a bash function would still "run" the rest of the script which is janky IMO.

I'm not sure what the cleanest solution would be here.

jessuppi commented 2 years ago

Commented out for now:

Ref: https://github.com/littlebizzy/slickstack/commit/499bc8a659135f5c30ce298d5435b4db2a205ad5

skilver-io commented 2 years ago

Hi @jessuppi,

Sorry I think I understand what you're saying now, the exit 1 stops the entire ss-install from running?

Yes, the entire SS installation process will exit.

Shouldn't it be ok to reverse the if statement to check if there is no swapfile? The rest of the code would go inside of the if statement and only run if there is no swapfile found. In this case no exit is needed.

I also want to suggest to move the $SS_SWAPFILE" != "false" statement to the very beginning, since there shouldn't be any reason to run the script at all if the option is turned off.

Best, Den

jessuppi commented 2 years ago

Had to comment out this one too for now:

Ref: https://github.com/littlebizzy/slickstack/commit/782d602529dc2dd98edf446b8b1a1528c602d876

ss-perms-ubuntu-swapfile

jessuppi commented 2 years ago

I also want to suggest to move the $SS_SWAPFILE" != "false" statement to the very beginning, since there shouldn't be any reason to run the script at all if the option is turned off.

Preparing to do this: https://github.com/littlebizzy/slickstack/commit/2fd93dcc3f06816dacaec821f7e88d5001dcee4b

Shouldn't it be ok to reverse the if statement to check if there is no swapfile? The rest of the code would go inside of the if statement and only run if there is no swapfile found. In this case no exit is needed.

You are correct, however I have tried to avoid putting entire bash scripts inside if statements because it just feels janky and makes it harder to read and format the code.

It is sort of the same concept on those Stack Exchange links, putting the entire thing in a bash function.

jessuppi commented 2 years ago

After more consideration and after some providers like Vultr began force-installing 2GB swapfiles, we decided that swapfiles will now be required for SlickStack, and only the 2GB size will be installed going forward, regardless of how much space that your server might have on disk... anyway, larger servers tend to have more RAM anyways.

Therefore SS_SWAPFILE option is now removed from ss-config and more importantly, the script will no longer exit in any case and it will simply check if swap exists yet or not before installeding:

Ref: https://github.com/littlebizzy/slickstack/blob/master/bash/ss-install-ubuntu-swapfile.txt

if [[ -z $(grep "swapfile" /etc/fstab 2> /dev/null) ]] && [[ $DISK_REMAINING_MB -gt 5000 ]]; then
...

While some general code cleanup would be nice, this Issue should now be resolved.