chg: Improve scripts controller

pull/937/head
Raphaël Vinot 2024-08-07 16:36:38 +02:00
parent 223c57635e
commit 42eefef512
1 changed files with 10 additions and 12 deletions

View File

@ -32,17 +32,15 @@ def main() -> None:
except FileNotFoundError: except FileNotFoundError:
print('Redis is down.') print('Redis is down.')
else: else:
if args.action == 'restart': # we need to keep the cmdline for the restart
# we need to keep the cmdline for the restart # And if it doesn't exist, we want to inform the user.
try: for name, numbers, pids in AbstractManager.is_running():
running_services = AbstractManager.is_running() if name == args.script:
except KeyError: to_restart = _get_cmdline(pids.pop())
print(f'{args.script} is not running.') break
return else:
for name, numbers, pids in running_services: print(f'{args.script} is not running or does not exists.')
if name == args.script: to_restart = []
to_restart = _get_cmdline(pids.pop())
break
print(f'Request {args.script} to {args.action}...') print(f'Request {args.script} to {args.action}...')
r = Redis(unix_socket_path=get_socket_path('cache'), db=1) r = Redis(unix_socket_path=get_socket_path('cache'), db=1)
@ -53,7 +51,7 @@ def main() -> None:
print('done.') print('done.')
r.srem('shutdown_manual', args.script) r.srem('shutdown_manual', args.script)
if args.action == 'restart': if args.action == 'restart' and to_restart:
print(f'Start {args.script}...') print(f'Start {args.script}...')
Popen(to_restart) Popen(to_restart)
print('done.') print('done.')