Can the pm2 node module restarts the app after crash automatically

后端 未结 4 1715
我寻月下人不归
我寻月下人不归 2021-02-06 23:06

I have a node app ready which is workable, but has known and unknown bugs which crashes the node app. In such cases it would be nice if pm2 can restart the node app. Is this fea

相关标签:
4条回答
  • 2021-02-06 23:14

    This may help:

    # Generate Startup Script
    $ pm2 startup
    
    # Freeze your process list across server restart
    $ pm2 save
    
    # Remove Startup Script
    $ pm2 unstartup
    

    More details here

    0 讨论(0)
  • 2021-02-06 23:20

    To make app restart when it crash you have to use one of PM2 Restart strategies.

    There is something called Exponential Backoff Restart Delay which PM2 explains as:

    Instead of restarting your application like crazy when exceptions happens (e.g. database is down), the exponential backoff restart will increase incrementaly the time between restarts.

    You can set it with CLI by

    pm2 start app.js --exp-backoff-restart-delay=100
    

    There are other restart methods also, which are mentioned here.

    0 讨论(0)
  • 2021-02-06 23:31

    Also, check new excellent option

    --exp-backoff-restart-delay=100 (msec, not sec!)
    

    pm2 will restart crashed app after 100 msec, then step-by-step increase restart-delay to 15 secunds

    0 讨论(0)
  • 2021-02-06 23:39

    Yes, it does this by default and there is even a watch option to restart on changes.

    0 讨论(0)
提交回复
热议问题