2

I'm working on deploying a node project to a Linux box on amazon EC2. The project uses mongoDB. I'm trying to run node and mongoDB simultaneously on the box but I'm unfamiliar with linux.

Is it possible to run mongo in the background and multi-task with node? I only have access to the command line, there's no GUI.

1 Answer 1

1

You haven't mentioned what flavor of Linux you are using, but these will cover the major types:

Each of these install guides will walk you through installing MongoDB as a package, and each package will install MongoDB as a service on your host. Services are generally designed to start at boot, run in the background, restart when upgrades are done, and be started/stopped easily and cleanly etc.

The MongoDB packages are no exception, and this would be my recommended way of installing and running MongoDB in EC2 unless you want to go for one of the pre-configured AMI's from the marketplace of course.

For reference, it is absolutely possible to run MongoDB in the background manually. You will need to specify the --fork, --logpath options (or the config file equivalents) at a minimum to have it run in the background (I would recommend and --logappend as well). When you are done you can either kill the process or use the shutdown command from the mongo shell. Some general guidance on these options (and more) can be found here.

2
  • 1
    There's a much simpler option that your answer neglects that is distro non-specific, which is the "screen" application, which will allow him to run tasks in the background even without daemonizing them, allowing him screen-access to them again if need be. Apr 2, 2014 at 1:32
  • 1
    that is not technically running in the background though detaching the screen will have a similar effect. Additionally, screen is not necessarily installed by default, and it would require that the user learn another tool and screen is far from simple to someone that has never seen it before. Finally it would make looking at logging very difficult to track, since screen does not retain console history (which is where mongod will output to by default without the logpath/fork options above)
    – Adam C
    Apr 2, 2014 at 1:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .