2

I'm experimenting with running Sonar on my Linux desktop box. I wanted to make it start up automatically on startup of the box, but it's ok for it to run as me.

I created "~/.init/sonar.conf" with the following simple contents:

description "Sonar server"
start on startup
respawn
chdir ~/apps/sonar-3.2/bin
exec ~/apps/sonar-3.2/bin/linux-x86-64/sonar.sh start

I read that Upstart isn't configured for user jobs by default, so I edited "/etc/dbus-1/system.d/Upstart.conf", commenting out the existing "" element and replacing it with the following:

<policy context="default">
  <allow send_destination="com.ubuntu.Upstart" send_interface="org.freedesktop.DBus.Introspectable"/>
  <allow send_destination="com.ubuntu.Upstart" send_interface="org.freedesktop.DBus.Properties"/>
  <allow send_destination="com.ubuntu.Upstart" send_interface="com.ubuntu.Upstart0_6"/>
  <allow send_destination="com.ubuntu.Upstart" send_interface="com.ubuntu.Upstart0_6.Job"/>
  <allow send_destination="com.ubuntu.Upstart" send_interface="com.ubuntu.Upstart0_6.Instance"/>
</policy>

When I do "start sonar" I get "start: Job failed to start". I also did "initctl list | grep sonar" and got "sonar stop/waiting".

How can I troubleshoot this further?

2

Likely your issue is that what you think of as startup is not what upstart uses it for. Startup is one of the first events emitted during the system init script boot. So you may well be missing things like network stack and drivers, filesystems, almost everything really. Re-read the manpage carefully about the meaning of the startup event, and also what started means too.

Here's the process I use to check and test upstart services.

Firstly check your config:

# silent if the config is valid    
initctl check-config sonar
# reload the configuration to pick up latest changes
initctl reload-configuration

I also add a script -- that does run on startup -- to switch upstart into debug logging mode:

sudo -s
cat <<EOCONF > /etc/init/upstart-debug.conf 
description "enable debugging of upstart from within"
author      "@dch__"
version     "0.1"

start on startup

task
exec initctl log-priority debug

As it's a task it runs just once. The result now is that you get a lot more detail in /var/log/dmesg - just | grep init: for the history.

For your specific upstart job I'd change the following:

  • for normal user daemons I run start on started networking and filesystem which works successfully on Quantal and Precise, but probably not earlier versions.
  • use an absolute path rather than a relative one.
  • check to see if your sonar.sh script forks or daemonises, if so you will likely need to add expect fork or expect daemon as a stanza.
  • finally, sprinkle either emit ... stanzas, or shell echo here statements in your pre-exec and exec scripts and check for this output in the corresponding /var/log/upstart/sonar.log.
0

For Upstart User Job following Upstart.conf configuration change: https://gist.github.com/bradleyayers/1660182 worked for me.

  • tested on Ubuntu 12.04
  • my (user) jobs are in ~/.init
  • no restart after saving Upstart.conf is needed

Regarding your sonar.conf - start on startup is probably too early. start on desktop-session-start seems more appropriate for user jobs.

Edit: user jobs are not respected by Ubuntu at startup as described in this Bug report - you can use following workaround.

  • doesn't work. jobs are not started – haelix Nov 20 '13 at 13:54
  • confirmed not working. not a good answer. not downvoting so far, just wanted to let you ammend it or delete it, since I'm not a hater. – meshfields Apr 7 '15 at 21:42
  • @AchmedDurangi Are you still using Ubuntu 12.04? After 3 years it is probably time to upgrade ;-) Using 14.04? Starting long running processes changes often in Ubuntu, so my solution will likely not work for newer or older Ubuntu versions. – geekQ Apr 8 '15 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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