mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
actions: Add more action utilities
- Utilities for enabling, disabling, restarting and getting enabled status of a service. - Currently they are based on systemd but they can be extended to work with sysvinit also. - Enable and disable also synchronize state with sysvinit.
This commit is contained in:
parent
1d3b179f6e
commit
f2b4dca4eb
@ -1,5 +1,3 @@
|
|||||||
#!/usr/bin/python3
|
|
||||||
# -*- mode: python -*-
|
|
||||||
#
|
#
|
||||||
# This file is part of Plinth.
|
# This file is part of Plinth.
|
||||||
#
|
#
|
||||||
@ -18,7 +16,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Python action utility functions
|
Python action utility functions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -39,3 +37,29 @@ def service_is_running(servicename):
|
|||||||
running = True
|
running = True
|
||||||
break
|
break
|
||||||
return running
|
return running
|
||||||
|
|
||||||
|
|
||||||
|
def service_is_enabled(service_name):
|
||||||
|
"""Check if service is enabled in systemd."""
|
||||||
|
try:
|
||||||
|
subprocess.check_output(['systemctl', 'is-enabled', service_name])
|
||||||
|
return True
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def service_enable(service_name):
|
||||||
|
"""Enable and start a service in systemd and sysvinit using update-rc.d."""
|
||||||
|
subprocess.call(['systemctl', 'enable', service_name])
|
||||||
|
subprocess.call(['systemctl', 'start', service_name])
|
||||||
|
|
||||||
|
|
||||||
|
def service_disable(service_name):
|
||||||
|
"""Disable and stop service in systemd and sysvinit using update-rc.d."""
|
||||||
|
subprocess.call(['systemctl', 'stop', service_name])
|
||||||
|
subprocess.call(['systemctl', 'disable', service_name])
|
||||||
|
|
||||||
|
|
||||||
|
def service_restart(service_name):
|
||||||
|
"""Restart service with systemd."""
|
||||||
|
subprocess.call(['systemctl', 'restart', service_name])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user