2018-10-31 19:17:23 +02:00
#!/usr/bin/python3
2018-10-22 17:01:59 +02:00
import os
2019-10-08 07:29:33 +02:00
import logging as log
import sys
log . basicConfig ( stream = sys . stderr , level = os . environ . get ( " LOG_LEVEL " , " INFO " ) )
2018-10-22 17:01:59 +02:00
2018-11-08 22:43:05 +02:00
os . system ( " flask mailu advertise " )
os . system ( " flask db upgrade " )
2019-01-25 16:04:20 +02:00
2019-08-21 15:34:25 +02:00
account = os . environ . get ( " INITIAL_ADMIN_ACCOUNT " )
domain = os . environ . get ( " INITIAL_ADMIN_DOMAIN " )
password = os . environ . get ( " INITIAL_ADMIN_PW " )
if account is not None and domain is not None and password is not None :
mode = os . environ . get ( " INITIAL_ADMIN_MODE " , default = " ifmissing " )
2019-10-08 07:29:33 +02:00
log . info ( " Creating initial admin accout %s @ %s with mode %s " , account , domain , mode )
2019-08-21 15:34:25 +02:00
os . system ( " flask mailu admin %s %s ' %s ' --mode %s " % ( account , domain , password , mode ) )
2019-01-25 16:04:20 +02:00
2022-01-05 19:49:30 +02:00
def test_DNS ( ) :
import dns . resolver
import dns . exception
import dns . flags
import dns . rdtypes
import dns . rdatatype
import dns . rdataclass
import time
# DNS stub configured to do DNSSEC enabled queries
resolver = dns . resolver . Resolver ( )
2022-02-19 14:02:52 +02:00
resolver . use_edns ( 0 , dns . flags . DO , 1232 )
2022-01-05 19:49:30 +02:00
resolver . flags = dns . flags . AD | dns . flags . RD
nameservers = resolver . nameservers
for ns in nameservers :
resolver . nameservers = [ ns ]
2022-01-12 14:34:18 +02:00
while True :
2022-01-05 19:49:30 +02:00
try :
2022-01-21 15:17:37 +02:00
result = resolver . resolve ( ' example.org ' , dns . rdatatype . A , dns . rdataclass . IN , lifetime = 10 )
2022-01-05 19:49:30 +02:00
except Exception as e :
2022-02-23 12:48:53 +02:00
log . critical ( " Your DNS resolver at %s is not working ( %s ). Please see https://mailu.io/master/faq.html#the-admin-container-won-t-start-and-its-log-says-critical-your-dns-resolver-isn-t-doing-dnssec-validation " , ns , e ) ;
2022-01-12 14:34:18 +02:00
else :
2022-01-12 14:44:17 +02:00
if result . response . flags & dns . flags . AD :
break
2022-02-23 12:48:53 +02:00
log . critical ( " Your DNS resolver at %s isn ' t doing DNSSEC validation; Please see https://mailu.io/master/faq.html#the-admin-container-won-t-start-and-its-log-says-critical-your-dns-resolver-isn-t-doing-dnssec-validation. " , ns )
2022-01-05 19:49:30 +02:00
time . sleep ( 5 )
test_DNS ( )
2019-10-08 07:29:33 +02:00
start_command = " " . join ( [
2021-07-24 15:45:25 +02:00
" gunicorn --threads " , str ( os . cpu_count ( ) ) ,
" -b :80 " ,
2019-10-08 07:29:33 +02:00
" --access-logfile - " if ( log . root . level < = log . INFO ) else " " ,
" --error-logfile - " ,
" --preload " ,
" ' mailu:create_app() ' " ] )
os . system ( start_command )