skeddtemp
By:
skeddtemp

Can PM2 run scripts? Can you specify what order

February 24, 2017 1.4k views
Node.js MongoDB Configuration Management Linux Commands Ubuntu 16.04

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 mongo-start.sh 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.

Questions:

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

1 Answer
  1. Launch scripts with --interpreter=bash
  2. doesnt matter
  3. use -- to start entering options for the launched app
Have another answer? Share your knowledge.