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:
#!/bin/bash
UDP_PORT=9 # Change this if you need to run this on a different port
START_PHRASE="E.....@"
START_PHRASE_ESCAPED="E.....@"
# The following block checks if the user running this script has the required privileges to listen on the port specified above
WHO=`whoami`
if [ "$WHO" != "root" ]; then
echo "Cannot start unless running as root." >> /var/log/xbmc-starter.log
exit 1
fi
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
/usr/bin/xbmc
echo "test log after command" >> /var/log/xbmc-starter.log
fi
# Sleep, to be nice, for unwanted rogue processes writing to our port
sleep 1
done
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?