O script Bash funciona a partir da linha de comando, mas não se iniciado pelo upstart

3

Eu tenho um script que escuta na porta 12 e invoca o xbmc ao receber um pacote wol. Ele funciona perfeitamente quando eu inicio o script diretamente da linha de comando, mas nada acontece quando eu deixo o upstart executá-lo, nem mesmo grava no arquivo de log. Alguma idéia por quê?

EDIT: Adicionado log no final do segmento

Aqui está o script xbmc seguido, mas o script inicial:

#!/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   

Autostarter remoto Yatse XMBC

descrição "Yatse XMBC remote autostarter" autor "Henk Bezuidenhout link "

# 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 ()
    
por Yotam 06.12.2014 / 13:09

1 resposta

0

Acho que você precisa exportar a exibição do usuário no script para saber qual exibição usar. Normalmente, a exibição padrão do primeiro usuário X é definida como :0 .

Tente adicionar export DISPLAY=:0 ao topo do script:

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
    
por victorbrca 16.02.2015 / 19:22