简体   繁体   English

pm2可以运行命令行启动脚本吗?

[英]Can PM2 run command line start scripts?

I'm using a library, say I want the script that starts my app to be cli-lib start how can i go about that?我正在使用一个库,假设我希望启动我的应用程序的脚本是cli-lib start我怎么能 go 呢? I don't want to just run node app.js or any js file for that matter, the cli lib does that for me but i cant figure out a way to get this to work.我不想为此只运行node app.js或任何 js 文件,cli lib 为我做这些,但我想不出一种方法来让它工作。

Yes you can run any process type with pm2.是的,您可以使用 pm2 运行任何进程类型。 For scripts in other languages which has assigned an interpreter by default,对于默认分配解释器的其他语言的脚本,

pm2 start echo.coffee
pm2 start echo.php
pm2 start echo.py
pm2 start echo.sh
pm2 start echo.rb

or with interpreter或带口译员

pm2 start echo.pl --interpreter=perl

read more from docs从文档中阅读更多内容

I think you can create a bash script then run it with pm2, for examples:我认为您可以创建一个 bash 脚本,然后使用 pm2 运行它,例如:

bash.sh bash.sh

#!/usr/bin/bash
node /home/user/test.js

then you can run file "bash.sh" with pm2然后你可以用pm2运行文件“bash.sh”

pm2 start bash.sh

I did not test it yet but you can try.我还没有测试它,但你可以试试。

Yes we can use & operate pm2 related command with script in Linux.是的,我们可以在 Linux 中通过脚本使用和操作 pm2 相关命令。

  • create script file for run.创建用于运行的脚本文件。
$ sudo nano runpm2.sh
  • add your relevant command for run pm2.添加运行 pm2 的相关命令。 Also you can visit for more command on this site您也可以访问此站点以获取更多命令
#!/usr/bin/bash
pm2 restart "a"
pm2 restart "b"
pm2 restart "c"

pm2 start "app.js"

pm2 restart "app_name"
pm2 reload "app_name"
pm2 stop "app_name"
pm2 delete "app_name" 
  • Assign access for run script.为运行脚本分配访问权限。
sudo chmod +x runpm2.sh
  • run.sh file with this command.使用此命令运行 run.sh 文件。
sudo ./runpm2.sh

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

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