Refactor: Implement Hysteria server restart in Python
This commit is contained in:
34
core/scripts/hysteria2/restart.py
Normal file
34
core/scripts/hysteria2/restart.py
Normal file
@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
from init_paths import *
|
||||
from paths import *
|
||||
|
||||
def restart_hysteria_server():
|
||||
"""
|
||||
Restarts the Hysteria server service.
|
||||
|
||||
Returns:
|
||||
int: 0 on success, 1 on failure.
|
||||
"""
|
||||
try:
|
||||
subprocess.run([sys.executable, CLI_PATH, "traffic-status"], check=False, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
|
||||
subprocess.run(["systemctl", "restart", "hysteria-server.service"], check=True)
|
||||
print("Hysteria server restarted successfully.")
|
||||
return 0
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Error: Failed to restart the Hysteria server.")
|
||||
return 1
|
||||
except FileNotFoundError:
|
||||
print(f"Error: CLI script not found at {CLI_PATH}.")
|
||||
return 1
|
||||
except Exception as e:
|
||||
print(f"An unexpected error occurred: {e}")
|
||||
return 1
|
||||
|
||||
if __name__ == "__main__":
|
||||
exit_code = restart_hysteria_server()
|
||||
sys.exit(exit_code)
|
||||
@ -1,8 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
python3 /etc/hysteria/core/cli.py traffic-status > /dev/null 2>&1
|
||||
if systemctl restart hysteria-server.service; then
|
||||
echo "Hysteria server restarted successfully."
|
||||
else
|
||||
echo "Error: Failed to restart the Hysteria server."
|
||||
fi
|
||||
Reference in New Issue
Block a user