Tweak machine.py component to allow rebooting and shutting down from mainsail GUI on a runit based distro ( just tested on voidlinux) #687
engelsheidt
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! I have been using klipper-moonraker-mainsail for around 1 year on a thinclient (voidlinux), i manually installed them and have been trying to make the host control work( via Mainsail´s GUI) , initially moonraker didn´t let me execute the reboot command because it detected the thinclient as a container because of the following:
[common.py:build_error()] - JSON-RPC Request-Error -Requested Method: machine.reboot. Code:400, Message: Cannot reboot within a 1xc container
I bypassed _check_inside_container (inside machine.py) by commenting the following lines:
def _check_inside_container(self) -> Dict[str, Any]:
cgroup_file = pathlib.Path(CGROUP_PATH)
virt_type = virt_id = "none"
if cgroup_file.exists():
try:
data = cgroup_file.read_text()
container_types = ["docker", "lxc"]
for ct in container_types:
if ct in data:
#self.inside_container = True
#virt_type = "container"
#virt_id = ct
logging.info(
f"Container detected via cgroup: {ct}"
)
After that moonraker gave me another error: "Container detected via sched", so i went back to machine.py and added "runit" to:
if proc_name not in ["init", "systemd", "runit"]:
Then commented and added the following to machine.py:
async def shutdown(self) -> None:
#await self._exec_sudo_command(f"systemctl {self.shutdown_action}")
await self._exec_sudo_command("poweroff")
async def reboot(self) -> None:
#await self._exec_sudo_command("systemctl reboot")
await self._exec_sudo_command("reboot")
Finally , at the end of the sudoers file i added:
pi ALL=(ALL) NOPASSWD: /usr/bin/halt,/usr/bin/poweroff,/usr/bin/reboot,/run/runit/stopit
Rebooted the thinclient (via ssh) and the host control works for now via mainsail GUI.
Klipper and moonraker run as user services, nginx as a root service.
I understand that my method to achieve the result is not ideal, that´s why I'm requesting the feature.
The user service directory looks like:
#!/bin/bash
exec 2>&1
exec chpst -u pi:"pi:dialout" runsvdir /home/pi/service
The klipper user service file contains:
~/sv/klipper-pi/run
#!/bin/bash
export HOME="/home/pi"
exec "$HOME"/klippy-env/bin/python "$HOME"/klipper/klippy/klippy.py "$HOME"/printer_data//logs/klippy.log -a /tmp/klippy_uds
The moonraker user service file contains:
~/sv/moonraker-pi/run
#!/bin/bash
export HOME="/home/pi"
exec "$HOME"/moonraker-env/bin/python "$HOME"/moonraker/moonraker/moonraker.py -c "$HOME"/printer_data/config/moonraker.conf -l "$HOME/printer_data/logs/moonraker.log
Running klipper and moonraker using python3
Finally adding the option to specify custom reboot, shutdown and system update shell commands on the .conf file would be amazing .
Beta Was this translation helpful? Give feedback.
All reactions