Adding swap space on DigitalOcean during installation

There is a great tutorial for adding swap space to a server (aka “droplet”) on DigitalOcean at How To Add Swap Space on Ubuntu 22.04 | DigitalOcean

It essentially involves accessing the console and typing in commands, one after another:

sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
sudo nano /etc/sysctl.conf


I’m wondering whether there is some code or commands I can input, or process I can follow, in order to automatically add this swap space to every new Ghost install I create.

Rather than (my current method of) creating a Ghost install, then logging back into the console and typing in all of these commands manually.

Adding swap space is simple, but because I’m creating new sites frequently, doing so manually becomes quite a tedious process.

Any help or advice would be much appreciated.

You can use a simple script and add it to your services manager but it seems to be related to your host and not Ghost itself.