thelastWallE / OctoprintKlipperPlugin

A plugin for a better integration of Klipper into OctoPrint.
GNU Affero General Public License v3.0
65 stars 14 forks source link

[Feature Request] Restart Klipper service #55

Closed jpedrick closed 3 years ago

jpedrick commented 3 years ago

After certain actions, such as M112, I find that I need to restart the entire klipper service to get my printer back to a functional state. It'd be helpful to have a service restart button.

Maybe also a "Full restart" service(sudo service klipper restart), host(gcode:RESTART), firmware.

thelastWallE commented 3 years ago

I i understand correct you need also the "sudo service klipper restart" command beside the other two existing commands? octoklippertab_mark

jpedrick commented 3 years ago

@thelastWallE Yes exactly that

I i understand correct you need also the "sudo service klipper restart" command beside the other two existing commands? octoklippertab_mark

Sineos commented 3 years ago

This can quite easily be achieved in octoprint itself:

Edit your octoprint config.yaml:

system:
  actions:
  - action: KlipperRestart
    command: sudo /bin/systemctl restart klipper.service
    name: Restart Klipper

(Can't remember if the system section is already there or needs to be created)

In addition you will have to allow the user, under which Octoprint runs, sudoer rights:

Edit /etc/sudoers or better create an include under /etc/sudoers.d/ and add an entry like:

pi ALL=(ALL) NOPASSWD:ALL

This will allow the user pi to call all commands via sudo. You can limit this to certain commands if you want, but I did not bother for an internal system that is not exposed.

Btw, this sudoer step would likely also be needed if @thelastWallE would implement it, since OctoKlipper also can only draw on the same permissions.

Result: grafik

thelastWallE commented 3 years ago

Yes the need for sudo is a little roadblocker here for this. I would need to show some instruction in the settings dialog if someone want this command on a button.

For the command function i would have looked at the action commands plugin. There should be already a working example how to do this in a plugin.

@Sineos would this command in the menu of octoprint be showing a warning popup?

Sineos commented 3 years ago

@Sineos would this command in the menu of octoprint be showing a warning popup?

No, it just executes the command the same way as it would in a shell. I thou shows a success popup:

grafik

Guess it just uses the exit status of the command.

z00mantwo commented 3 years ago

Following will also add it to the Octoprint "System" menu at the bottom. Note this does not work if you have the OctoDash plugin loaded.

pi@octopi:~/oprint/lib/python3.7/site-packages/octoprint_klipper $ diff init.py init.py.orig 617,620d616 < plugin_settings_overlay = {'system': {'actions': [{'action': 'octoklipper_restart', < 'command': 'sudo service klipper restart', < 'name': 'Restart Klipper', < 'confirm': 'You are about to restart Klipper.'}]}}

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.