I have an upstart script that will start a custom jetty server. When I do sudo start [myservice] nothing happens. Subsequently, sudo status [myservice] show it as: [myservice] start/killed, process 3586.

Here's the script in /etc/init/[myservice].conf:

description "[description]"
author "[my name and email]"
start on runlevel [2345]
stop on runlevel [016]
respawn
expect fork
script
    sudo -u www-data /path/to/grafserv-start.sh >> /tmp/upstart.log 2>&1
end-script

And here is grafserv-start.sh:

#!/bin/bash
/usr/bin/java -Djetty.port=3070 -jar /path/to/grafserv/trunk/start.jar
echo "Done starting GrafServ"

I've tried redirecting the output of the script command to a tmp logfile, but that file is never created. When I start it, I just get a hang, until I ^C. Also, I tried running it with strace but that gave me a lot of stuff about sockets.

link|improve this question
Just a sanity check: is there actually code in start.jar that forks to background? Otherwise, the the JVM would just block, no? – Bittrance Mar 25 '11 at 21:03
1  
Possibly related: bugs.debian.org/cgi-bin/bugreport.cgi?bug=582745 – Brendan Long Jul 20 '11 at 22:47
feedback

2 Answers

sudo -u www-data

...will hang if it prompts for password. Have you've checked that the user the "startup script" runs as has sudoers permissions to do that?

link|improve this answer
feedback

I think you missed the exec in front of your script in upstart... I think it's necessary. Try this:

exec sudo -u www-data /path/to/grafserv-start.sh >> /tmp/upstart.log 2>&1

Like Bittrance said, you might also want to make sure that your java program runs in the background. Try appending a & or something to the end of the command in your script if you don't have any logic in your java program that runs it as a background process or a daemon.

link|improve this answer
Choices are "exec" or "script / end script". The example uses the latter. – danorton Jun 6 '11 at 23:23
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.