Errors from Port Number Already In Use

I run many Ghost sites/instances on my Managed VPS. If I spin up a new Ghost site while any one of the other sites on the same VPS is stopped, the new Ghost site will assign/use the same port number of the stopped instance (detecting that port as unused.)

This results in 2 or more separate Ghost sites using the same port number, which can cause 503 errors, as well as URLs arriving at the wrong sites, and multiple URLs arriving at the same site.

The most simple fix for this I’ve discovered is to change the port number(s) of the site(s) to an unused port.

I can discover the port numbers of all of my Ghost installs in the terminal using the command ghost ls:

To change the port number for a Ghost site, I edit the port number in both of these 2 files (followed by restarting the server):