mynode/rootfs/standard/var/pynode/enable_disable_functions.py

41 lines
1.4 KiB
Python
Raw Normal View History

2019-06-15 23:02:44 +00:00
import os
import subprocess
2021-04-25 19:25:49 +00:00
from werkzeug.routing import RequestRedirect
2019-06-15 23:02:44 +00:00
from config import *
2020-10-08 02:59:44 +00:00
from systemctl_info import *
# Generic Enable / Disable Function
def enable_service(short_name):
os.system("systemctl enable {} --no-pager".format(short_name))
os.system("systemctl start {} --no-pager".format(short_name))
open("/mnt/hdd/mynode/settings/{}_enabled".format(short_name), 'a').close() # touch file
clear_service_enabled_cache()
2021-04-25 19:25:49 +00:00
enable_actions(short_name)
def disable_service(short_name):
enabled_file = "/mnt/hdd/mynode/settings/{}_enabled".format(short_name)
if os.path.isfile(enabled_file):
os.remove(enabled_file)
disable_actions(short_name)
os.system("systemctl stop {} --no-pager".format(short_name))
os.system("systemctl disable {} --no-pager".format(short_name))
clear_service_enabled_cache()
# Functions to handle special enable/disable cases
def enable_actions(short_name):
pass
def disable_actions(short_name):
if short_name == "electrs":
# Hard kill since we are disabling
os.system("killall -9 electrs")
if short_name == "vpn":
# Disable OpenVPN as well
os.system("systemctl stop openvpn --no-pager")
os.system("systemctl disable openvpn --no-pager")
2021-04-25 19:25:49 +00:00
# Function to restart service
def restart_service(short_name):
os.system("systemctl restart {} --no-pager".format(short_name))