GlenNicholls / unraid_parity_scripter

Unraid user script that supports specifying Python functions to call during parity check start/stop stages
MIT License
0 stars 0 forks source link

Catch and log exceptions so script doesn't exit #1

Closed GlenNicholls closed 1 year ago

GlenNicholls commented 1 year ago

Currently, exceptions can cause the script to exit which is undesireable:

Script Starting Jun 07, 2023 13:16.48

Full logs for this script are available at /tmp/user.scripts/tmpScripts/parity_monitor/log.txt

2023-06-07 13:16:48,530 - INFO - Started monitoring parity state (main.py:55)
2023-06-07 13:16:48,530 - INFO - Checking parity state (main.py:57)
2023-06-07 13:16:48,534 - INFO - Parity check is stopped but stop functions haven't been run, calling stop functions. (monitor.py:102)
2023-06-07 13:16:48,534 - INFO - Starting container 'NginxProxyManager' (containers.py:16)
Traceback (most recent call last):
File "/mnt/user/glen/nas/scripts/unraid_parity_scripter/parity_scripter/main.py", line 68, in
run()
File "/mnt/user/glen/nas/scripts/unraid_parity_scripter/parity_scripter/main.py", line 58, in run
parity_logic(
File "/mnt/user/glen/nas/scripts/unraid_parity_scripter/parity_scripter/monitor.py", line 107, in parity_logic
func()
File "/mnt/user/glen/nas/scripts/unraid_parity_scripter/parity_scripter/main.py", line 61, in
stop_funcs=[lambda: containers.start(args.config)],
File "/mnt/user/glen/nas/scripts/unraid_parity_scripter/parity_scripter/containers.py", line 17, in start
sys_call(f"docker start {container}")
File "/mnt/user/glen/nas/scripts/unraid_parity_scripter/parity_scripter/utils.py", line 36, in sys_call
subprocess.run(shlex.split(command), capture_output=True, check=True)
File "/usr/lib64/python3.9/subprocess.py", line 528, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['docker', 'start', 'NginxProxyManager']' returned non-zero exit status 1.
Script Finished Jun 07, 2023 13:16.48

We should catch this and log the traceback.