Can PM2 run scripts? Can you specify what order

I want to use PM2 so that my server is restarted if it crashes.

My server uses mongo and node. When I want to start the server on c9 after it’s been stopped, I first run a script which does the following:

rm ./data/mongod.lock mongod --nojournal --dbpath=data --repair mongod --nojournal --dbpath=data

I had to clear the lock at the beginning because it seemed to get locked every time it shut down, which is very frequently with c9.

Then once that is running I run my server with bin/www and the node runner.


  1. Can I just tell PM2 to run the mongo script? Or does it have to be an application?

  2. How can I make sure it doesn’t try to run the web server first? If it’s run before mongo, it crashes?

  3. If you can’t run scripts, is there a way to use options on the command you want to run, such as --dbpath=data on mongo? It seems to interpret it as a pm2 option (which doesnt exist)?


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

  1. Launch scripts with --interpreter=bash
  2. doesnt matter
  3. use – to start entering options for the launched app