2022-10-08 15:55:40 +02:00
|
|
|
#!/usr/bin/env python3
|
2017-11-10 15:48:13 +02:00
|
|
|
|
|
|
|
import os
|
|
|
|
import glob
|
2019-01-07 23:49:10 +02:00
|
|
|
import logging as log
|
2022-10-27 10:51:45 +02:00
|
|
|
import requests
|
2023-03-09 10:21:45 +02:00
|
|
|
import shutil
|
2019-01-07 23:49:10 +02:00
|
|
|
import sys
|
2022-10-27 10:51:45 +02:00
|
|
|
import time
|
2022-12-08 13:46:31 +02:00
|
|
|
from socrate import system,conf
|
2017-11-10 15:48:13 +02:00
|
|
|
|
2022-12-08 13:46:31 +02:00
|
|
|
system.set_env()
|
2019-01-07 23:49:10 +02:00
|
|
|
|
|
|
|
# Actual startup script
|
2019-05-07 11:42:08 +02:00
|
|
|
|
2023-03-09 10:21:45 +02:00
|
|
|
config_files = []
|
2017-11-10 15:48:13 +02:00
|
|
|
for rspamd_file in glob.glob("/conf/*"):
|
2019-07-25 10:33:57 +02:00
|
|
|
conf.jinja(rspamd_file, os.environ, os.path.join("/etc/rspamd/local.d", os.path.basename(rspamd_file)))
|
2023-03-09 10:21:45 +02:00
|
|
|
config_files.append(os.path.basename(rspamd_file))
|
|
|
|
|
|
|
|
for override_file in glob.glob("/overrides/*"):
|
|
|
|
if os.path.basename(override_file) not in config_files:
|
|
|
|
shutil.copyfile(override_file, os.path.join("/etc/rspamd/local.d", os.path.basename(override_file)))
|
2017-11-10 15:48:13 +02:00
|
|
|
|
2022-10-27 10:51:45 +02:00
|
|
|
# Admin may not be up just yet
|
|
|
|
healthcheck = f'http://{os.environ["ADMIN_ADDRESS"]}/internal/rspamd/local_domains'
|
|
|
|
while True:
|
|
|
|
time.sleep(1)
|
|
|
|
try:
|
|
|
|
if requests.get(healthcheck,timeout=2).ok:
|
|
|
|
break
|
|
|
|
except:
|
|
|
|
pass
|
2022-10-28 18:28:31 +02:00
|
|
|
log.warning("Admin is not up just yet, retrying in 1 second")
|
2022-10-27 10:51:45 +02:00
|
|
|
|
2017-11-10 15:48:13 +02:00
|
|
|
# Run rspamd
|
2022-11-17 19:09:00 +02:00
|
|
|
os.system("mkdir -m 755 -p /run/rspamd")
|
|
|
|
os.system("chown rspamd:rspamd /run/rspamd")
|
2022-11-21 19:12:11 +02:00
|
|
|
os.system("find /var/lib/rspamd | grep -v /filter | xargs -n1 chown rspamd:rspamd")
|
2022-11-17 19:09:00 +02:00
|
|
|
os.execv("/usr/sbin/rspamd", ["rspamd", "-f", "-u", "rspamd", "-g", "rspamd"])
|