7

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.

Simon Woodside
  • 466
  • 1
  • 7
  • 15

3 Answers3

2
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?

  • 2
    and you can add ``-n`` to sudo so it exits with an error instead of waiting for password. – Evgeny Oct 11 '12 at 14:58
1

I think there are three possible issues:

  • Your expect fork is wrong because your program doesn't actually fork. This is probably not the case since you are using a script but you might want to try expect daemon or not expect at all.

  • Your java program doesn't actually go into daemon mode and thus requires to be put in the background. In other words you need a & at the end: sudo -u www-data /path/to/grafserv-start.sh >> /tmp/upstart.log 2>&1&

  • Your Upstart is in a bad state. I don't know exactly how it happens but you can get upstart in a state where even if you edit the script to be correct it will still hang. If this happens rename the file (ie /etc/init/[myservice]-1.conf and try starting it till stops hanging. Once you get the script right rename the file to the correct name and restart the system.

Adam Gent
  • 260
  • 1
  • 7
-1

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.

beatgammit
  • 339
  • 1
  • 10