The cookbook has the answer [1] :) TLDR: If you're running upstart 1.4 or later, you can use the 'setuid' and 'setgid' stanzas. Otherwise you'll have to use su, sudo or start-stop-daemon. Start-stop-daemon is recommended, because su and sudo do a bunch of extra stuff to the PAM session that is probably unnecessary for a daemon process.
Cheers, Evan [1] http://upstart.ubuntu.com/cookbook/#changing-user On Sat, Mar 17, 2012 at 8:28 AM, Tom <[email protected]> wrote: > Thanks Even. > > I will read through the cookbook and hopefully it will indeed answer > my questions. > > About the su command, I read that this was the only way to run a > process as an unprivileged user with upstart here: > > http://superuser.com/questions/213416/running-upstart-jobs-as-unprivileged-users > > "A future release of Upstart will have native support for that, but > for now, you can use something like: > > exec su -s /bin/sh -c 'exec "$0" "$@"' username -- /path/to/command > [parameters...]" > > Is there a better way of doing this nowadays? > > Tom > > 2012/3/17 Evan Huus <[email protected]>: > > 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. > > > > Cheers, > > Evan > > > > [1] http://upstart.ubuntu.com/cookbook/ > > [2] http://upstart.ubuntu.com/cookbook/#expect > > [3] http://upstart.ubuntu.com/cookbook/#changing-user > > [4] http://upstart.ubuntu.com/cookbook/#script > > > > On Sat, Mar 17, 2012 at 7:32 AM, Tom <[email protected]> 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 > >> [email protected] > >> Modify settings or unsubscribe at: > >> https://lists.ubuntu.com/mailman/listinfo/upstart-devel > > > > > > -- > upstart-devel mailing list > [email protected] > Modify settings or unsubscribe at: > https://lists.ubuntu.com/mailman/listinfo/upstart-devel >
-- upstart-devel mailing list [email protected] Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/upstart-devel
