Salandora / OctoPrint-SystemCommandEditor

This plugin makes System Commands editable through the OctoPrint WebUI
GNU Affero General Public License v3.0
9 stars 10 forks source link

Error when running webcam reset command #25

Open Rolleroo opened 2 years ago

Rolleroo commented 2 years ago

I am trying to run the command below using a function call Reset Webcam:

sudo pkill mjpg_streamer

I am getting an error code thus:

{"error":"Command for custom:Reset Webcam failed: 500 Internal Server Error: Command for custom:Reset Webcam failed with return code 1:\nSTDOUT: \nSTDERR: sudo: no tty present and no askpass program specified\n"}

I am guessing this is because of a lack of admin privledges. Please can you help out how I can make this work?

Apologies if this is a trivial fix as a bit of a Linus noob.

Roller

a0s commented 2 years ago

What about sudo ? My file /etc/sudoers.d/10-user :

odroid ALL=(ALL) NOPASSWD:ALL

Just replace odroid with user under which your OctoPrint was started, pi for e.g. and reboot, then sudo pkill mjpg_streamer starts working

Rolleroo commented 2 years ago

Thanks for the response.

Not sure it is very elegant but ended up using this

echo "PWD" | sudo -S pkill mjpg_streamer

Where PWD is the password for pi user

a0s commented 2 years ago

OFFTOPIC: I prefered to have more structured setup of this things: systemd servise + environment generator

/etc/systemd/system/webcam.service:

[Unit]
Description=Webcam
After=network.target
Requires=network.target

[Service]
Restart=always
WorkingDirectory=/root/mjpg-streamer/mjpg-streamer-experimental
EnvironmentFile=/root/mjpg-streamer/mjpg-streamer-experimental/environment
ExecStartPre=-/root/mjpg-streamer/mjpg-streamer-experimental/webcam-pre.sh
ExecStart=\
     /root/mjpg-streamer/mjpg-streamer-experimental/_build/mjpg_streamer \
        -i "input_uvc.so --resolution 1280x720 -d ${DEVICE} -y" \
        -o "output_http.so -p 8090 -w ./www"

[Install]
WantedBy=multi-user.target

/root/mjpg-streamer/mjpg-streamer-experimental/webcam-pre.sh:

#!/usr/bin/env sh
echo "DEVICE=$(/usr/bin/v4l2-ctl --media-bus-info  usb-12110000.usb-1 --list-devices | grep video | head -n 1)" > /root/mjpg-streamer/mjpg-streamer-experimental/environment

Some additional preparations (from root):

apt install -y - v4l-utils cmake libjpeg8-dev
chmod +x /root/mjpg-streamer/mjpg-streamer-experimental/webcam-pre.sh
systemctl enable webcam
systemctl start webcam