From 24275449725cde29cc153dbec9dead230d46b491 Mon Sep 17 00:00:00 2001 From: kaiyou Date: Wed, 8 Nov 2017 09:39:34 +0100 Subject: [PATCH] Move statistics to the start.sh script for clarity --- core/admin/mailu/__init__.py | 14 -------------- core/admin/manage.py | 24 +++++++++++++++++++++++- core/admin/start.sh | 1 + 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/core/admin/mailu/__init__.py b/core/admin/mailu/__init__.py index f34a75f1..96d880a1 100644 --- a/core/admin/mailu/__init__.py +++ b/core/admin/mailu/__init__.py @@ -55,20 +55,6 @@ db = flask_sqlalchemy.SQLAlchemy(app) migrate = flask_migrate.Migrate(app, db) limiter = flask_limiter.Limiter(app, key_func=lambda: current_user.username) -# Run statistics -if os.path.isfile(app.config["INSTANCE_ID_PATH"]): - with open(app.config["INSTANCE_ID_PATH"], "r") as handle: - instance_id = handle.read() -else: - instance_id = str(uuid.uuid4()) - with open(app.config["INSTANCE_ID_PATH"], "w") as handle: - handle.write(instance_id) -if app.config["DISABLE_STATISTICS"].lower() != "true": - try: - socket.gethostbyname(app.config["STATS_ENDPOINT"].format(instance_id)) - except: - pass - # Debugging toolbar if app.config.get("DEBUG"): import flask_debugtoolbar diff --git a/core/admin/manage.py b/core/admin/manage.py index a8128f4e..f7e9e17d 100644 --- a/core/admin/manage.py +++ b/core/admin/manage.py @@ -1,5 +1,27 @@ from mailu import app, manager, db, models +import os +import socket +import uuid + + +@manager.command +def advertise(): + """ Advertise this server against statistic services. + """ + if os.path.isfile(app.config["INSTANCE_ID_PATH"]): + with open(app.config["INSTANCE_ID_PATH"], "r") as handle: + instance_id = handle.read() + else: + instance_id = str(uuid.uuid4()) + with open(app.config["INSTANCE_ID_PATH"], "w") as handle: + handle.write(instance_id) + if app.config["DISABLE_STATISTICS"].lower() != "true": + try: + socket.gethostbyname(app.config["STATS_ENDPOINT"].format(instance_id)) + except: + pass + @manager.command def admin(localpart, domain_name, password): @@ -51,7 +73,7 @@ def domain(domain_name, max_users=0, max_aliases=0, max_quota_bytes=0): @manager.command -def user_import(localpart, domain_name, password_hash, +def user_import(localpart, domain_name, password_hash, hash_scheme=app.config['PASSWORD_SCHEME']): """ Import a user along with password hash. Available hashes: 'SHA512-CRYPT' diff --git a/core/admin/start.sh b/core/admin/start.sh index afe276be..2a899bb7 100755 --- a/core/admin/start.sh +++ b/core/admin/start.sh @@ -1,4 +1,5 @@ #!/bin/sh +python manage.py advertise python manage.py db upgrade gunicorn -w 4 -b 0.0.0.0:80 --access-logfile - --error-logfile - --preload mailu:app