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.
Can I just tell PM2 to run the mongo script? Or does it have to be an application?
How can I make sure it doesn’t try to run the web server first? If it’s run before mongo, it crashes?
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)?
This textbox defaults to using Markdown to format your 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.
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.
Click below to sign up and get $200 of credit to try our products over 60 days!