How to automatically resume a nodeJs server in production after restarting the cloud server

3

I've been looking for the best way to make a cloud server with Ubuntu to restart, or if it has a fall for any reason and then get up again, automatically restart the nodeJs server that I have running in it.

To keep node running I do it with Forever, and to do what I'm looking for, I found two ways:

  • Crontab:
  • Using Crontab as follows:

    $ crontab -u myuser -e
    

    and in the editor that opens by adding the following line

    @reboot /usr/local/bin/forever start /your/path/to/your/app.js
    
  • Adding file to $ cd /etc/init.d
  • Add file and change permissions as follows:

    $ cd /etc/init.d
    $ sudo nano nodeapps
    

    in the editor where nodeapp is created we put the following line:

    sudo forever start /ruta/al/script/principal/de/la/app.js
    

    We give execution permissions:

    $ sudo chmod +x nodeapps
    

    and the script is added to the boot:

    $ sudo update-rc.d nodeapps defaults
    

    Well, my question is which of these ways would be more stable, or if they have some other better way to do it?

        
    asked by amblador 22.12.2018 в 16:02
    source

    0 answers