简体   繁体   中英

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? 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.

Yes you can run any process type with 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.sh

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

then you can run file "bash.sh" with pm2

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.

  • create script file for run.
$ sudo nano runpm2.sh
  • add your relevant command for run 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.
sudo ./runpm2.sh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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