machine: add "restart_service" method

Move the service restart functionality out of the "service restart" request into its own method.  This allows the "service restart" to be called internally by other modules.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2021-01-27 06:22:15 -05:00
parent aa9bf0fb9c
commit c365de32cf
1 changed files with 5 additions and 3 deletions

View File

@ -39,13 +39,15 @@ class Machine:
async def reboot_machine(self):
await self._execute_cmd("sudo shutdown -r now")
async def restart_service(self, service_name):
await self._execute_cmd(f'sudo systemctl restart {service_name}')
async def _handle_service_restart(self, web_request):
name = web_request.get('service')
if name == "klipper":
await self._execute_cmd(f'sudo systemctl restart {name}')
await self.restart_service(name)
elif name == "moonraker":
IOLoop.current().spawn_callback(
self._execute_cmd, f'sudo systemctl restart {name}')
IOLoop.current().spawn_callback(self.restart_service, name)
else:
raise self.sever.error(
f"Invalid argument recevied for 'name': {name}")