Can PM2 run command line start scripts?
Asked Answered
C

3

10

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.

Cotillion answered 21/11, 2019 at 2:21 Comment(0)
D
10

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

Danell answered 21/7, 2020 at 10:26 Comment(0)
A
6

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.

Albertype answered 21/11, 2019 at 2:47 Comment(0)
D
-1

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
Darreldarrell answered 4/10, 2022 at 11:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.