diff --git a/bench/config/lets_encrypt.py b/bench/config/lets_encrypt.py index bea1b86b..2615784d 100755 --- a/bench/config/lets_encrypt.py +++ b/bench/config/lets_encrypt.py @@ -87,11 +87,15 @@ def run_certbot_and_setup_ssl(site, custom_domain, bench_path, interactive=True) def setup_crontab(): job_command = '/opt/certbot-auto renew -a nginx --post-hook "systemctl reload nginx"' + job_comment = 'Renew lets-encrypt every month' system_crontab = CronTab(user='root') - if job_command not in str(system_crontab): - job = system_crontab.new(command=job_command, comment="Renew lets-encrypt every month") - job.setall('0 0 */1 * *') # Run at 00:00 every day-of-month - system_crontab.write() + + for job in system_crontab.find_comment(comment=job_comment): # Removes older entries + system_crontab.remove(job) + + job = system_crontab.new(command=job_command, comment=job_comment) + job.setall('0 0 */1 * *') # Run at 00:00 every day-of-month + system_crontab.write() def create_dir_if_missing(path): @@ -113,10 +117,13 @@ def get_certbot_path(): def renew_certs(): + # Needs to be run with sudo click.confirm('Running this will stop the nginx service temporarily causing your sites to go offline\n' 'Do you want to continue?', abort=True) + setup_crontab() + service('nginx', 'stop') exec_cmd("{path} renew".format(path=get_certbot_path())) service('nginx', 'start') diff --git a/bench/patches/v5/fix_letsencrypt_renew_frequency.py b/bench/patches/v5/fix_letsencrypt_renew_frequency.py deleted file mode 100644 index 73806c54..00000000 --- a/bench/patches/v5/fix_letsencrypt_renew_frequency.py +++ /dev/null @@ -1,19 +0,0 @@ -from bench.config.common_site_config import get_config -from crontab import CronTab - - -def execute(bench_path): - """ - This patch fixes a cron job that would renew letsencrypt certificate - """ - - job_command = '/opt/certbot-auto renew -a nginx --post-hook "systemctl reload nginx"' - system_crontab = CronTab(user='root') - job_comment = "Renew lets-encrypt every month" - - for job in system_crontab.find_comment(job_comment): - system_crontab.remove(job) - job = system_crontab.new(command=job_command, comment=job_comment) - job.setall('0 0 */1 * *') # Run at 00:00 every day-of-month - system_crontab.write() - break