Lightsail AWS Node.js start forever

1.7k Views Asked by At

I'm experimenting with Vapid CMS and I want to upload a new site to my Amazon Lightsail server. Vapid is dependent on Node.js and I was able to download Vapid to my account and get everything set up with the static IP address I have through AWS.

The way Vapid works is that once you're in the root folder you call vapid start . to start the server and see your site/get access to the dashboard. I have it set up so that the static IP address of the AWS server redirects to the default http://localhost:3000 that is activated when you start up Vapid.

The main problem I'm having is that the Vapid site doesn't stay active very long. If I exit out of the AWS terminal after stating Vapid, in a few minutes the site goes to "Service Unavailable." Is there a way to keep that sucker running forever so that my site stays up until the end of time?

2

There are 2 best solutions below

0
On BEST ANSWER

You could use Systemd to keep your process running. It will ensure that Vapid CMS process is running and restarts it after crash.

Check one these tutorials:

1
On

While Systemd or PM2 can be used to keep the node process running if it crashes, this will not prevent it from closing if you are running these commands from a terminal using ssh to access the server and then exit the terminal.

This is because the terminal will send the signal hang up command (SIGHUP) to the process when it's closed.

The easiest way to prevent this is using the nohup command. It's designed for the purpose. Instead of vapid start run:

nohup vapid start &

The nohup command will prevent the terminal from sending the SIGHUP when exiting. The & command will run the process in the background, allowing you to run additional terminal commands (such as exiting).