-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinux_golinks_stop.py
40 lines (34 loc) · 1.22 KB
/
linux_golinks_stop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
import os
import sys
import subprocess
def run_command(cmd):
try:
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"Error running command {' '.join(cmd)}: {e}")
sys.exit(1)
def stop_service():
print("Stopping GoLinks service...")
service_path = "/etc/systemd/system/golinks.service"
try:
if os.path.exists(service_path):
run_command(["sudo", "systemctl", "stop", "golinks"])
run_command(["sudo", "systemctl", "disable", "golinks"])
run_command(["sudo", "rm", service_path])
run_command(["sudo", "systemctl", "daemon-reload"])
print("Service stopped and removed successfully")
else:
print("Service is not installed")
except Exception as e:
print(f"Error stopping service: {e}")
sys.exit(1)
def main():
if os.geteuid() != 0:
print("This script requires sudo privileges to stop the service.")
print("Please run: sudo python3 linux_golinks_stop.py")
sys.exit(1)
stop_service()
print("\nGoLinks service has been stopped. You can restart it using golinks.py --start")
if __name__ == "__main__":
main()