Call python script in extcommands.xml

edited December 2015 in Repetier-Server
Hi
I have 0.65.0 running on an RPI and want to call a python script from within the extcommands.xml. The corrosponding section looks like this:

<command>
     <name>Switch Relay</name>
     <execute>sudo /var/lib/Repetier-Server/database/relay.py</execute>
</command>


I also added:

repetierserver ALL=NOPASSWD: /usr/bin/python

to /etc/sudoers.d, but when I finally tap on the button, nothing happens. Other commands work fine, just these python related won't work. When I execute /var/lib/Repetier-Server/database/relay.py from bash, it works fine.

I'm not very familiar with linux, so I have any clue whats going wrong here. Any hints?

Regards
Holger

Comments

  • You have to start python code within python I think. If you run from commandline the bash shell detects that it should start python relay.py instead, but from host it is executed directly. So call python with the script as argument and it should work. Use full path names!

    sudo is only required if you need to run a command as root like shutdown. Without it will run with the same id as the server runs (so make sure everything is then allowed e.g. writing to disk).
  • No, that doesn't work either.

    <command>
          <name>Switch Relay</name>
           <execute>/usr/bin/python /var/lib/Repetier-Server/database/relay.py</execute>
    </command>
     
    Nothing happens when tapping the button. Same call in bash works.
  • Does server.log show anything? If you print something it should appear in server log I think.

    It might be a permission problem since it is started as user repetierserver
    Try running manually with
    sudo -u repetierserver

    and see if it would still work.
















  • The log only reports "Starting external command /usr/bin/python with 1 parameters."
    Starting manually brings up more detail:

    Traceback (most recent call last):
      File "/var/lib/Repetier-Server/database/relay.py", line 17, in <module>
        GPIO.setup(RELAIS_1, GPIO.OUT)
    RuntimeError: No access to /dev/mem.  Try running as root!

    So finally I NEEDED to sudo call python and the script from within extcommands.xml

            <command>
                    <name>Switch Relay</name>
                    <execute>sudo /usr/bin/python /var/lib/Repetier-Server/database/relay.py</execute>
            </command>

    Thanks for your Help.
    Hmmm, I'm wondering why I can execute the script from bash even without sudo, since I'm logged in as pi, not as root.
  • I guess you need to be member of the right group to access the pins. pi has different groups then repetierserver and root can do anything anyway.
Sign In or Register to comment.