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
|
|
|
|
2023-05-05 19:50:49 +02:00
|
|
|
env = 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/*"):
|
2023-05-05 19:50:49 +02:00
|
|
|
conf.jinja(rspamd_file, env, os.path.join("/etc/rspamd/local.d", os.path.basename(rspamd_file)))
|
2023-10-10 10:19:36 +02:00
|
|
|
if rspamd_file != '/conf/forbidden_file_extension.map':
|
|
|
|
config_files.append(os.path.basename(rspamd_file))
|
2023-03-09 10:21:45 +02:00
|
|
|
|
|
|
|
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
|
2023-08-28 11:17:25 +02:00
|
|
|
healthcheck = f'http://{env["ADMIN_ADDRESS"]}:8080/internal/rspamd/local_domains'
|
2022-10-27 10:51:45 +02:00
|
|
|
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")
|
2023-10-05 20:41:54 +02:00
|
|
|
os.execv("/usr/bin/rspamd", ["rspamd", "-f", "-u", "rspamd", "-g", "rspamd"])
|