From dc56b6f4ad5358875f26d9639eee5835ea30a386 Mon Sep 17 00:00:00 2001 From: Inex Code Date: Wed, 17 Nov 2021 12:36:26 +0200 Subject: [PATCH] Use systemd units for system rebuilds --- selfprivacy_api/resources/system.py | 34 ++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/selfprivacy_api/resources/system.py b/selfprivacy_api/resources/system.py index 1c41d8e..7c3ad77 100644 --- a/selfprivacy_api/resources/system.py +++ b/selfprivacy_api/resources/system.py @@ -25,7 +25,9 @@ class RebuildSystem(Resource): 401: description: Unauthorized """ - rebuild_result = subprocess.Popen(["nixos-rebuild", "switch"]) + rebuild_result = subprocess.Popen( + ["systemctl", "start", "sp-nixos-rebuild.service"], start_new_session=True + ) rebuild_result.communicate()[0] return rebuild_result.returncode @@ -47,7 +49,9 @@ class RollbackSystem(Resource): 401: description: Unauthorized """ - rollback_result = subprocess.Popen(["nixos-rebuild", "switch", "--rollback"]) + rollback_result = subprocess.Popen( + ["systemctl", "start", "sp-nixos-rollback.service"], start_new_session=True + ) rollback_result.communicate()[0] return rollback_result.returncode @@ -69,11 +73,34 @@ class UpgradeSystem(Resource): 401: description: Unauthorized """ - upgrade_result = subprocess.Popen(["nixos-rebuild", "switch", "--upgrade"]) + upgrade_result = subprocess.Popen( + ["systemctl", "start", "sp-nixos-upgrade.service"], start_new_session=True + ) upgrade_result.communicate()[0] return upgrade_result.returncode +class RebootSystem(Resource): + """Reboot the system""" + + def get(self): + """ + Reboot the system + --- + tags: + - System + security: + - bearerAuth: [] + responses: + 200: + description: System reboot has started + 401: + description: Unauthorized + """ + subprocess.Popen(["reboot"], start_new_session=True) + return "System reboot has started" + + class SystemVersion(Resource): """Get system version from uname""" @@ -121,5 +148,6 @@ class PythonVersion(Resource): api.add_resource(RebuildSystem, "/configuration/apply") api.add_resource(RollbackSystem, "/configuration/rollback") api.add_resource(UpgradeSystem, "/configuration/upgrade") +api.add_resource(RebootSystem, "/reboot") api.add_resource(SystemVersion, "/version") api.add_resource(PythonVersion, "/pythonVersion")