make scheduler integrations optional
This commit is contained in:
@@ -24,6 +24,8 @@ services:
|
|||||||
HA_TOKEN: ${HA_TOKEN:?set HA_TOKEN}
|
HA_TOKEN: ${HA_TOKEN:?set HA_TOKEN}
|
||||||
OPENWEATHER_API_KEY: ${OPENWEATHER_API_KEY:?set OPENWEATHER_API_KEY}
|
OPENWEATHER_API_KEY: ${OPENWEATHER_API_KEY:?set OPENWEATHER_API_KEY}
|
||||||
CKAL_XLSX_DIR: /data/ckal-xlsx
|
CKAL_XLSX_DIR: /data/ckal-xlsx
|
||||||
|
STRATO_SYNC_ENABLED: ${STRATO_SYNC_ENABLED:-true}
|
||||||
|
BRANDSCHUTZ_MAIL_ENABLED: ${BRANDSCHUTZ_MAIL_ENABLED:-true}
|
||||||
volumes:
|
volumes:
|
||||||
- profile_pictures:/var/www/html/intranet_repo/general_files/profile_pictures
|
- profile_pictures:/var/www/html/intranet_repo/general_files/profile_pictures
|
||||||
- content_news:/var/www/html/intranet_repo/projects/contentpanel/insertion/news
|
- content_news:/var/www/html/intranet_repo/projects/contentpanel/insertion/news
|
||||||
|
|||||||
+69
-10
@@ -37,23 +37,65 @@ def prepare_ssh_key() -> Path:
|
|||||||
|
|
||||||
|
|
||||||
def calendar_sync():
|
def calendar_sync():
|
||||||
run([PYTHON, str(ROOT / 'ckal_upload_client/client.py')], cwd=ROOT / 'ckal_upload_client')
|
# CKalender-XLSX verarbeiten
|
||||||
run([PYTHON, str(ROOT / 'pdf_python/create_pdf.py')], cwd=ROOT / 'pdf_python')
|
run(
|
||||||
run(['/bin/bash', str(ROOT / 'pdf_python/pdf_to_png.sh')], cwd=ROOT / 'pdf_python')
|
[PYTHON, str(ROOT / 'ckal_upload_client/client.py')],
|
||||||
|
cwd=ROOT / 'ckal_upload_client'
|
||||||
|
)
|
||||||
|
|
||||||
|
# PDF erzeugen
|
||||||
|
run(
|
||||||
|
[PYTHON, str(ROOT / 'pdf_python/create_pdf.py')],
|
||||||
|
cwd=ROOT / 'pdf_python'
|
||||||
|
)
|
||||||
|
|
||||||
|
# PDF in Dashboard-PNGs umwandeln
|
||||||
|
run(
|
||||||
|
['/bin/bash', str(ROOT / 'pdf_python/pdf_to_png.sh')],
|
||||||
|
cwd=ROOT / 'pdf_python'
|
||||||
|
)
|
||||||
|
|
||||||
|
# STRATO-Synchronisation kann z. B. im DEV deaktiviert werden
|
||||||
|
strato_sync_enabled = os.getenv(
|
||||||
|
'STRATO_SYNC_ENABLED',
|
||||||
|
'true'
|
||||||
|
).strip().lower() in ('1', 'true', 'yes', 'on')
|
||||||
|
|
||||||
|
if not strato_sync_enabled:
|
||||||
|
print('STRATO Sync deaktiviert', flush=True)
|
||||||
|
print('Calendar Sync erfolgreich (ohne STRATO)', flush=True)
|
||||||
|
return
|
||||||
|
|
||||||
required('STRATO_SSH_USER')
|
required('STRATO_SSH_USER')
|
||||||
required('STRATO_REMOTE_PATH')
|
required('STRATO_REMOTE_PATH')
|
||||||
|
|
||||||
host = os.getenv('STRATO_SSH_HOST', 'ssh.strato.de')
|
host = os.getenv('STRATO_SSH_HOST', 'ssh.strato.de')
|
||||||
port = os.getenv('STRATO_SSH_PORT', '22')
|
port = os.getenv('STRATO_SSH_PORT', '22')
|
||||||
known_hosts = Path(os.getenv('STRATO_KNOWN_HOSTS_FILE', '/run/secrets/known_hosts'))
|
|
||||||
|
known_hosts = Path(
|
||||||
|
os.getenv(
|
||||||
|
'STRATO_KNOWN_HOSTS_FILE',
|
||||||
|
'/run/secrets/known_hosts'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if not known_hosts.is_file():
|
if not known_hosts.is_file():
|
||||||
raise RuntimeError(f'known_hosts missing: {known_hosts}')
|
raise RuntimeError(
|
||||||
|
f'known_hosts missing: {known_hosts}'
|
||||||
|
)
|
||||||
|
|
||||||
key = prepare_ssh_key()
|
key = prepare_ssh_key()
|
||||||
|
|
||||||
if not PDF_OUTPUT.is_file() or PDF_OUTPUT.stat().st_size == 0:
|
if not PDF_OUTPUT.is_file() or PDF_OUTPUT.stat().st_size == 0:
|
||||||
raise RuntimeError(f'PDF missing/empty: {PDF_OUTPUT}')
|
raise RuntimeError(
|
||||||
|
f'PDF missing/empty: {PDF_OUTPUT}'
|
||||||
|
)
|
||||||
|
|
||||||
run([
|
run([
|
||||||
'/usr/bin/scp', '-O', '-q', '-P', port,
|
'/usr/bin/scp',
|
||||||
|
'-O',
|
||||||
|
'-q',
|
||||||
|
'-P', port,
|
||||||
'-i', str(key),
|
'-i', str(key),
|
||||||
'-o', 'IdentitiesOnly=yes',
|
'-o', 'IdentitiesOnly=yes',
|
||||||
'-o', 'BatchMode=yes',
|
'-o', 'BatchMode=yes',
|
||||||
@@ -62,24 +104,41 @@ def calendar_sync():
|
|||||||
str(PDF_OUTPUT),
|
str(PDF_OUTPUT),
|
||||||
f"{required('STRATO_SSH_USER')}@{host}:{required('STRATO_REMOTE_PATH')}",
|
f"{required('STRATO_SSH_USER')}@{host}:{required('STRATO_REMOTE_PATH')}",
|
||||||
])
|
])
|
||||||
|
|
||||||
print('Calendar Sync erfolgreich', flush=True)
|
print('Calendar Sync erfolgreich', flush=True)
|
||||||
|
|
||||||
|
|
||||||
def brandschutz_once_per_month():
|
def brandschutz_once_per_month():
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
|
|
||||||
if now.day != 1 or now.hour < 8:
|
if now.day != 1 or now.hour < 8:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
brandschutz_enabled = os.getenv(
|
||||||
|
'BRANDSCHUTZ_MAIL_ENABLED',
|
||||||
|
'true'
|
||||||
|
).strip().lower() in ('1', 'true', 'yes', 'on')
|
||||||
|
|
||||||
|
if not brandschutz_enabled:
|
||||||
|
print('Brandschutz-Mail deaktiviert', flush=True)
|
||||||
|
return
|
||||||
|
|
||||||
marker = STATE_DIR / 'brandschutz-last-attempt'
|
marker = STATE_DIR / 'brandschutz-last-attempt'
|
||||||
month = now.strftime('%Y-%m')
|
month = now.strftime('%Y-%m')
|
||||||
|
|
||||||
if marker.exists() and marker.read_text().strip() == month:
|
if marker.exists() and marker.read_text().strip() == month:
|
||||||
return
|
return
|
||||||
|
|
||||||
# At-most-once: erst markieren, dann ausführen. Bei Fehler manuell prüfen und Marker löschen.
|
# At-most-once: erst markieren, dann ausführen
|
||||||
marker.write_text(month + '\n')
|
marker.write_text(month + '\n')
|
||||||
print(f'Brandschutz-Lauf {month}', flush=True)
|
|
||||||
run(['/usr/local/bin/php', '/var/www/html/intranet_repo/projects/brandschutz/brandschutz_cron.php'])
|
|
||||||
|
|
||||||
|
print(f'Brandschutz-Lauf {month}', flush=True)
|
||||||
|
|
||||||
|
run([
|
||||||
|
'/usr/local/bin/php',
|
||||||
|
'/var/www/html/intranet_repo/projects/brandschutz/brandschutz_cron.php'
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
STATE_DIR.mkdir(parents=True, exist_ok=True)
|
STATE_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user