I am running Ubuntu 12.04. Here is what I am trying to do:

I copied and adapted a shell script from here: http://yatse.leetzone.org/redmine/boards/2/topics/2088. It listens to UDP port 9 for Wake-On-LAN packages. When it receives a package, it should start xbmc. Here is the script /home/myusername/.xbmc/autostarter:

UDP_PORT=9          # Change this if you need to run this on a different port


# The following block checks if the user running this script has the required      privileges to listen on the port specified above
if [ "$WHO" != "root" ]; then
     echo "Cannot start unless running as root." >> /var/log/xbmc-starter.log
  exit 1

echo "Listening on port $UDP_PORT for start command" >> /var/log/xbmc-starter.log

while [ true ]; do
     # Wait for a packet to come in
     LISTEN=`tcpdump "udp port $UDP_PORT" -A -c 1 2>&1 | grep -o    "$START_PHRASE_ESCAPED"`
     # Make sure that we received the right command
     if [ "$LISTEN" = "$START_PHRASE" ]; then
        echo "Starting XBMC" >> /var/log/xbmc-starter.log
        echo "test log after command" >> /var/log/xbmc-starter.log
     # Sleep, to be nice, for unwanted rogue processes writing to our port
     sleep 1

When I run this script from command line with sudo and send the WOL package, it works and starts xbmc.

sudo ./autostarter

The log output is:

Listening on port 9 for start command
Starting XBMC
test log after command

But when I run it from an upstart script, it creates the same log output but does not start xbmc. Here is my upstart script xbmc-starter.conf:

# Starts a listener that runs the xbmc start script when a WOL package is received
description     "start xbmc wol listener script"
# runlevels
start on runlevel [2345]
stop on runlevel [!2345]
exec /home/myusername/.xbmc/autostarter

And the log output:

Listening on port 9 for start command
Starting XBMC
test log after command

Why doesn't it start XBMC?


Maybe adding env DISPLAY=:0 to the Upstart job would help? I think XBMC needs to be able to know what display to use, you know?

  • Thanks, I already tried that but it had no effect. But it seems that I have to do this also in addition to the solution of the other Problem. – Arnold Franke Oct 24 '14 at 22:51
  • Maybe adding --standalone to xbmc's options would work. – CameronNemo Oct 24 '14 at 23:44
  • Your first suggestion was part of the solution! See my comment on the other answer. Thank you very much! – Arnold Franke Oct 25 '14 at 22:55

I'll take a shot, since no one else has offered an answer.

Try changing your start condition to start on started tty1

My understanding of init systems is that they will happily start programs at weird times if you ask them to. Asking to start at the run levels could mean at the beginning of those run levels, before anything else has started. Like before things like any part of the file system have been mounted, and certainly before minimal networking is available.

start on started tty1 will wait till the first terminal is started before starting the program, which is basically the same time that you would be able to run/test things manually. So your program starts up later in the boot process, but you should get more consistent results.

  • Thanks, but I don't think that is the problem. The log output suggests that the script is started correctly and that tcpdump receives the WOL package correctly. Otherwise it could not have entered the if-block and logged the last two lines. The problem seems to be with the execution of the xbmc command. – Arnold Franke Oct 23 '14 at 6:27
  • OK, fair enough. FWIW, I am confident that the syntax I gave you will work. It is the simple way to have a script start up on bootup, per some guide I read. If you DO give it a try, let me know if it still doesn't work. I'm curious. – user7134 Oct 23 '14 at 19:49
  • and maybe check the xbmc.log file to see if there are any errors there. gl – user7134 Oct 23 '14 at 19:54
  • Ok, I tried "start on started tty1". First, the result didn't change. BUT: I also wrote a simpler script for testing that just waits 10 seconds and then starts XBMC (without any network foo). This script had the same Problem. But then I tried this script with "start on started tty1" and the result was weird: 1. Ubuntu didn't boot anymore. Black screen, no GUI no CLI available. 2. Boot in recovery mode into resume normal boot. Suddenly xbmc starts immediatly. 3. Boot normally again - ubuntu still won't start. I had to change the script back in recovery mode. What does all that mean? – Arnold Franke Oct 24 '14 at 16:09
  • 2
    Solved it! It was two things combined. First, I have to start xbmc with the user i am logged in with and NOT with root (as the upstart script does). So I changed the xbmc command to "sudo -u myusername /usr/bin/xbmc". The second thing was almost what CameronNemo suggested, only that my Display is named :0.0 apparently. So adding "export DISPLAY=:0.0" before starting xbmc finally did the trick. So thanks to both of you for helping me on my way to the solution! I would upvote but it seems that I do not have enough reputation yet. – Arnold Franke Oct 25 '14 at 22:54

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.