From 84f6482cc561408195b5635012b68c2f569579df Mon Sep 17 00:00:00 2001 From: Zuinige Rijder Date: Mon, 14 Oct 2024 15:01:13 +0200 Subject: [PATCH] Major update: introduction of running monitor.py infinitely --- logging_config.ini | 21 +++++++++++++++++++++ run_monitor_infinite.sh | 23 +++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 logging_config.ini create mode 100644 run_monitor_infinite.sh diff --git a/logging_config.ini b/logging_config.ini new file mode 100644 index 0000000..bb99740 --- /dev/null +++ b/logging_config.ini @@ -0,0 +1,21 @@ +[loggers] +keys=root + +[handlers] +keys=stdout + +[formatters] +keys=simpleFormatter + +[logger_root] +level=INFO +handlers=stdout + +[handler_stdout] +class=StreamHandler +formatter=simpleFormatter +args=(sys.stdout,) + +[formatter_simpleFormatter] +format=%(asctime)s: %(levelname)s: %(message)s +datefmt=%Y%m%d %H:%M:%S diff --git a/run_monitor_infinite.sh b/run_monitor_infinite.sh new file mode 100644 index 0000000..c98de49 --- /dev/null +++ b/run_monitor_infinite.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# --------------------------------------------------------------- +# A script to run monitor infinite. +# if still running, do not start new one +# Assumption is that monitor.cfg is configured to run infinite (monitor_infinite = True) and +# monitor_execute_commands_when_something_written_or_error is configured to run summary.py and/or dailystats.py, e.g. +# monitor_execute_commands_when_something_written_or_error = python -u summary.py sheetupdate > summary.log;python -u dailystats.py sheetupdate > dailystats.log +# Add to your crontab to run once per hour to restart after crashes or reboot +# 0 * * * * ~/hyundai_kia_connect_monitor/run_monitor_infinite.sh >> ~/hyundai_kia_connect_monitor/crontab_run_monitor_infinite.log 2>&1 +# --------------------------------------------------------------- +script_name=$(basename -- "$0") +cd ~/hyundai_kia_connect_monitor + +now=$(date) +if pidof -x "$script_name" -o $$ >/dev/null +then + echo "$now: $script_name still running" +else + echo "$now: starting $script_name" >> run_monitor_infinite.log + /usr/bin/python -u ~/hyundai_kia_connect_monitor/monitor.py >> run_monitor_infinite.log 2>&1 + now=$(date) + echo "$now: $script_name exited" >> run_monitor_infinite.log +fi