From 74cfa274a7e6bf2d19a69bd823a2c5e752678f23 Mon Sep 17 00:00:00 2001 From: gru Date: Sun, 8 Jun 2025 00:10:04 +0200 Subject: [PATCH] Update node_exporter_manager.py --- node_exporter_manager.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/node_exporter_manager.py b/node_exporter_manager.py index dbb102b..8d07767 100644 --- a/node_exporter_manager.py +++ b/node_exporter_manager.py @@ -189,9 +189,15 @@ def setup(): source_path = Path(__file__).resolve() target_path = Path('/usr/local/bin/node_exporter_manager.py') - if source_path != target_path: + if source_path == target_path: + print("ℹ️ Skrypt już działa z docelowej lokalizacji.") + elif not target_path.exists(): shutil.copy(source_path, target_path) target_path.chmod(0o755) + logging.info(f"Zainstalowano skrypt jako {target_path}") + print(f"✅ Skrypt zainstalowany w {target_path}") + else: + print(f"ℹ️ Skrypt już zainstalowany w {target_path}") cron_line = f"15 3 * * * {target_path} --update >> /var/log/node_exporter_cron.log 2>&1" try: @@ -200,9 +206,15 @@ def setup(): cron_result = "" if cron_line not in cron_result: with open('/tmp/node_exporter_cron', 'w') as f: - f.write(cron_result.strip() + '\n' + cron_line + '\n') + if cron_result.strip(): + f.write(cron_result.strip() + '\n') + f.write(cron_line + '\n') run_cmd(['crontab', '/tmp/node_exporter_cron']) os.remove('/tmp/node_exporter_cron') + logging.info("Dodano wpis do crontaba") + print("✅ Zadanie cron dodane") + else: + print("ℹ️ Wpis cron już istnieje.") logrotate_path = '/etc/logrotate.d/node_exporter_manager' logrotate_config = f"""{LOG_FILE} /var/log/node_exporter_cron.log {{ @@ -216,6 +228,9 @@ def setup(): """ with open(logrotate_path, 'w') as f: f.write(logrotate_config) + logging.info("Skonfigurowano logrotate") + print(f"✅ Logrotate dodany w {logrotate_path}") + # ------------------ ZABEZPIECZENIA ------------------