Upstart in Amazon linux AMI

Daniel Lam daniel.cklam at gmail.com
Thu Jul 31 02:31:20 UTC 2014


Hi James,

Thank you!! Sorry replying late. Your explanation really helped.

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:

-
https://www.exratione.com/2013/02/nodejs-and-forever-as-a-service-simple-upstart-and-init-scripts-for-ubuntu/
- http://stackoverflow.com/questions/13982257/upstart-script-for-node-js-app

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.

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?

I did notice someone suggested in SO that I could use the following

exec su -s /bin/sh -c 'exec "$0" "$@"' username -- /path/to/command
[parameters]

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.

Cheers,
Daniel



On 28 July 2014 18:31, James Hunt <james.hunt at ubuntu.com> wrote:

> Hi Daniel,
>
> 2014-07-28 3:01 GMT+01:00 Daniel Lam <daniel.cklam at gmail.com>:
>
> Hi there,
>>
>> 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".
>>
>> 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).
>>
>>
>>     #!upstart
>>
> 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 :-)
>
>
>>     description "node app"
>>
>>
>>
>>     #start on started mountall
>>
>>     start on startup
>>
> This is the most likely cause of the issue you are seeing. Read
> http://upstart.ubuntu.com/cookbook/#normal-start (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.
>
>
>>     stop on shutdown
>>
> (Unless you have arranged to have this event emitted) this is incorrect -
> see http://upstart.ubuntu.com/cookbook/#normal-shutdown.
>
>
>
>>
>>
>>     # Automatically Respawn:
>>
>>     respawn
>>
>>     respawn limit 99 5
>>
> See the extremely important note that starts this section -
> http://upstart.ubuntu.com/cookbook/#respawn
>
>
>>
>>     env NODE_ENV=development
>>
>>
>>
>>     script
>>
>>         cd /home/ec2-user/test
>>
> Best to use the chdir stanza:  http://upstart.ubuntu.com/cookbook/#chdir.
> Note that this service will be running as root. Maybe you want to run as
> ec2-user instead? See:
>
> http://upstart.ubuntu.com/cookbook/#setuid
> http://upstart.ubuntu.com/cookbook/#setgid
>
>
>         exec node app.js 2>&1 >> /var/log/test.log
>>
> 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.
>
>     end script
>>
>>
>> Any help will be much appreciated thank you!
>>
>> Daniel
>>
>>
>> --
>> upstart-devel mailing list
>> upstart-devel at lists.ubuntu.com
>> Modify settings or unsubscribe at:
>> https://lists.ubuntu.com/mailman/listinfo/upstart-devel
>>
>>
>
> Kind regards,
>
> James.
> --
> James Hunt
> ____________________________________
> #upstart on freenode
> http://upstart.ubuntu.com/cookbook
> https://lists.ubuntu.com/mailman/listinfo/upstart-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/upstart-devel/attachments/20140731/fa75de4c/attachment.html>


More information about the upstart-devel mailing list