I am trying to use upstart to start a daemon on the "input-device-added" event, however if someone knows of a different method to start something on the same event that doesn't involve Upstart I would be very pleased too. Anyway, when the input-device-added event is emitted myservice.conf gets called correctly and the first few lines of script get parsed. But when the daemon gets launched it never completely starts running and Upstart seemingly kills it prematurely.

I've tried using Upstart in two different ways, both give me the same problem:

author "AnVoWiDo"
start on input-device-added
device='printinputdevices | grep thecorrectdevice'
echo $device 
/start/my/daemon -option device
end script

and also

author "AnVoWiDo"
start on input-device-added
exec myscript.sh

where myscript.sh file contains the script above. The echo command in there is just for diagnostics and outputs correctly in both methods.

Running myscript.sh from terminal will start the daemon perfectly fine with all the expected output. The same is true for running the "/start/my/daemon -option device" command, both will output something along the lines of

device 0: /dev/input/event9 mydevice
Display name: :0

But when launching it from Upstart (with service myservice start or by plugging in a new input device) the output halts midway 'Display name: :0' and only logs 'Display name: ' at which point Upstart kills the process. It looks to me like the double colon in the output is the culprit (or of course the :0), and perhaps Upstart mistakes it for an error code of sorts?

Anyone know of a different method of starting my service at the correct moment? Perhaps I have missed something stupid and obvious while making the Upstart conf file which can be fixed? Lastly maybe Upstart can in some way be convinced to ignore the ": :0" in output (if this really is the cause of course) and keep running the daemon?


Display Name :0 is referring to an X display. It works in your GUI terminal because $DISPLAY is set to :0.

If you want the service to start on your GUI, then you should do

env DISPLAY=":0"
exec /start/my/daemon
  • 1
    This may be insufficient if the daemon also tries to make an X connection. Without $HOME pointing to a directory with an .Xauthority file with a valid security token, the daemon won't be able to connect (unless you do something like xhost +SI:localuser:root). – Marius Gedminas Jan 23 '12 at 10:47

Upstart runs the script as root, which probably doesn't have the DISPLAY environment set (demonstrated by your script debug: Display name: <empty>. When you run the script from command line, DISPLAY is taken from your user account env and is being set correctly.

You can either use SpamapS's answer to add the DISPLAY to job environment, or run the command with exec su - <your account> ....

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.