Mongodb upstart script

Evan Huus eapache at
Sat Mar 17 12:22:18 UTC 2012

Hi Tom,

As per the upstart cookbook [1], you'll likely need a few extra stanzas.

According to the 'expect' section [2] you'll probably need to add 'expect
daemon' to allow upstart to track the proper process ID when mongodb forks
in order to daemonize.

Also, I'm not sure what you're trying to do with the "su -s /bin/sh -c
exec". If you're trying to change users [3] you probably shouldn't be using
su. If you need the program to be run in a shell environment for some
reason, you can simply use 'script' [4] instead of exec. If you're simply
using it to fork so that it daemonizes properly instead of only forking
once, you can change 'expect daemon' to 'expect fork' and upstart will
track the process ID correctly.

There are a lot of good resources in the cookbook [1], so hopefully it will
answer any other questions you might have.



On Sat, Mar 17, 2012 at 7:32 AM, Tom <tommedema at> wrote:

> Hi folks,
> I'm trying to run mongod as a deamon using upstart under the
> unprivileged mongouser account.
> The following appears to work great:
> # Mongodb Ubuntu upstart file at /etc/init/mongodb.conf
> description "MongoDB deamon"
> pre-start script
>    mkdir -p /home/mongouser/data/db
>    mkdir -p /home/mongouser/data/logs
> end script
> start on runlevel [2345]
> stop on runlevel [06]
> exec su -s /bin/sh -c 'exec "$0" "$@"' mongouser --
> /home/mongouser/Applications/mongodb/bin/mongod --fork --journal
> --nohttpinterface --dbpath /home/mongouser/data/db --logpath
> /home/mongouser/data/logs/mongodb.log --logappend --port 30000
> ------------
> When I reboot the system mongod indeed starts properly. However, here
> are the issues:
> 1. when I do sudo status mongodb I get "stop/waiting" even though it is
> running
> 2. when I do sudo start mongodb it starts the deamon again, even
> though mongod is already running.
> Can anyone tell me what is going wrong here?
> --
> upstart-devel mailing list
> upstart-devel at
> Modify settings or unsubscribe at:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the upstart-devel mailing list