[22:42] <shaatar> hey all, I am trying to write an upstart service (/etc/init/*.conf file). I basically want to be able to say "start flashpolicy" and execute a command that works from the command line. What I have so far is this: http://www.privatepaste.com/45189f0858
[22:43] <shaatar> however, it does not work and I get a "start: Job failed to start."
[22:45] <JanC> shaatar: does this service need networking or something like that?
[22:46] <JanC> or a filesystem to be mounted, etc...
[22:46] <shaatar> JanC: yes, I suppose it does. It's accepts TCP connections over port 843 and returns a static xml file
[22:46] <ion> Or the root filesystem to be mounted in readwrite mode
[22:47] <JanC> then you are starting it way too early
[22:47] <shaatar> i see, I need to require some other services
[22:49] <JanC> shaatar: http://upstart.ubuntu.com/cookbook/ might be useful (it's a work-in-progress still, but some info you need is there already)
[22:49] <shaatar> I haven't actually tested this on boot yet, however. I am just trying to run $ start flashpolicy. Wouldn't networking have already loaded? Unless I am misunderstanding this.
[22:49] <shaatar> JanC: thanks, I was looking at that, I shall look into it some more.
[22:50] <shaatar> should my command be in a script stanza?
[22:50] <JanC> you are right that networking is probably up by that time, yes
[22:50] <shaatar> I will require it anyways, better safe than sorry.
[22:51] <JanC> maybe something is wrong with the command you run?
[22:51] <ion> Anything in the daemon’s logs? Anything in its output? (exec >/tmp/flashpolicy.out 2>&1 before running the service)
[22:55] <shaatar> ion: Like this? root@dev:/etc/init# >/tmp/flashpolicy.out 2>&1
[22:55] <shaatar> root@dev:/etc/init# start flashpolicy
[22:56] <ion> No, in the script section of the job.
[22:56] <ion> exec >/tmp/flashpolicy.out 2>&1
[22:56] <shaatar> JanC: I can run the command copy + pasted into the command line.
[22:56] <shaatar> AH I see, sorry about that
[22:58] <shaatar> hmm, interesting, it says "erlexec: HOME must be set"
[22:58] <shaatar> looks like more of an erlang configuration issue. what user does upstart execute commands as?
[22:58] <ion> root
[22:59] <shaatar> interesting, the command definitely runs as root from bash. looks like google has some info on this error though, thanks all!
[23:00] <ion> I use “exec su -c 'exec …' username” for an Erlang service.
[23:00] <ion> The PAM session sets HOME etc.
[23:01] <shaatar> where username is just some other user, say, a user I create called flashpolicy?
[23:01] <ion> for instance
[23:10] <shaatar> exec su -c 'exec rl -pa /opt/flashpolicy/ebin -noshell -noinput -detached -flashpolicy logfile_path '"/var/log/flashpolicy/"' -run flashpolicy_app start'
[23:10] <shaatar> does that look good? except for my *erl typo
[23:12] <shaatar> ah, that appears to have at least run the command, excellent!
[23:12] <shaatar> thank you muchly
[23:12] <ion> You have mismatched quotes.
[23:13] <ion> exec su -c 'exec "$0" "$@"' username -- erl -pa … should take care of it.
[23:13] <shaatar> I do?
[23:14] <ion> Might as well add -s. exec su -s /bin/sh -c 'exec "$0" "$@"' username -- erl -pa …
[23:14] <shaatar> gotcha
[23:15] <shaatar> what does "$0" "$@"' do?
[23:16] <ion> # su -s /bin/sh -c 'printf "|%s|" exec "$0" "$@"' ion -- foo bar 'baz quux'
[23:16] <ion> |exec||foo||bar||baz quux|
[23:17] <shaatar> Ah, I see
[23:17] <shaatar> one last q: 'username', replace that with an actual username? I don't think so based on what I understand of su
[23:18] <ion> Yes, whatever user you want to service to run as.
[23:18] <shaatar> ah, understood
[23:18] <shaatar> i need to learn more about su then :P