Update node_exporter_manager.py
This commit is contained in:
@@ -189,9 +189,15 @@ def setup():
|
|||||||
source_path = Path(__file__).resolve()
|
source_path = Path(__file__).resolve()
|
||||||
target_path = Path('/usr/local/bin/node_exporter_manager.py')
|
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)
|
shutil.copy(source_path, target_path)
|
||||||
target_path.chmod(0o755)
|
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"
|
cron_line = f"15 3 * * * {target_path} --update >> /var/log/node_exporter_cron.log 2>&1"
|
||||||
try:
|
try:
|
||||||
@@ -200,9 +206,15 @@ def setup():
|
|||||||
cron_result = ""
|
cron_result = ""
|
||||||
if cron_line not in cron_result:
|
if cron_line not in cron_result:
|
||||||
with open('/tmp/node_exporter_cron', 'w') as f:
|
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'])
|
run_cmd(['crontab', '/tmp/node_exporter_cron'])
|
||||||
os.remove('/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_path = '/etc/logrotate.d/node_exporter_manager'
|
||||||
logrotate_config = f"""{LOG_FILE} /var/log/node_exporter_cron.log {{
|
logrotate_config = f"""{LOG_FILE} /var/log/node_exporter_cron.log {{
|
||||||
@@ -216,6 +228,9 @@ def setup():
|
|||||||
"""
|
"""
|
||||||
with open(logrotate_path, 'w') as f:
|
with open(logrotate_path, 'w') as f:
|
||||||
f.write(logrotate_config)
|
f.write(logrotate_config)
|
||||||
|
logging.info("Skonfigurowano logrotate")
|
||||||
|
print(f"✅ Logrotate dodany w {logrotate_path}")
|
||||||
|
|
||||||
|
|
||||||
# ------------------ ZABEZPIECZENIA ------------------
|
# ------------------ ZABEZPIECZENIA ------------------
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user