1

I have tried so many ways to keeping node server alive on Linux environment but nothing has worked. Sometime the server runs only 4-5 hours and sometime it runs 10-12 hours and after that server goes shut down automatically. I have tried forever start, pm2, nodemon but nothing has worked. I have also tried shell script with forever start for running it but that also not worked.

Aafreen Ali
  • 21
  • 1
  • 2

3 Answers3

1

Applications that are running under PM2 will be restarted automatically if the application crashes or is killed, but an additional step needs to be taken to get the application to launch on system startup (boot or reboot). Luckily, PM2 provides an easy way to do this, the startup subcommand.

The startup subcommand generates and configures a startup script to launch PM2 and its managed processes on server boots:

$ pm2 startup systemd

Run the command that was generated (similar to the highlighted output above, but with your username instead of sammy) to set PM2 up to start on boot (use the command from your own output):

sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u sammy --hp /home/sammy

check here for details https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04

You can increase the size of memory restar- check this: pm2 process crashed on server. it gives an error

Alex
  • 409
  • 6
  • 15
0

Try using process manager for making the application run all the time. Here is the link for Pm2 . It will restart you application once it crashes also automatically

ashok poudel
  • 703
  • 11
  • 28
-1

Use a NPM package called nodemon

npm install -g nodemon
nodemon index.js

If the application fails or crashes for any reason it will restart

Read more at https://www.npmjs.com/package/nodemon

Rand
  • 87
  • 2
  • 9