pm2方式管理进程
作者:互联网
4.pm2方式管理进程
要保证后台保持进程,需要安装pm2。
全局安装:npm install -g pm2
启动:pm2 start /usr/local/my-yapi/vendors/server/app.js --watch -i 1
这样以后就可以很方便的用pm2就行启动关闭啦~
5. 通过pm2 save
保存当前进程状态。
查看:pm2 list
重启:pm2 restart service/app.js
停止:可以先通过pm2 list
获取应用的名字(--name指定的)或者进程id。
# pm2 stop app_name|app_id
# pm2 stop /usr/local/my-yapi/vendors/server/app.js
pm2使用参考文档:
http://imweb.io/topic/57c8cbb27f226f687b365636
本地测试
[root@VM-16-14-centos my-yapi]# npm install pm2 -g
npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
/usr/local/node/bin/pm2 -> /usr/local/node/lib/node_modules/pm2/bin/pm2
/usr/local/node/bin/pm2-dev -> /usr/local/node/lib/node_modules/pm2/bin/pm2-dev
/usr/local/node/bin/pm2-docker -> /usr/local/node/lib/node_modules/pm2/bin/pm2-docker
/usr/local/node/bin/pm2-runtime -> /usr/local/node/lib/node_modules/pm2/bin/pm2-runtime
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules/pm2/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN ws@7.4.6 requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN ws@7.4.6 requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself.+ pm2@5.2.0
updated 1 package in 12.44s
[root@VM-16-14-centos my-yapi]# pm2 -v
-bash: pm2: command not found
[root@VM-16-14-centos my-yapi]# pm2 start /usr/local/my-yapi/vendors/server/app.js --watch -i 1
-bash: pm2: command not found
标签:node,bin,pm2,方式,modules,usr,进程,local 来源: https://www.cnblogs.com/myibm/p/16621178.html