Use systemd units for system rebuilds

This commit is contained in:
Inex Code 2021-11-17 12:36:26 +02:00
parent c910b761d1
commit dc56b6f4ad

View file

@ -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")