Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    ExecOnMcode V0.5, sudo commands are not executed

    Scheduled Pinned Locked Moved
    Plugins for DWC and DSF
    3
    8
    317
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • theoxundefined
      theox
      last edited by theox

      Re: [ExecOnMcode + 3.4.6](sudo commands are not executed)

      Hi there,

      I'm encountering an issue with the ExecOnMcode plugin (v0.5) in conjunction with DSF 3.4.6 on my Duet setup (SBC raspberrypi4). Specifically, I'm trying to execute a command using sudo within the plugin to launch a Python script for calibrating different printheads, like so:

      sudo python "path/calib.py"
      

      However, it seems that commands starting with sudo aren't being executed properly. When I attempt to run this command, it ends immediately without any error, indicated by a green status.

      I attempted to address this by modifying the ExecOnMcode.json file to include the "superUser" permission, but this resulted in unexpected behavior. After restarting duetcontrolserver, the plugin appeared broken, with all commands disappearing and the inability to save new ones.

      Has anyone encountered a similar issue or found a workaround for executing sudo commands within the ExecOnMcode plugin successfully? Any insights or suggestions would be greatly appreciated.

      Thanks in advance for your help!

      chrishammundefined Falcounetundefined 2 Replies Last reply Reply Quote 0
      • chrishammundefined
        chrishamm administrators @theox
        last edited by

        @theox It isn't recommended to use sudo from plugins, but if you insist, change /etc/sudoers to include user or group dsf (possibly with NOPASSWD option).

        Duet software engineer

        1 Reply Last reply Reply Quote 0
        • Falcounetundefined
          Falcounet @theox
          last edited by

          @theox This is documented here : https://github.com/LoicGRENON/DSF_ExecOnMcode_Plugin?tab=readme-ov-file#limitations

          1 Reply Last reply Reply Quote 0
          • theoxundefined
            theox
            last edited by

            @chrishamm said in ExecOnMcode V0.5, sudo commands are not executed:

            /etc/sudoers

            Hi again,

            Thank you both for your quick responses. I had already adjusted the sudo user permissions as suggested.
            Despite following the instructions provided by Falcounet and adjusting the sudo user permissions in /etc/sudoers.d/, I'm still unable to execute commands prefixed with sudo successfully.

            Here's a simple example to illustrate the problem:

            echo hello  
            

            OK.png
            However, when I try to execute the command with sudo:

            sudo echo hello 
            

            notOK.png
            The command fails to execute.

            The reason I need to use sudo commands is due to my reliance on the dsf-python library. It seems that running the file without sudo prevents the Raspberry Pi from communicating with the Duet, leading to errors like the one depicted below:
            error.png

            chrishammundefined 1 Reply Last reply Reply Quote 0
            • chrishammundefined
              chrishamm administrators @theox
              last edited by

              @theox said in ExecOnMcode V0.5, sudo commands are not executed:

              The reason I need to use sudo commands is due to my reliance on the dsf-python library. It seems that running the file without sudo prevents the Raspberry Pi from communicating with the Duet, leading to errors like the one depicted below:

              If you run your program as another user, make sure it is part of the dsf group (unless it is root). Otherwise it will not have permission to access the IPC socket and you get the error you posted (add it via sudo gpasswd -a SMT dsf, then log out and back in, and try again).

              Duet software engineer

              theoxundefined 1 Reply Last reply Reply Quote 0
              • theoxundefined
                theox @chrishamm
                last edited by

                @chrishamm

                Now, I am able to run the program through an SSH connection using my SMT user. However, it still doesn't work when I use the plugin. Can I run the program using the dsf user ? This way, I will be able to see the errors. I tried but couldn't find the password.

                chrishammundefined 1 Reply Last reply Reply Quote 0
                • chrishammundefined
                  chrishamm administrators @theox
                  last edited by

                  @theox Yes, you can, either using sudo -u dsf <your program> or by wrapping it into a plugin (see here). For dev purposes it's probably easier to just run it as dsf. The dsf user is a system account and has no password set.

                  Btw there is no need to use ExecOnMCode to start your own program that already communicates with DSF. Instead you could write the necessary code interceptor yourself and simplify the whole structure that way (see here).

                  Duet software engineer

                  1 Reply Last reply Reply Quote 0
                  • theoxundefined
                    theox
                    last edited by

                    Thank you, @chrishamm , for the guidance. I've followed your suggestion to intercept the command directly using dsf-python, and it's working as intended. This approach simplify the process significantly. I appreciate your help!

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post
                    Unless otherwise noted, all forum content is licensed under CC-BY-SA