Yatse XMBC 远程自动启动

Yatse XMBC 远程自动启动

我有一个脚本,它在端口 12 上监听,并在收到 wol 数据包时调用 xbmc。当我直接从命令行启动脚本时,它运行良好,但当我让 upstart 运行它时什么也没发生,甚至没有写入日志文件。有什么想法吗?

编辑:在线程末尾添加日志

以下是 xbmc 脚本,但遵循了 upstart 脚本:

#!/bin/bash

UDP_PORT=12            # Change this if you need to run this on a different port, just remember to update Yatse's settings as well
RUN_XBMC_AS=usrname     # Change this if you need to run it as another user

LOG_FILE="${HOME}/xbmc-autostarter.log"

START_PHRASE="YatseStart-Xbmc"    # Do not touch this, unless you know what you are doing...

# 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 "Unprivileged users may not evesdrop on ports. Cannot start unless running as root."  &>> "${LOG_FILE}"
      exit 1
   fi

echo "Listening on port $UDP_PORT for Yatse remote start command"  &>> "${LOG_FILE}"

while [ true ]; do
   # Wait for a packet to come in from Yatse
   LISTEN=`tcpdump "udp port $UDP_PORT" -A -c 1 -i wlan0 2>&1 | grep -o "$START_PHRASE"`
   echo ${LISTEN}  &>> "${LOG_FILE}"
   # Make sure that we received the right command
   if [ "$LISTEN" = "$START_PHRASE" ]; then
      #echo "Starting XBMC as $RUN_XBMC_AS" 
      # Start XBMC using sudo -u to run it using the username above
      # If you need to you can replace the xbmc command below with xbmc-standalone if you are not using a window manager
      sudo --user=$RUN_XBMC_AS xbmc  &>> "${LOG_FILE}"
   fi 
   # Sleep, to be nice, for unwanted rogue processes writing to our port
   sleep 1
done   

Yatse XMBC 远程自动启动

描述“Yatse XMBC 远程自动启动”作者“Henk Bezuidenhouthttp://yatse.leetzone.org/redmine/boards/2/topics/2088

# Stanzas
#
# Stanzas control when and how a process is started and stopped
# See a list of stanzas here: http://upstart.ubuntu.com/wiki/Stanzas#respawn

# When to start the service
start on runlevel [2345]

# When to stop the service
stop on runlevel [016]

# Automatically restart process if crashed
respawn

# Start the process
exec /bin/bash /home/yotam/bin/xbmc-autostarter


YatseStart-Xbmc
/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:57: GtkWarning: could not open display
  warnings.warn(str(e), _gtk.Warning)
Error: unable to open display 
/usr/share/xbmc/FEH.py:69: Warning: invalid (NULL) pointer instance
  window = gtk.Window(gtk.WINDOW_TOPLEVEL)
/usr/share/xbmc/FEH.py:69: Warning: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed
  window = gtk.Window(gtk.WINDOW_TOPLEVEL)
/usr/share/xbmc/FEH.py:83: GtkWarning: IA__gtk_settings_get_for_screen: assertion 'GDK_IS_SCREEN (screen)' failed
  button = gtk.Button("Quit")
/usr/share/xbmc/FEH.py:83: Warning: g_object_get: assertion 'G_IS_OBJECT (object)' failed
  button = gtk.Button("Quit")
/usr/share/xbmc/FEH.py:88: GtkWarning: Screen for GtkWindow not set; you must always set
a screen for a GtkWindow before using the window
  window.show_all ()
/usr/share/xbmc/FEH.py:88: GtkWarning: IA__gdk_pango_context_get_for_screen: assertion 'GDK_IS_SCREEN (screen)' failed
  window.show_all ()
/usr/share/xbmc/FEH.py:88: PangoWarning: pango_context_set_font_description: assertion 'context != NULL' failed
  window.show_all ()
/usr/share/xbmc/FEH.py:88: PangoWarning: pango_context_set_base_dir: assertion 'context != NULL' failed
  window.show_all ()
/usr/share/xbmc/FEH.py:88: PangoWarning: pango_context_set_language: assertion 'context != NULL' failed
  window.show_all ()
/usr/share/xbmc/FEH.py:88: PangoWarning: pango_layout_new: assertion 'context != NULL' failed
  window.show_all ()
/usr/share/xbmc/FEH.py:88: PangoWarning: pango_layout_set_text: assertion 'layout != NULL' failed
  window.show_all ()
/usr/share/xbmc/FEH.py:88: PangoWarning: pango_layout_set_alignment: assertion 'layout != NULL' failed
  window.show_all ()
/usr/share/xbmc/FEH.py:88: PangoWarning: pango_layout_set_ellipsize: assertion 'PANGO_IS_LAYOUT (layout)' failed
  window.show_all ()
/usr/share/xbmc/FEH.py:88: PangoWarning: pango_layout_set_single_paragraph_mode: assertion 'PANGO_IS_LAYOUT (layout)' failed
  window.show_all ()
/usr/share/xbmc/FEH.py:88: PangoWarning: pango_layout_set_width: assertion 'layout != NULL' failed
  window.show_all ()
/usr/share/xbmc/FEH.py:88: PangoWarning: pango_layout_get_extents: assertion 'layout != NULL' failed
  window.show_all ()
/usr/share/xbmc/FEH.py:88: PangoWarning: pango_layout_set_attributes: assertion 'layout != NULL' failed
  window.show_all ()
/usr/share/xbmc/FEH.py:88: GtkWarning: IA__gdk_screen_get_default_colormap: assertion 'GDK_IS_SCREEN (screen)' failed
  window.show_all ()
/usr/share/xbmc/FEH.py:88: GtkWarning: IA__gdk_colormap_get_visual: assertion 'GDK_IS_COLORMAP (colormap)' failed
  window.show_all ()
/usr/share/xbmc/FEH.py:88: GtkWarning: IA__gdk_screen_get_root_window: assertion 'GDK_IS_SCREEN (screen)' failed
  window.show_all ()
/usr/share/xbmc/FEH.py:88: GtkWarning: IA__gdk_window_new: assertion 'GDK_IS_WINDOW (parent)' failed
  window.show_all ()

答案1

我认为您需要在脚本中导出用户的显示,以便它知道要使用哪个显示。通常,第一个 X 用户的默认显示设置为:0

尝试添加export DISPLAY=:0到脚本的顶部:

UDP_PORT=12            # Change this if you need to run this on a different port, just remember to update Yatse's settings as well
RUN_XBMC_AS=usrname     # Change this if you need to run it as another user
export DISPLAY=:0

相关内容