Ankündigung

Einklappen
Keine Ankündigung bisher.

Problem running as service

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    Problem running as service

    Hallo,

    um mein iPad mit Smarthome/Smartvisu schneller verfügbar zu machen, habe ich die Anleitung wie in https://www.symcon.de/forum/threads/25177 beschrieben befolgt.
    Ich kann jetzt mein iPad aus einer Smarthome.py logik heraus schlafen legen bzw wieder aufwecken (getriggert durch PM).

    Code:
    #!/usr/bin/env python
    
    # Option 1)
    # requires paramiko
    # https://github.com/paramiko/paramiko/
    # pip install paramiko
    #
    # Option 2)
    # Requries that SSH keys are set so that no pwd is asked for
    # ssh-keygen -b 4096 (run as smarthome user)
    # copy public id into iPad's authenticated_keys
    #
    # configure iPad as per https://www.symcon.de/forum/threads/25177
    # set 3 tasks
    # 1) schlafen -> set iPad to sleep
    # 2) aufwachen -> simulate Homebutton
    # 3) visu -> launch browser with visu
    
    from paramiko import SSHClient
    import time
    import subprocess
    
    option = 1;
    
    
    #logger.warning("BY" + str(trigger['by'])) # Item
    #logger.warning("SOURCE" + str(trigger['source'])) # Item
    #logger.warning("DEST" + str(trigger['dest'])) # Item
    #logger.warning("VALUE" + str(trigger['value'])) # Item
    
    
    if option==1:
        client = SSHClient()
        client.load_system_host_keys()
        client.connect("192.168.2.103", username="root")
    
    if option==2:
        ret=""
        
        
    if sh.EG.wohnzimmer.ipad.sperren() == True:
        logger.warning("iPad ist gesperrt!")
    else:
        if trigger['source'] == "Haustuer.klingel":
            if sh.Haustuer.klingel() == True:
                subprocess.call(["ssh", "root@192.168.2.103", "notify_post aufwachen"]) if option==1 else client.exec_command('notify_post aufwachen')
                subprocess.call(["ssh", "root@192.168.2.103", "notify_post visu"]) if option ==1 else client.exec_command('notify_post visu')
    #             stdin, stdout, stderr = client.exec_command('notify_post aufwachen')
    #             stdin, stdout, stderr = client.exec_command('notify_post visu')
                logger.warning("iPad wurde von Klingel eingeschaltet")
        elif trigger['source'] == "EG.wohnzimmer.ipad.schalten":
            if sh.EG.wohnzimmer.ipad.schalten() == True:
                subprocess.call(["ssh", "root@192.168.2.103", "notify_post aufwachen"]) if option==1 else client.exec_command('notify_post aufwachen')
                time.sleep(0.5)
                subprocess.call(["ssh", "root@192.168.2.103", "notify_post visu"]) if option==1 else client.exec_command('notify_post visu')
    #             stdin, stdout, stderr = client.exec_command('notify_post aufwachen')
    #             time.sleep(0.5)
    #             stdin, stdout, stderr = client.exec_command('notify_post visu')
                logger.warning("iPad wurde manuell über Visu eingeschaltet")
            elif sh.EG.wohnzimmer.ipad.schalten() == False:
    #            stdin, stdout, stderr = client.exec_command('notify_post schlafen')
                subprocess.call(["ssh", "root@192.168.2.103", "notify_post schlafen"]) if option==1 else client.exec_command('notify_post schlafen')
                logger.warning("iPad wurde manuell über Visu ausgeschaltet")
        else:
            if sh.EG.kueche.praesenz() == True or sh.EG.wohnzimmer.praesenz() == True:
                subprocess.call(["ssh", "root@192.168.2.103", "notify_post aufwachen"]) if option==1 else client.exec_command('notify_post aufwachen')
                time.sleep(0.5)
                subprocess.call(["ssh", "root@192.168.2.103", "notify_post visu"]) if option==1 else client.exec_command('notify_post visu')
    #             stdin, stdout, stderr = client.exec_command('notify_post aufwachen')
    #             time.sleep(0.5)
    #             stdin, stdout, stderr = client.exec_command('notify_post visu')
        #        time.sleep(0.5)
        #        stdin, stdout, stderr = client.exec_command('sblaunch com.opera.Coast')
                logger.warning("iPad wurde von Bewegungsmelder {0} eingeschaltet".format(str(trigger['source'])))
            else:
                subprocess.call(["ssh", "root@192.168.2.103", "notify_post schlafen"]) if option==1 else client.exec_command('notify_post schlafen')
    #            stdin, stdout, stderr = client.exec_command('notify_post schlafen')
                logger.warning("iPad wurde von Bewegungsmelder {0} ausgeschaltet".format(str(trigger['source'])))
    
    if option==1:
        client.close()
    Mein Problem: Im interactive Modus von Smarthome funktioniert alles wunderbar. Auszug aus Log:
    Code:
     2016-01-04 09:15:07,886 DEBUG    Thread-7     starting thread (client mode): 0xb0dab90c -- transport.py:_log:1545
      2016-01-04 09:15:07,886 DEBUG    Thread-7     Local version/idstring: SSH-2.0-paramiko_1.16.0 -- transport.py:_log:1545
      2016-01-04 09:15:07,960 DEBUG    Thread-7     Remote version/idstring: SSH-2.0-OpenSSH_6.7 -- transport.py:_log:1545
      2016-01-04 09:15:07,960 INFO     Thread-7     Connected (version 2.0, client OpenSSH_6.7) -- transport.py:_log:1545
      2016-01-04 09:15:07,962 DEBUG    Thread-7     kex algos:['curve25519-sha256@libssh.org', 'ecdh-sha2-nistp256', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp521', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group14-sha1'] server key:['ssh-rsa', 'ssh-dss'] client encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'chacha20-poly1305@openssh.com'] server encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'chacha20-poly1305@openssh.com'] client mac:['umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'] server mac:['umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'] client compress:['none', 'zlib@openssh.com'] server compress:['none', 'zlib@openssh.com'] client lang:[''] server lang:[''] kex follows?False -- transport.py:_log:1545
      2016-01-04 09:15:07,962 DEBUG    Thread-7     Kex agreed: diffie-hellman-group14-sha1 -- transport.py:_log:1545
      2016-01-04 09:15:07,962 DEBUG    Thread-7     Cipher agreed: aes128-ctr -- transport.py:_log:1545
      2016-01-04 09:15:07,962 DEBUG    Thread-7     MAC agreed: hmac-sha2-256 -- transport.py:_log:1545
      2016-01-04 09:15:07,963 DEBUG    Thread-7     Compression agreed: none -- transport.py:_log:1545
      2016-01-04 09:15:08,276 DEBUG    Thread-7     kex engine KexGroup14 specified hash_algo <built-in function openssl_sha1> -- transport.py:_log:1545
      2016-01-04 09:15:08,277 DEBUG    Thread-7     Switch to new keys ... -- transport.py:_log:1545
      2016-01-04 09:15:08,280 DEBUG    ipad         Trying discovered key b'xxxxxxxxxxxxxxxxxxxxxxxxxxxx' in /home/christian/.ssh/id_rsa -- transport.py:_log:1545
      2016-01-04 09:15:08,283 DEBUG    Thread-7     userauth is OK -- transport.py:_log:1545

    Sobald ich aber Smarthome als Service starte bekomme ich immer folgende Fehlermeldung:

    Code:
     2016-01-04 09:13:32 ERROR    Thread-6     Socket exception: Bad file descriptor (9)
      2016-01-04 09:13:32 ERROR    ipad         Logic: ipad, File: /usr/local/lib/python3.4/dist-packages/paramiko/transport.py, Line: 1909, Method: _send_kex_init, Exception: [Errno 9] Bad file descriptor
      Traceback (most recent call last):
        File "/usr/local/smarthome/lib/scheduler.py", line 341, in _task
          exec(obj.bytecode)
        File "/usr/local/smarthome/logics/ipad.py", line 35, in <module>
          client.connect("192.168.2.103", username="root")
        File "/usr/local/lib/python3.4/dist-packages/paramiko/client.py", line 325, in connect
          t.start_client()
        File "/usr/local/lib/python3.4/dist-packages/paramiko/transport.py", line 492, in start_client
          raise e
        File "/usr/local/lib/python3.4/dist-packages/paramiko/transport.py", line 1719, in run
          self._send_kex_init()
        File "/usr/local/lib/python3.4/dist-packages/paramiko/transport.py", line 1909, in _send_kex_init
          m.add_bytes(os.urandom(16))
      OSError: [Errno 9] Bad file descriptor
    Der Code ist absolut identisch, die Fehlermeldung lässt sich reproduzieren, sobald ich im Service Mode bin. Ich habe auch 2 unterschiedliche Arten des Zugriffs ausprobiert (Optionen 1 und 2 in der Logik), die beide separat im interaktiven Modus funktionieren.
    Habe gestern das ganze mit nohub gestartet und da funktioniert es auch. Habe auch probiert, smarthome service nicht mit dem smarthome user sondern "meinem" user zu starten => immer die gleiche Fehlermeldung.

    Hat jemand eine Ahnung was ich noch probieren könnte?

    Danke
    christian
    ++ Der ultimative ETS Schnellkurs ++
    KNX und die ETS vom Profi lernen
    www.ets-schnellkurs.de

    #2
    Hallo,

    ich vermute das paramiko nicht damit klar kommt kein Zugriff auf stdin/stdout zu bekommen. Als Service stehen die quasi nicht mehr zur Verfügung.

    Bis bald

    Marcus

    Kommentar


      #3
      So wie es scheint, hat Paramiko ein Problem unter daemon zu laufen: http://stackoverflow.com/questions/2...causes-ioerror

      Habe das jetzt über Pythons subprocess hinbekommen...

      Danke
      ++ Der ultimative ETS Schnellkurs ++
      KNX und die ETS vom Profi lernen
      www.ets-schnellkurs.de

      Kommentar

      Lädt...
      X