mirror of https://github.com/Aidaho12/haproxy-wi
v7.3.2.0: Refactor action_service method in roxy module
Refactoring of the function 'action_service' has been completed in the roxywi module. The function for different actions ('start', 'stop', and 'restart') has been replaced by a dictionary for more clean and efficient code. This change also enhances code readability and maintainability.pull/390/head v7.3.2.0
parent
508f7d4cc1
commit
45b964d341
|
@ -93,11 +93,14 @@ def update_user_status() -> None:
|
||||||
|
|
||||||
def action_service(action: str, service: str) -> str:
|
def action_service(action: str, service: str) -> str:
|
||||||
is_in_docker = is_docker()
|
is_in_docker = is_docker()
|
||||||
cmd = f"sudo systemctl disable {service} --now"
|
actions = {
|
||||||
if action in ("start", "restart"):
|
'start': 'enable --now',
|
||||||
cmd = f"sudo systemctl {action} {service} --now"
|
'stop': 'disable --now',
|
||||||
if not roxy_sql.select_user_status():
|
'restart': 'restart',
|
||||||
return 'warning: The service is disabled because you are not subscribed. Read <a href="https://roxy-wi.org/pricing" ' \
|
}
|
||||||
|
cmd = f"sudo systemctl {actions[action]} {service}"
|
||||||
|
if not roxy_sql.select_user_status():
|
||||||
|
return 'warning: The service is disabled because you are not subscribed. Read <a href="https://roxy-wi.org/pricing" ' \
|
||||||
'title="Roxy-WI pricing" target="_blank">here</a> about subscriptions'
|
'title="Roxy-WI pricing" target="_blank">here</a> about subscriptions'
|
||||||
if is_in_docker:
|
if is_in_docker:
|
||||||
cmd = f"sudo supervisorctl {action} {service}"
|
cmd = f"sudo supervisorctl {action} {service}"
|
||||||
|
|
Loading…
Reference in New Issue