From 097879e1fb855d4223fcce3ad359a2f9ec81d835 Mon Sep 17 00:00:00 2001 From: Abhishek Balam Date: Tue, 8 Sep 2020 12:58:56 +0530 Subject: [PATCH] feat: patch for older setups with wrong cron format --- .../v5/fix_letsencrypt_renew_frequency.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 bench/patches/v5/fix_letsencrypt_renew_frequency.py diff --git a/bench/patches/v5/fix_letsencrypt_renew_frequency.py b/bench/patches/v5/fix_letsencrypt_renew_frequency.py new file mode 100644 index 00000000..eda219ba --- /dev/null +++ b/bench/patches/v5/fix_letsencrypt_renew_frequency.py @@ -0,0 +1,19 @@ +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 --force-renewal -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 on every day-of-month 1 + system_crontab.write() + break