简体   繁体   English

强制 PM2 从应用程序内重新启动 - 如何从正在运行的应用程序与 PM2 交互?

[英]Force PM2 to restart from within the application - how to interact with PM2 from the running application?

I'm using PM2 to run a NodeJS app.我正在使用 PM2 运行 NodeJS 应用程序。 Sometimes it's desirable to restart the app.有时需要重新启动应用程序。 Is there a way to do this from within the app, to avoid having to log into the server each time?有没有办法应用程序中执行此操作,以避免每次都必须登录服务器?

Would the simplest solution be to set PM2 to restart on changes in the app directory, then have the app touch a file?最简单的解决方案是将 PM2 设置为在应用程序目录中的更改时重新启动,然后让应用程序触摸文件吗? Or is there a way to interact with PM2 from within the app?或者有没有办法从应用程序中与 PM2 进行交互?

PM2 starts a process that ended, this means that if the process exits due to exception or natural exit, it will restart it. PM2启动一个已经结束的进程,这意味着如果该进程由于异常或自然退出而退出,它将重新启动它。

So, just run this when ever need因此,只需在需要时运行它

process.exit(0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM