[Rspamd] Echo dummy for fowardingshosts map; Use higher map reading interval;

[Dockerapi] Exit on sigterm;
[Watchdog] Wait for dockerapi-mailcow to be online
master
André 2017-10-27 11:22:39 +02:00
parent fe2bd9779b
commit 1e9bc49f2c
5 changed files with 88 additions and 45 deletions

View File

@ -1,62 +1,85 @@
from flask import Flask from flask import Flask
from flask_restful import Resource, Api from flask_restful import Resource, Api
from flask import jsonify from flask import jsonify
from threading import Thread
import docker import docker
import signal
import time
docker_client = docker.DockerClient(base_url='unix://var/run/docker.sock') docker_client = docker.DockerClient(base_url='unix://var/run/docker.sock')
app = Flask(__name__) app = Flask(__name__)
api = Api(app) api = Api(app)
class containers_get(Resource): class containers_get(Resource):
def get(self): def get(self):
containers = {} containers = {}
for container in docker_client.containers.list(all=True): for container in docker_client.containers.list(all=True):
containers.update({container.attrs['Id']: container.attrs}) containers.update({container.attrs['Id']: container.attrs})
return containers return containers
class container_get(Resource): class container_get(Resource):
def get(self, container_id): def get(self, container_id):
if container_id and container_id.isalnum(): if container_id and container_id.isalnum():
for container in docker_client.containers.list(all=True, filters={"id": container_id}): for container in docker_client.containers.list(all=True, filters={"id": container_id}):
return container.attrs return container.attrs
else: else:
return jsonify(message='No or invalid id defined') return jsonify(message='No or invalid id defined')
class container_post(Resource): class container_post(Resource):
def post(self, container_id, post_action): def post(self, container_id, post_action):
if container_id and container_id.isalnum() and post_action: if container_id and container_id.isalnum() and post_action:
if post_action == 'stop': if post_action == 'stop':
try: try:
for container in docker_client.containers.list(all=True, filters={"id": container_id}): for container in docker_client.containers.list(all=True, filters={"id": container_id}):
container.stop() container.stop()
except: except:
return 'Error' return 'Error'
else:
return 'OK'
elif post_action == 'start':
try:
for container in docker_client.containers.list(all=True, filters={"id": container_id}):
container.start()
except:
return 'Error'
else:
return 'OK'
elif post_action == 'restart':
try:
for container in docker_client.containers.list(all=True, filters={"id": container_id}):
container.restart()
except:
return 'Error'
else:
return 'OK'
else:
return jsonify(message='Invalid action')
else: else:
return jsonify(message='Invalid container id or missing action') return 'OK'
elif post_action == 'start':
try:
for container in docker_client.containers.list(all=True, filters={"id": container_id}):
container.start()
except:
return 'Error'
else:
return 'OK'
elif post_action == 'restart':
try:
for container in docker_client.containers.list(all=True, filters={"id": container_id}):
container.restart()
except:
return 'Error'
else:
return 'OK'
else:
return jsonify(message='Invalid action')
else:
return jsonify(message='Invalid container id or missing action')
class GracefulKiller:
kill_now = False
def __init__(self):
signal.signal(signal.SIGINT, self.exit_gracefully)
signal.signal(signal.SIGTERM, self.exit_gracefully)
def exit_gracefully(self,signum, frame):
self.kill_now = True
def startFlaskAPI():
app.run(debug=False, host='0.0.0.0', port='8080', threaded=True)
api.add_resource(containers_get, '/containers/json') api.add_resource(containers_get, '/containers/json')
api.add_resource(container_get, '/containers/<string:container_id>/json') api.add_resource(container_get, '/containers/<string:container_id>/json')
api.add_resource(container_post, '/containers/<string:container_id>/<string:post_action>') api.add_resource(container_post, '/containers/<string:container_id>/<string:post_action>')
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=False, host='0.0.0.0', port='8080') api_thread = Thread(target=startFlaskAPI)
api_thread.daemon = True
api_thread.start()
killer = GracefulKiller()
while True:
time.sleep(1)
if killer.kill_now:
break
print "Stopping dockerapi-mailcow"

View File

@ -360,6 +360,22 @@ while true; do
done done
) & ) &
# Monitor dockerapi
(
while true; do
while nc -z dockerapi 8080; do
sleep 3
done
echo "Cannot find dockerapi-mailcow, waiting to recover..."
kill -STOP ${BACKGROUND_TASKS[*]}
until nc -z dockerapi 8080; do
sleep 3
done
kill -CONT ${BACKGROUND_TASKS[*]}
kill -USR1 ${BACKGROUND_TASKS[*]}
done
) &
# Restart container when threshold limit reached # Restart container when threshold limit reached
while true; do while true; do
CONTAINER_ID= CONTAINER_ID=

View File

@ -44,11 +44,13 @@ if (isset($_GET['host'])) {
} }
} else { } else {
try { try {
echo '240.240.240.240' . PHP_EOL;
foreach ($redis->hGetAll('WHITELISTED_FWD_HOST') as $host => $source) { foreach ($redis->hGetAll('WHITELISTED_FWD_HOST') as $host => $source) {
echo $host . "\n"; echo $host . PHP_EOL;
} }
} }
catch (RedisException $e) { catch (RedisException $e) {
echo '240.240.240.240' . PHP_EOL;
exit; exit;
} }
} }

View File

@ -1,7 +1,7 @@
dns { dns {
enable_dnssec = true; enable_dnssec = true;
} }
map_watch_interval = 15s; map_watch_interval = 60s;
dns { dns {
timeout = 4s; timeout = 4s;
retransmits = 5; retransmits = 5;

View File

@ -215,12 +215,14 @@ services:
depends_on: depends_on:
- sogo-mailcow - sogo-mailcow
- php-fpm-mailcow - php-fpm-mailcow
- redis-mailcow
image: nginx:mainline-alpine image: nginx:mainline-alpine
command: /bin/sh -c "envsubst < /etc/nginx/conf.d/templates/listen_plain.template > /etc/nginx/conf.d/listen_plain.active && command: /bin/sh -c "envsubst < /etc/nginx/conf.d/templates/listen_plain.template > /etc/nginx/conf.d/listen_plain.active &&
envsubst < /etc/nginx/conf.d/templates/listen_ssl.template > /etc/nginx/conf.d/listen_ssl.active && envsubst < /etc/nginx/conf.d/templates/listen_ssl.template > /etc/nginx/conf.d/listen_ssl.active &&
envsubst < /etc/nginx/conf.d/templates/server_name.template > /etc/nginx/conf.d/server_name.active && envsubst < /etc/nginx/conf.d/templates/server_name.template > /etc/nginx/conf.d/server_name.active &&
nginx -qt && nginx -qt &&
until ping phpfpm -c1 > /dev/null; do sleep 1; done && until ping phpfpm -c1 > /dev/null; do sleep 1; done &&
until ping redis -c1 > /dev/null; do sleep 1; done &&
exec nginx -g 'daemon off;'" exec nginx -g 'daemon off;'"
environment: environment:
- HTTPS_PORT=${HTTPS_PORT:-443} - HTTPS_PORT=${HTTPS_PORT:-443}
@ -291,7 +293,7 @@ services:
- /lib/modules:/lib/modules:ro - /lib/modules:/lib/modules:ro
watchdog-mailcow: watchdog-mailcow:
image: mailcow/watchdog:1.8 image: mailcow/watchdog:1.9
build: ./data/Dockerfiles/watchdog build: ./data/Dockerfiles/watchdog
volumes: volumes:
- vmail-vol-1:/vmail:ro - vmail-vol-1:/vmail:ro
@ -310,7 +312,7 @@ services:
- watchdog - watchdog
dockerapi-mailcow: dockerapi-mailcow:
image: mailcow/dockerapi:1.0 image: mailcow/dockerapi:1.1
stop_grace_period: 3s stop_grace_period: 3s
build: ./data/Dockerfiles/dockerapi build: ./data/Dockerfiles/dockerapi
volumes: volumes: