ExecOnMcode V0.5, sudo commands are not executed
-
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!
-
@theox It isn't recommended to use sudo from plugins, but if you insist, change /etc/sudoers to include user or group
dsf
(possibly withNOPASSWD
option). -
@theox This is documented here : https://github.com/LoicGRENON/DSF_ExecOnMcode_Plugin?tab=readme-ov-file#limitations
-
@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
However, when I try to execute the command with sudo:sudo echo hello
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:
-
@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 isroot
). Otherwise it will not have permission to access the IPC socket and you get the error you posted (add it viasudo gpasswd -a SMT dsf
, then log out and back in, and try again). -
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.
-
@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 asdsf
. Thedsf
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).
-
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!