Windows: Auto start PM2 and node apps

前端 未结 3 1136
礼貌的吻别
礼貌的吻别 2021-01-30 18:40

At a Windows AWS server i have a NODE app and i\'m using PM2 to launch the app

I have tried the NPMs: \"pm2-windows-startup\" and \"pm2-windows-service\"

But aft

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-30 19:05

    pm2-windows-startup works great if you're okay with the fact that it is launched on login. If you have a reboot on a server though (say Windows Update) you are out of luck.

    pm2-windows-service did work for me, using @innomizetech fork, but I've had some issues, probably due to the user or its setup, or something else. Basically the service would start an old version of the saved process list, even though I tried pm2 delete all, pm2 start ecosystem.config.js, pm2 save.

    I resorted to a very simple home-made solution:

    1. Create a file pm2-resurrect.sh in C:\, which contains the single line pm2 resurrect.
    2. In Task Scheduler, add a new task that is run on boot, and select that it is run whether the user is logged in or not. You need to type the user password at this point which is saved for successive runs.
    3. Set the task command to execute the file C:\pm2-resurrect.sh.

    In my case I have Git for Windows which comes with bash, which opens the file and executes it. I didn't test it but I guess you could have a .cmd file with the same content.

提交回复
热议问题