The cookbook has the answer [1] :)<br><br>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.<br>

<br>Cheers,<br>Evan<br><br>[1] <a href="http://upstart.ubuntu.com/cookbook/#changing-user">http://upstart.ubuntu.com/cookbook/#changing-user</a><br><br><div class="gmail_quote">On Sat, Mar 17, 2012 at 8:28 AM, Tom <span dir="ltr"><<a href="mailto:tommedema@gmail.com">tommedema@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks Even.<br>
<br>
I will read through the cookbook and hopefully it will indeed answer<br>
my questions.<br>
<br>
About the su command, I read that this was the only way to run a<br>
process as an unprivileged user with upstart here:<br>
<a href="http://superuser.com/questions/213416/running-upstart-jobs-as-unprivileged-users" target="_blank">http://superuser.com/questions/213416/running-upstart-jobs-as-unprivileged-users</a><br>
<br>
"A future release of Upstart will have native support for that, but<br>
for now, you can use something like:<br>
<br>
exec su -s /bin/sh -c 'exec "$0" "$@"' username -- /path/to/command<br>
[parameters...]"<br>
<br>
Is there a better way of doing this nowadays?<br>
<br>
Tom<br>
<br>
2012/3/17 Evan Huus <<a href="mailto:eapache@gmail.com">eapache@gmail.com</a>>:<br>
<div class="HOEnZb"><div class="h5">> Hi Tom,<br>
><br>
> As per the upstart cookbook [1], you'll likely need a few extra stanzas.<br>
><br>
> According to the 'expect' section [2] you'll probably need to add 'expect<br>
> daemon' to allow upstart to track the proper process ID when mongodb forks<br>
> in order to daemonize.<br>
><br>
> Also, I'm not sure what you're trying to do with the "su -s /bin/sh -c<br>
> exec". If you're trying to change users [3] you probably shouldn't be using<br>
> su. If you need the program to be run in a shell environment for some<br>
> reason, you can simply use 'script' [4] instead of exec. If you're simply<br>
> using it to fork so that it daemonizes properly instead of only forking<br>
> once, you can change 'expect daemon' to 'expect fork' and upstart will track<br>
> the process ID correctly.<br>
><br>
> There are a lot of good resources in the cookbook [1], so hopefully it will<br>
> answer any other questions you might have.<br>
><br>
> Cheers,<br>
> Evan<br>
><br>
> [1] <a href="http://upstart.ubuntu.com/cookbook/" target="_blank">http://upstart.ubuntu.com/cookbook/</a><br>
> [2] <a href="http://upstart.ubuntu.com/cookbook/#expect" target="_blank">http://upstart.ubuntu.com/cookbook/#expect</a><br>
> [3] <a href="http://upstart.ubuntu.com/cookbook/#changing-user" target="_blank">http://upstart.ubuntu.com/cookbook/#changing-user</a><br>
> [4] <a href="http://upstart.ubuntu.com/cookbook/#script" target="_blank">http://upstart.ubuntu.com/cookbook/#script</a><br>
><br>
> On Sat, Mar 17, 2012 at 7:32 AM, Tom <<a href="mailto:tommedema@gmail.com">tommedema@gmail.com</a>> wrote:<br>
>><br>
>> Hi folks,<br>
>><br>
>> I'm trying to run mongod as a deamon using upstart under the<br>
>> unprivileged mongouser account.<br>
>><br>
>> The following appears to work great:<br>
>><br>
>> # Mongodb Ubuntu upstart file at /etc/init/mongodb.conf<br>
>><br>
>> description "MongoDB deamon"<br>
>><br>
>> pre-start script<br>
>>    mkdir -p /home/mongouser/data/db<br>
>>    mkdir -p /home/mongouser/data/logs<br>
>> end script<br>
>><br>
>> start on runlevel [2345]<br>
>> stop on runlevel [06]<br>
>><br>
>> exec su -s /bin/sh -c 'exec "$0" "$@"' mongouser --<br>
>> /home/mongouser/Applications/mongodb/bin/mongod --fork --journal<br>
>> --nohttpinterface --dbpath /home/mongouser/data/db --logpath<br>
>> /home/mongouser/data/logs/mongodb.log --logappend --port 30000<br>
>><br>
>> ------------<br>
>><br>
>> When I reboot the system mongod indeed starts properly. However, here<br>
>> are the issues:<br>
>> 1. when I do sudo status mongodb I get "stop/waiting" even though it is<br>
>> running<br>
>> 2. when I do sudo start mongodb it starts the deamon again, even<br>
>> though mongod is already running.<br>
>><br>
>> Can anyone tell me what is going wrong here?<br>
>><br>
>> --<br>
>> upstart-devel mailing list<br>
>> <a href="mailto:upstart-devel@lists.ubuntu.com">upstart-devel@lists.ubuntu.com</a><br>
>> Modify settings or unsubscribe at:<br>
>> <a href="https://lists.ubuntu.com/mailman/listinfo/upstart-devel" target="_blank">https://lists.ubuntu.com/mailman/listinfo/upstart-devel</a><br>
><br>
><br>
<br>
--<br>
upstart-devel mailing list<br>
<a href="mailto:upstart-devel@lists.ubuntu.com">upstart-devel@lists.ubuntu.com</a><br>
Modify settings or unsubscribe at: <a href="https://lists.ubuntu.com/mailman/listinfo/upstart-devel" target="_blank">https://lists.ubuntu.com/mailman/listinfo/upstart-devel</a><br>
</div></div></blockquote></div><br>