<div dir="ltr"><div>Hi James,</div><div><br></div><div>Thank you!! Sorry replying late. Your explanation really helped.</div><div><br></div><div>As you might have noticed I haven’t really read up on upstart docs at all, just tried to copy from samples out there to get my thing to work:</div>
<div><br></div><div>- <a href="https://www.exratione.com/2013/02/nodejs-and-forever-as-a-service-simple-upstart-and-init-scripts-for-ubuntu/">https://www.exratione.com/2013/02/nodejs-and-forever-as-a-service-simple-upstart-and-init-scripts-for-ubuntu/</a></div>
<div>- <a href="http://stackoverflow.com/questions/13982257/upstart-script-for-node-js-app">http://stackoverflow.com/questions/13982257/upstart-script-for-node-js-app</a></div><div><br></div><div>I tried to read the doc on respawn and expect, it’s a lot to digest and I just don’t have the time to fully understand them. At the moment, I have “respawn” and “respawn limit x y” and it seems to work for me. I guess I’ll leave it like that. </div>
<div><br></div><div>Unfortunately Amazon Linux AMI has upstart version 0.6.5, which is way older than 1.4 where setuid/setgid is available. I suppose it’s up to the Amazon team to make more recent versions available later on? Or is there way around it (but is it a good option to e.g. to build upstart myself?) Or can you guys request the Amazon guys to use a more recent version?</div>
<div><br></div><div>I did notice someone suggested in SO that I could use the following </div><div><br></div><div><span style="color:rgb(0,0,0);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;font-size:14px;line-height:18px;white-space:pre-wrap;background-color:rgb(238,238,238)">exec su -s /bin/sh -c 'exec "$0" "$@"' username -- /path/to/command [parameters]</span><br>
</div><div><br></div><div>The above worked, but it's 2 processes, one as root with "su -s ..." and one as ec2-user, which just seems a bit ugly and I'm not sure if there're undesirable side-effects.</div>
<div><br></div><div><div>Cheers,<br></div></div><div>Daniel</div><div><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 28 July 2014 18:31, James Hunt <span dir="ltr"><<a href="mailto:james.hunt@ubuntu.com" target="_blank">james.hunt@ubuntu.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Hi Daniel,<div class="gmail_extra"><br><div class="gmail_quote">
2014-07-28 3:01 GMT+01:00 Daniel Lam <span dir="ltr"><<a href="mailto:daniel.cklam@gmail.com" target="_blank">daniel.cklam@gmail.com</a>></span>:<div class=""><br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Hi there, <div><br></div><div>Need some help in using upstart in an Amazon-Linux-AMI instance here. My apology if this is not the right place to ask.. but IRC channel says "post to mailing list if no response here".</div>
<div><br></div><div>I've got my .conf below placed in /etc/init. Command to start/stop/restart would work, e.g. "sudo start my-app-name". However I can't get my process to start automatically on reboot (see how I tried 2 different params already).</div>
<div><br></div><div><br></div><div><p style="margin:0px;font-size:11px;font-family:Monaco"> #!upstart<span style="font-family:arial;font-size:small"> </span></p></div></div></blockquote></div><div>I'm guessing this is just a reminder to yourself that this is an upstart job since there is no hash-bang magic for upstart :-)</div>
<div class="">
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>
<p style="margin:0px;font-size:11px;font-family:Monaco"> description "node app"</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;min-height:15px"> </p>
<p style="margin:0px;font-size:11px;font-family:Monaco"> #start on started mountall</p>
<p style="margin:0px;font-size:11px;font-family:Monaco"> start on startup</p></div></div></blockquote></div><div>This is the most likely cause of the issue you are seeing. Read <a href="http://upstart.ubuntu.com/cookbook/#normal-start" target="_blank">http://upstart.ubuntu.com/cookbook/#normal-start</a> (use the runlevel version). As documented in upstart-events(7) and startup(7), the startup event is emitted very early in boot - before disks are writeable, etc. Use 'start on runlevel [2345]. If you have particular requirements for starting as early as possible, I suggest you read upstart-events(7) carefully since this documents all "well-known" events along with the order in which they are emitted.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>
<p style="margin:0px;font-size:11px;font-family:Monaco"> stop on shutdown</p></div></div></blockquote><div>(Unless you have arranged to have this event emitted) this is incorrect - see <a href="http://upstart.ubuntu.com/cookbook/#normal-shutdown" target="_blank">http://upstart.ubuntu.com/cookbook/#normal-shutdown</a>.</div>
<div class="">
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>
<p style="margin:0px;font-size:11px;font-family:Monaco;min-height:15px"> </p>
<p style="margin:0px;font-size:11px;font-family:Monaco"> # Automatically Respawn:</p>
<p style="margin:0px;font-size:11px;font-family:Monaco"> respawn</p>
<p style="margin:0px;font-size:11px;font-family:Monaco"> respawn limit 99 5</p></div></div></blockquote></div><div>See the extremely important note that starts this section - <a href="http://upstart.ubuntu.com/cookbook/#respawn" target="_blank">http://upstart.ubuntu.com/cookbook/#respawn</a> </div>
<div class="">
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>
<p style="margin:0px;font-size:11px;font-family:Monaco;min-height:15px"> </p>
<p style="margin:0px;font-size:11px;font-family:Monaco"> env NODE_ENV=development</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;min-height:15px"> </p>
<p style="margin:0px;font-size:11px;font-family:Monaco"> script</p>
<p style="margin:0px;font-size:11px;font-family:Monaco"> cd /home/ec2-user/test</p></div></div></blockquote></div><div>Best to use the chdir stanza: <a href="http://upstart.ubuntu.com/cookbook/#chdir" target="_blank">http://upstart.ubuntu.com/cookbook/#chdir</a>. Note that this service will be running as root. Maybe you want to run as ec2-user instead? See:</div>
<div><br></div><div><a href="http://upstart.ubuntu.com/cookbook/#setuid" target="_blank">http://upstart.ubuntu.com/cookbook/#setuid</a><br></div><div><a href="http://upstart.ubuntu.com/cookbook/#setgid" target="_blank">http://upstart.ubuntu.com/cookbook/#setgid</a><br>
</div><div class=""><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">
<div>
<p style="margin:0px;font-size:11px;font-family:Monaco"> exec node app.js 2>&1 >> /var/log/test.log</p></div></div></blockquote></div><div>Redirection most likely not necessary since as of Upstart 1.4, all job output is logged automatically to /var/log/upstart/$job.log. To determine which version of Upstart you are using, run "initctl version". This coupled to the fact you were starting the job 'on startup' likely meant that app.js was failing to start (due to disks not being writeable), but it also wasn't able to log any errors for the same reason.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><div dir="ltr"><div>
<p style="margin:0px;font-size:11px;font-family:Monaco"> end script</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;min-height:15px"> </p></div><div>Any help will be much appreciated thank you!</div><span><font color="#888888"><div><br></div><div>Daniel</div><div> </div>
</font></span></div>
<br></div>--<br>
upstart-devel mailing list<br>
<a href="mailto:upstart-devel@lists.ubuntu.com" target="_blank">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>
<br></blockquote></div><br><div> <br></div><div dir="ltr">Kind regards,<br><br>James.<br>--<br>James Hunt<br>____________________________________<br>#upstart on freenode<br><a href="http://upstart.ubuntu.com/cookbook" target="_blank">http://upstart.ubuntu.com/cookbook</a><br>
<a href="https://lists.ubuntu.com/mailman/listinfo/upstart-devel" target="_blank">https://lists.ubuntu.com/mailman/listinfo/upstart-devel</a><br></div>
</div></div>
</blockquote></div><br></div></div>