From acad1bd9472389effadd0ef109d7da9d795f8f85 Mon Sep 17 00:00:00 2001 From: Shuai Lin Date: Wed, 16 Nov 2016 15:41:08 +0800 Subject: [PATCH] Add cron for renewal of letsencrypt certs --- scripts/bootstrap.py | 24 +++++++++++++++++++++++- templates/Dockerfile.template | 9 +++++---- templates/letsencrypt.cron.template | 3 +++ 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 templates/letsencrypt.cron.template diff --git a/scripts/bootstrap.py b/scripts/bootstrap.py index 6912d34..1a695d3 100755 --- a/scripts/bootstrap.py +++ b/scripts/bootstrap.py @@ -13,6 +13,7 @@ from os.path import abspath, basename, exists, dirname, join, isdir import shutil import sys import uuid +import time from utils import call, get_conf, get_install_dir, get_script, render_template, get_seafile_version @@ -44,7 +45,21 @@ def init_letsencrypt(): 'https': True, 'domain': domain, } - render_template('/templates/seafile.nginx.conf.template', join(generated_dir, 'seafile.nginx.conf'), context) + render_template( + '/templates/seafile.nginx.conf.template', + join(generated_dir, 'seafile.nginx.conf'), + context + ) + + context = { + 'ssl_dir': ssl_dir, + 'domain': domain, + } + render_template( + '/templates/letsencrypt.cron.template', + join(generated_dir, 'letsencrypt.cron'), + context + ) def is_https(): return get_conf('server.https', '').lower() == 'true' @@ -89,6 +104,13 @@ def main(): if is_https(): init_letsencrypt() + init_seafile_server() + +def init_seafile_server(): + if exists(join(shared_seafiledir, 'seafile-data')): + print 'Skipping running setup-seafile-mysql.py because there is existing seafile-data folder.' + return + env = { 'SERVER_NAME': 'seafile', 'SERVER_IP': get_conf('server.hostname'), diff --git a/templates/Dockerfile.template b/templates/Dockerfile.template index 37b070a..1f3d6ef 100644 --- a/templates/Dockerfile.template +++ b/templates/Dockerfile.template @@ -6,13 +6,14 @@ ADD scripts /scripts ADD bootstrap /bootstrap -# This can be removed for seafile server 6.0.6 and later +{%- if seafile_version <= '6.0.6' %} ADD scripts/tmp/check_init_admin.py /opt/seafile/seafile-server-{{ seafile_version }}/check_init_admin.py +{%- endif %} ADD bootstrap/generated/seafile.nginx.conf /etc/nginx/sites-enabled/seafile.nginx.conf -{% if https -%} -# TODO: add a cron job to renew letsencrypt -{% endif -%} +{%- if https %} +ADD bootstrap/generated/letsencrypt.cron /etc/cron.d/letsencrypt.cron +{%- endif %} CMD ["/sbin/my_init", "--", "/scripts/start.py"] diff --git a/templates/letsencrypt.cron.template b/templates/letsencrypt.cron.template new file mode 100644 index 0000000..3f53864 --- /dev/null +++ b/templates/letsencrypt.cron.template @@ -0,0 +1,3 @@ +PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +# m h dom mon dow command +0 0 1 * * root /scripts/ssl.sh {{ ssl_dir }} {{ domain }}