Add system reboot and shutdown controls

This commit is contained in:
2026-11-22 18:15:02 +03:00
parent ba0ffbe89b
commit 85929c9054
3 changed files with 76 additions and 0 deletions
+19
View File
@@ -321,6 +321,24 @@ def password_change(username):
)
return 0
def system_power(action):
commands = {
'reboot': '/usr/bin/systemctl',
'poweroff': '/usr/bin/systemctl',
}
if action not in commands:
return 2
subprocess.run(
[commands[action], '--no-block', action],
check=True,
capture_output=True,
text=True,
timeout=10,
)
return 0
def main():
if len(sys.argv) != 3: return 2
action, value = sys.argv[1:]
@@ -334,6 +352,7 @@ def main():
if value not in {'yes', 'no'}: return 2
run('/usr/bin/timedatectl', 'set-ntp', 'true' if value == 'yes' else 'false'); return 0
if action == 'password-change': return password_change(value)
if action == 'system-power': return system_power(value)
if action == 'network-read': return network_read(value)
if action == 'network-status': return network_status()
if action == 'network-apply': return network_apply(value)