Add colors for output.
This commit is contained in:
parent
665fbed920
commit
7f6b4f7f6a
26
service.py
26
service.py
@ -9,6 +9,12 @@ PID_FILE = Path("pid.txt")
|
||||
MAIN_SCRIPT = "main.py"
|
||||
START_DELAY = 0.3
|
||||
|
||||
# ANSI color codes
|
||||
RED = "\033[91m"
|
||||
GREEN = "\033[92m"
|
||||
YELLOW = "\033[93m"
|
||||
RESET = "\033[0m"
|
||||
|
||||
|
||||
def display_help():
|
||||
print(
|
||||
@ -47,20 +53,20 @@ def start_process():
|
||||
def cmd_status():
|
||||
pid = get_pid()
|
||||
if pid:
|
||||
print(f"[Running] PID: {pid}")
|
||||
print(f"{GREEN}[Running] PID: {pid}{RESET}")
|
||||
return 0
|
||||
print("[Stopped]")
|
||||
print(f"{RED}[Stopped]{RESET}")
|
||||
return 1
|
||||
|
||||
|
||||
def cmd_start():
|
||||
if pid := get_pid():
|
||||
print(f"Already running with PID: {pid}")
|
||||
print(f"{YELLOW}Already running with PID: {pid}{RESET}")
|
||||
return 2
|
||||
if pid := start_process():
|
||||
print(f"Started with PID: {pid}")
|
||||
print(f"{GREEN}Started with PID: {pid}{RESET}")
|
||||
return 0
|
||||
print(f"Can't get PID... Crash? | CWD: {os.getcwd()}")
|
||||
print(f"{RED}Can't get PID... Crash? | CWD: {os.getcwd()}{RESET}")
|
||||
return 1
|
||||
|
||||
|
||||
@ -68,14 +74,14 @@ def cmd_stop():
|
||||
pid = get_pid()
|
||||
clear_pid()
|
||||
if not pid:
|
||||
print(f"Process already stopped. | CWD: {os.getcwd()}")
|
||||
print(f"{YELLOW}Process already stopped. | CWD: {os.getcwd()}{RESET}")
|
||||
return 2
|
||||
try:
|
||||
os.kill(pid, signal.SIGTERM) # Graceful shutdown vs SIGKILL
|
||||
print("Process successfully stopped.")
|
||||
print(f"{GREEN}Process successfully stopped.{RESET}")
|
||||
return 0
|
||||
except ProcessLookupError:
|
||||
print(f"Process already stopped. | CWD: {os.getcwd()}")
|
||||
print(f"{YELLOW}Process already stopped. | CWD: {os.getcwd()}{RESET}")
|
||||
return 2
|
||||
|
||||
|
||||
@ -88,9 +94,9 @@ def cmd_restart():
|
||||
pass
|
||||
clear_pid()
|
||||
if pid := start_process():
|
||||
print(f"Restarted with PID: {pid}")
|
||||
print(f"{GREEN}Restarted with PID: {pid}{RESET}")
|
||||
return 0
|
||||
print(f"Can't get PID... Crash? | CWD: {os.getcwd()}")
|
||||
print(f"{RED}Can't get PID... Crash? | CWD: {os.getcwd()}{RESET}")
|
||||
return 1
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user