Cron job for let's encrypt renewalWhy is my crontab not working, and how can I troubleshoot it?Nginx certbot cronjob not workingMX record pointing to A record with two different IP'sIntermediate certificate for Let's EncryptDifferent behaviour when running letsencrypt's certbot as a cron jobLet's Encrypt verification failureHow to use Let's Encrypt with both EC2 and Cloudfront?Let's encrypt certificate permissions for tomcat8 ubuntu serverLet's Encrypt Expiry Bot (certificate expiration notice)Let's Encrypt with dynamic subdomainsnginx load balancer w/ https and lets encrypt cert renewalHow to recreate let's encrypt certificate with public key from the past?Trying to configure letsencrypt auto renewal with HAProxy

What was the idiom for something that we take without a doubt?

How to patch glass cuts in a bicycle tire?

Is it rude to call a professor by their last name with no prefix in a non-academic setting?

Why is this Simple Puzzle impossible to solve?

What is a really good book for complex variables?

Why are C64 games inconsistent with which joystick port they use?

Compaq Portable vs IBM 5155 Portable PC

Could a 19.25mm revolver actually exist?

Any advice on creating fictional locations in real places when writing historical fiction?

C++ forcing function parameter evalution order

NIntegrate doesn't evaluate

Where's this lookout in Nova Scotia?

Is it possible to remotely hack the GPS system and disable GPS service worldwide?

In general, would I need to season a meat when making a sauce?

Teacher help me explain this to my students

Would Jetfuel for a modern jet like an F-16 or a F-35 be producable in the WW2 era?

My employer faked my resume to acquire projects

The usage of "run a mile" in a sentence

Why didn't Thanos use the Time Stone to stop the Avengers' plan?

What to keep in mind when telling an aunt how wrong her actions are, without creating further family conflict?

What is Theresa May waiting for?

How do I partition a matrx into blocks and replace zeros with dots?

I know that there is a preselected candidate for a position to be filled at my department. What should I do?

Why does Mjolnir fall down in Age of Ultron but not in Endgame?



Cron job for let's encrypt renewal


Why is my crontab not working, and how can I troubleshoot it?Nginx certbot cronjob not workingMX record pointing to A record with two different IP'sIntermediate certificate for Let's EncryptDifferent behaviour when running letsencrypt's certbot as a cron jobLet's Encrypt verification failureHow to use Let's Encrypt with both EC2 and Cloudfront?Let's encrypt certificate permissions for tomcat8 ubuntu serverLet's Encrypt Expiry Bot (certificate expiration notice)Let's Encrypt with dynamic subdomainsnginx load balancer w/ https and lets encrypt cert renewalHow to recreate let's encrypt certificate with public key from the past?Trying to configure letsencrypt auto renewal with HAProxy






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








84















Is this correct way to set cron for renewal of Let's Encrypt cert in Apache2 ?
I use Ubuntu 16.04.



@monthly letsencrypt renew && service apache2 reload









share|improve this question



















  • 6





    As one of the answers states below, certbot v0.19.0 (and maybe some earlier) already create a crontab entry @ /etc/cron.d/certbot

    – xgMz
    Oct 29 '17 at 17:40











  • Also, the certbot apache plugin with the tls-sni validation will reload apache as part of the validation procedure after the new certificate has been retrieved.

    – xgMz
    Oct 29 '17 at 17:47











  • There is an answer below that is very important for new installs (as of JAN 2019), certbot automatically adds system timer and cron job schedule so the cron setup is not needed on your part.

    – Cory Robinson
    Feb 9 at 14:51

















84















Is this correct way to set cron for renewal of Let's Encrypt cert in Apache2 ?
I use Ubuntu 16.04.



@monthly letsencrypt renew && service apache2 reload









share|improve this question



















  • 6





    As one of the answers states below, certbot v0.19.0 (and maybe some earlier) already create a crontab entry @ /etc/cron.d/certbot

    – xgMz
    Oct 29 '17 at 17:40











  • Also, the certbot apache plugin with the tls-sni validation will reload apache as part of the validation procedure after the new certificate has been retrieved.

    – xgMz
    Oct 29 '17 at 17:47











  • There is an answer below that is very important for new installs (as of JAN 2019), certbot automatically adds system timer and cron job schedule so the cron setup is not needed on your part.

    – Cory Robinson
    Feb 9 at 14:51













84












84








84


27






Is this correct way to set cron for renewal of Let's Encrypt cert in Apache2 ?
I use Ubuntu 16.04.



@monthly letsencrypt renew && service apache2 reload









share|improve this question
















Is this correct way to set cron for renewal of Let's Encrypt cert in Apache2 ?
I use Ubuntu 16.04.



@monthly letsencrypt renew && service apache2 reload






cron lets-encrypt






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 19 '16 at 19:34









Michael Hampton

178k27325657




178k27325657










asked Jul 19 '16 at 19:07









user3448600user3448600

3591410




3591410







  • 6





    As one of the answers states below, certbot v0.19.0 (and maybe some earlier) already create a crontab entry @ /etc/cron.d/certbot

    – xgMz
    Oct 29 '17 at 17:40











  • Also, the certbot apache plugin with the tls-sni validation will reload apache as part of the validation procedure after the new certificate has been retrieved.

    – xgMz
    Oct 29 '17 at 17:47











  • There is an answer below that is very important for new installs (as of JAN 2019), certbot automatically adds system timer and cron job schedule so the cron setup is not needed on your part.

    – Cory Robinson
    Feb 9 at 14:51












  • 6





    As one of the answers states below, certbot v0.19.0 (and maybe some earlier) already create a crontab entry @ /etc/cron.d/certbot

    – xgMz
    Oct 29 '17 at 17:40











  • Also, the certbot apache plugin with the tls-sni validation will reload apache as part of the validation procedure after the new certificate has been retrieved.

    – xgMz
    Oct 29 '17 at 17:47











  • There is an answer below that is very important for new installs (as of JAN 2019), certbot automatically adds system timer and cron job schedule so the cron setup is not needed on your part.

    – Cory Robinson
    Feb 9 at 14:51







6




6





As one of the answers states below, certbot v0.19.0 (and maybe some earlier) already create a crontab entry @ /etc/cron.d/certbot

– xgMz
Oct 29 '17 at 17:40





As one of the answers states below, certbot v0.19.0 (and maybe some earlier) already create a crontab entry @ /etc/cron.d/certbot

– xgMz
Oct 29 '17 at 17:40













Also, the certbot apache plugin with the tls-sni validation will reload apache as part of the validation procedure after the new certificate has been retrieved.

– xgMz
Oct 29 '17 at 17:47





Also, the certbot apache plugin with the tls-sni validation will reload apache as part of the validation procedure after the new certificate has been retrieved.

– xgMz
Oct 29 '17 at 17:47













There is an answer below that is very important for new installs (as of JAN 2019), certbot automatically adds system timer and cron job schedule so the cron setup is not needed on your part.

– Cory Robinson
Feb 9 at 14:51





There is an answer below that is very important for new installs (as of JAN 2019), certbot automatically adds system timer and cron job schedule so the cron setup is not needed on your part.

– Cory Robinson
Feb 9 at 14:51










8 Answers
8






active

oldest

votes


















124














Monthly is not frequent enough. This script should run at least weekly, and preferably daily. Remember that certs don't get renewed unless they are near to expiration, and monthly would cause your existing certs to occasionally be expired already before they get renewed.



The name of the program is certbot, which was renamed from letsencrypt. If you are still using letsencrypt, you need to update to the current version.



Aside from those issues, it's about the same as my cron jobs.



43 6 * * * certbot renew --post-hook "systemctl reload nginx"



Note that in 18.04 LTS the letsencrypt package has been (finally) renamed to certbot. It now includes a systemd timer which you can enable to schedule certbot renewals, with systemctl enable certbot.timer and systemctl start certbot.timer. However, Ubuntu did not provide a way to specify hooks. You'll need to set up an override for certbot.service to override ExecStart= with your desired command line, until Ubuntu fixes this.






share|improve this answer




















  • 3





    What time window is "near to expiration"?

    – Andre Figueiredo
    May 11 '17 at 18:49






  • 1





    It may be better to user --renew-hook instead of --post-hook, to only restart if the cert is successfully renewed.

    – mwfearnley
    Oct 6 '17 at 9:27






  • 4





    For apache/httpd, certbot renew will just work™

    – aairey
    Oct 25 '17 at 11:39






  • 1





    I just wanted to add, rather than overriding ExecStart to reload nginx, just add an ExecStartPost line to certbot.service to reload your webserver after it's done: ExecStartPost=/usr/sbin/service nginx reload. Worked for me!

    – J.D. Mallen
    Dec 15 '18 at 6:16






  • 1





    @J.D.Mallen Using ExecStartPost= is a good idea. Why didn't I think of that? But be aware that the service command is deprecated; it won't be around forever. Switch to the corresponding systemctl commands.

    – Michael Hampton
    Dec 15 '18 at 15:51


















54














I don't have enough reputation to comment, so I'll answer here. I recently (October 2017) installed and ran certbot on an Ubuntu 16.04 server and a renewal cron job was created automatically in /etc/cron.d/certbot.



Here's the cron job that was created:



0 */12 * * * root test -x /usr/bin/certbot -a ! -d /run/systemd/system && perl -e 'sleep int(rand(3600))' && certbot -q renew


It would be a good idea to check, if this file already exists before creating a crontab entry.






share|improve this answer




















  • 1





    I saw I had this as well after running certbot. Very nice that lets encrypt did this! It's a great project.

    – Bjorn Tipling
    Dec 11 '17 at 7:24







  • 7





    It's worth being aware that the above cron job won't run certbot renew if /run/systemd/system is present - this is because instead a systemd timer is running certbot - read more about certbot and systemd timers here.

    – Hamish Downer
    Aug 2 '18 at 19:55











  • Thanks for mentioning that a cronjob had already been installed. I was not aware of that till I read your post.

    – NilsB
    Dec 1 '18 at 6:58


















39














The certbot documentation recommends running the script twice a day:




Note:



if you're setting up a cron or systemd job, we recommend running it twice per day (it won't do anything until your certificates are due for renewal or revoked, but running it regularly would give your site a chance of staying online in case a Let's Encrypt-initiated revocation happened for some reason). Please select a random minute within the hour for your renewal tasks.




As Michael Hampton mentions the name has changed to certbot, but they still provide the -auto option that keeps itself updated. The certbot-auto command need root priviledges to run, so the line in your cron script should look something like this:



52 0,12 * * * root /full/path/to/certbot-auto renew --quiet


In my own case the certbot-auto script is placed in the git-user's home directory. The exact command is then



52 0,12 * * * root /home/git/certbot-auto renew --quiet


Note that the example in the documentation corresponds to a relative path, as indicated by the dot which can be confusing:



./path/to/certbot-auto renew --quiet



Be sure to testrun the renew command in a shell beforehand to test the path, if the certificate isn't due for renewal nothing will happen (run this test without the --quiet flag to see what is happening).



It is not strictly necessary to reload the server when the certificate is renewed in this way, since the path to the live certificate doesn't change if set up correctly.



This is true if you are running apache - for nginx, consider adding a renew hook, such as:



52 0,12 * * * root certbot renew --renew-hook 'service nginx reload'





share|improve this answer




















  • 1





    I like how this is explained, detailing service restart is not needed (it could make a mess if someone is doing anything on it, having a chance twice a day to get caught) and mentioning privileges needed.

    – Gusstavv Gil
    Feb 21 '17 at 2:18






  • 2





    This is not true — it is necessary to reload the server, at least with Nginx — nginx appears to cache the initial certificate and does not register a new cert even if the file changes. See this post for info on using --renew-hook to only restart after a successful renewal: guyrutenberg.com/2017/01/01/…

    – Whatcould
    Aug 18 '17 at 1:43



















9














You shouldn't have to set up anything. Any recent Debian/Ubuntu install of certbot should install a systemd timer and a cron job (and the cron job will only run if systemd is not active, so you don't get both running).



systemd timer



You can check your systemd timers using command systemctl list-timers (or systemctl list-timers --all if you also want to show inactive timers). Something like this:



% sudo systemctl list-timers
NEXT LEFT LAST PASSED UNIT ACTIVATES
Fri 2018-08-03 06:17:25 UTC 10h left Thu 2018-08-02 06:27:13 UTC 13h ago apt-daily-upgrade.timer apt-daily-upgrade.service
Fri 2018-08-03 11:43:29 UTC 15h left Thu 2018-08-02 16:54:52 UTC 3h 7min ago certbot.timer certbot.service
Fri 2018-08-03 12:44:58 UTC 16h left Thu 2018-08-02 19:14:58 UTC 47min ago apt-daily.timer apt-daily.service
Fri 2018-08-03 19:43:44 UTC 23h left Thu 2018-08-02 19:43:44 UTC 18min ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
Mon 2018-08-06 00:00:00 UTC 3 days left Mon 2018-07-30 00:00:09 UTC 3 days ago fstrim.timer fstrim.service


The certbot timer should be here /lib/systemd/system/certbot.timer and it will execute the command specified in /lib/systemd/system/certbot.service



certbot.timer will execute the `certbot.service at 12 am and 12 pm, after a random delay of up to 12 hours (43200 seconds).



# cat /lib/systemd/system/certbot.timer
[Unit]
Description=Run certbot twice daily

[Timer]
OnCalendar=*-*-* 00,12:00:00
RandomizedDelaySec=43200
Persistent=true

[Install]
WantedBy=timers.target


and certbot.service will execute the renew command.



# cat /lib/systemd/system/certbot.service
[Unit]
Description=Certbot
Documentation=file:///usr/share/doc/python-certbot-doc/html/index.html
Documentation=https://letsencrypt.readthedocs.io/en/latest/
[Service]
Type=oneshot
ExecStart=/usr/bin/certbot -q renew
PrivateTmp=true


cron job



As others have mentioned, there is also a cron job installed in /etc/cron.d/certbot:



# Eventually, this will be an opportunity to validate certificates
# haven't been revoked, etc. Renewal will only occur if expiration
# is within 30 days.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

0 */12 * * * root test -x /usr/bin/certbot -a ! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew


This is doing:




  • test -x /usr/bin/certbot -a ! -d /run/systemd/system - check if /usr/bin/certbot is an executable file and that /run/systemd/system is not a directory. Only continue to the next bit if this check succeeds.

    • The systemd part of the check effectively means that if systemd is running, don't run certbot from the cron job - leave that to the timer.



  • perl -e 'sleep int(rand(43200))' - sleep a random amount between 0 seconds and 12 hours (43200 = 12 x 60 x 60).


  • certbot -q renew check your certificates and renew any if required. The -q flag is "quiet" - don't produce any output unless there is an error.

I was originally confused by the cron job as it wasn't going to run due to systemd, so how would certbot be run? I found the answer in this forum post which is what I based this answer on.






share|improve this answer























  • "You shouldn't have to set up anything" but my cert expired recently, and I installed certbot about 3 months ago. /etc/cron.d/certbot exists, systemctl list-timers shows certbot.timer, but my certs weren't renewed. Running certbot manually worked fine, so I don't know what's going on. Ended up adding an old school crontab entry.

    – Dan Dascalescu
    Oct 16 '18 at 5:20











  • This is the most up to date and correct answer but with a caveat that it depends on what dist you are running: certbot.eff.org/docs/using.html#id8

    – olive_tree
    Nov 22 '18 at 20:16


















5














For LetsEncrypt certificate renewal, I generally use getssl. It is a very handy shell wrapper which can even install certificate on other machines via SSH connection.



The cron entry is the following:



01 23 * * * root /root/scripts/getssl/getssl -u -a -q >>/var/log/getssl.log 2>&1 ; /usr/sbin/apache2ctl graceful



As already suggested, you should run it daily or, even better, twice a day.






share|improve this answer






























    3














    As already mentioned by glaux:




    Note: if you're setting up a cron or systemd job, we recommend running
    it twice per day (it won't do anything until your certificates are due
    for renewal or revoked, but running it regularly would give your site
    a chance of staying online in case a Let's Encrypt-initiated
    revocation happened for some reason). Please select a random minute
    within the hour for your renewal tasks.




    Source: https://certbot.eff.org/all-instructions/#debian-8-jessie-apache



    So i ended up using this (running is twice a day, at 01:00 and at 13:00 everyday):



    6 1,13 * * * certbot renew --post-hook "service apache2 restart"


    or even better:



    6 1,13 * * * certbot renew --renew-hook "service apache2 restart"


    I didn't test but this should work also:



    6 1,13 * * * certbot renew --post-hook "/etc/init.d/apache2 restart"
    6 1,13 * * * certbot renew --renew-hook "/etc/init.d/apache2 restart"



    --pre-hook and --post-hook hooks run before and after every renewal attempt. If you want your hook to run only after a successful renewal,
    use --renew-hook in a command like this.




    Source: https://certbot.eff.org/docs/using.html






    share|improve this answer




















    • 1





      "Please select a random minute within the hour for your renewal tasks."

      – Isius
      Aug 17 '17 at 15:55






    • 1





      Per my note above, you'd be better off with --renew-hook, which restarts your server only when the cert is actually renewed.

      – Whatcould
      Aug 18 '17 at 1:48











    • @Isius thanks, i changed it to a random minute (6).

      – Tadej
      Aug 18 '17 at 6:19






    • 1





      @JedatKinports: shouldn't the --post-hook and --renew-hook be service apache2 restart instead of service restart apache2?

      – Paul Ratazzi
      Apr 13 '18 at 18:29







    • 1





      The command is service apache2 restart! The service restart apache2 isn't correct command/service.

      – GTodorov
      Jun 12 '18 at 15:33


















    1














    This is what I use:



    /opt/letsencrypt/letsencrypt-auto renew


    gives output as:



    Upgrading certbot-auto 0.8.1 to 0.9.1...
    Replacing certbot-auto...
    Creating virtual environment...
    ...
    new certificate deployed with reload of apache server; fullchain is
    /etc/letsencrypt/live/host.simplecoin.cz/fullchain.pem
    -------------------------------------------------------------------------------

    Congratulations, all renewals succeeded. The following certs have been renewed:
    /etc/letsencrypt/live/host.simplecoin.cz/fullchain.pem (success)


    And its saying that apache is restarted already, so no need to do it over again. If I run it again:



    Cert not yet due for renewal


    therefore it's not problem to renew certificate daily, my cron is then:



    @daily /opt/letsencrypt/cronautorenew.sh


    I use script to tweak logging to separate file, so here is my cronautorenew.sh:



    #!/usr/bin/env bash
    printf "nattempt to renew certificates" >>/var/log/letsencrypt_cron.log 2>&1
    date >>/var/log/letsencrypt_cron.log 2>&1
    /opt/letsencrypt/letsencrypt-auto renew >>/var/log/letsencrypt_cron.log 2>&1
    printf "renew finishedn" >>/var/log/letsencrypt_cron.log 2>&1





    share|improve this answer






























      0














      According to EFF certbot guide




      Many Linux distributions provide automated renewal when you use the
      packages installed through their system package manager.




      If you are not sure whether or not your system has this already automated, check your system’s crontab (typically in /etc/crontab/ and /etc/cron.*/* $ crontab -l and systemd timers $ systemctl list-timers.






      share|improve this answer























        Your Answer








        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "2"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f790772%2fcron-job-for-lets-encrypt-renewal%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        8 Answers
        8






        active

        oldest

        votes








        8 Answers
        8






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        124














        Monthly is not frequent enough. This script should run at least weekly, and preferably daily. Remember that certs don't get renewed unless they are near to expiration, and monthly would cause your existing certs to occasionally be expired already before they get renewed.



        The name of the program is certbot, which was renamed from letsencrypt. If you are still using letsencrypt, you need to update to the current version.



        Aside from those issues, it's about the same as my cron jobs.



        43 6 * * * certbot renew --post-hook "systemctl reload nginx"



        Note that in 18.04 LTS the letsencrypt package has been (finally) renamed to certbot. It now includes a systemd timer which you can enable to schedule certbot renewals, with systemctl enable certbot.timer and systemctl start certbot.timer. However, Ubuntu did not provide a way to specify hooks. You'll need to set up an override for certbot.service to override ExecStart= with your desired command line, until Ubuntu fixes this.






        share|improve this answer




















        • 3





          What time window is "near to expiration"?

          – Andre Figueiredo
          May 11 '17 at 18:49






        • 1





          It may be better to user --renew-hook instead of --post-hook, to only restart if the cert is successfully renewed.

          – mwfearnley
          Oct 6 '17 at 9:27






        • 4





          For apache/httpd, certbot renew will just work™

          – aairey
          Oct 25 '17 at 11:39






        • 1





          I just wanted to add, rather than overriding ExecStart to reload nginx, just add an ExecStartPost line to certbot.service to reload your webserver after it's done: ExecStartPost=/usr/sbin/service nginx reload. Worked for me!

          – J.D. Mallen
          Dec 15 '18 at 6:16






        • 1





          @J.D.Mallen Using ExecStartPost= is a good idea. Why didn't I think of that? But be aware that the service command is deprecated; it won't be around forever. Switch to the corresponding systemctl commands.

          – Michael Hampton
          Dec 15 '18 at 15:51















        124














        Monthly is not frequent enough. This script should run at least weekly, and preferably daily. Remember that certs don't get renewed unless they are near to expiration, and monthly would cause your existing certs to occasionally be expired already before they get renewed.



        The name of the program is certbot, which was renamed from letsencrypt. If you are still using letsencrypt, you need to update to the current version.



        Aside from those issues, it's about the same as my cron jobs.



        43 6 * * * certbot renew --post-hook "systemctl reload nginx"



        Note that in 18.04 LTS the letsencrypt package has been (finally) renamed to certbot. It now includes a systemd timer which you can enable to schedule certbot renewals, with systemctl enable certbot.timer and systemctl start certbot.timer. However, Ubuntu did not provide a way to specify hooks. You'll need to set up an override for certbot.service to override ExecStart= with your desired command line, until Ubuntu fixes this.






        share|improve this answer




















        • 3





          What time window is "near to expiration"?

          – Andre Figueiredo
          May 11 '17 at 18:49






        • 1





          It may be better to user --renew-hook instead of --post-hook, to only restart if the cert is successfully renewed.

          – mwfearnley
          Oct 6 '17 at 9:27






        • 4





          For apache/httpd, certbot renew will just work™

          – aairey
          Oct 25 '17 at 11:39






        • 1





          I just wanted to add, rather than overriding ExecStart to reload nginx, just add an ExecStartPost line to certbot.service to reload your webserver after it's done: ExecStartPost=/usr/sbin/service nginx reload. Worked for me!

          – J.D. Mallen
          Dec 15 '18 at 6:16






        • 1





          @J.D.Mallen Using ExecStartPost= is a good idea. Why didn't I think of that? But be aware that the service command is deprecated; it won't be around forever. Switch to the corresponding systemctl commands.

          – Michael Hampton
          Dec 15 '18 at 15:51













        124












        124








        124







        Monthly is not frequent enough. This script should run at least weekly, and preferably daily. Remember that certs don't get renewed unless they are near to expiration, and monthly would cause your existing certs to occasionally be expired already before they get renewed.



        The name of the program is certbot, which was renamed from letsencrypt. If you are still using letsencrypt, you need to update to the current version.



        Aside from those issues, it's about the same as my cron jobs.



        43 6 * * * certbot renew --post-hook "systemctl reload nginx"



        Note that in 18.04 LTS the letsencrypt package has been (finally) renamed to certbot. It now includes a systemd timer which you can enable to schedule certbot renewals, with systemctl enable certbot.timer and systemctl start certbot.timer. However, Ubuntu did not provide a way to specify hooks. You'll need to set up an override for certbot.service to override ExecStart= with your desired command line, until Ubuntu fixes this.






        share|improve this answer















        Monthly is not frequent enough. This script should run at least weekly, and preferably daily. Remember that certs don't get renewed unless they are near to expiration, and monthly would cause your existing certs to occasionally be expired already before they get renewed.



        The name of the program is certbot, which was renamed from letsencrypt. If you are still using letsencrypt, you need to update to the current version.



        Aside from those issues, it's about the same as my cron jobs.



        43 6 * * * certbot renew --post-hook "systemctl reload nginx"



        Note that in 18.04 LTS the letsencrypt package has been (finally) renamed to certbot. It now includes a systemd timer which you can enable to schedule certbot renewals, with systemctl enable certbot.timer and systemctl start certbot.timer. However, Ubuntu did not provide a way to specify hooks. You'll need to set up an override for certbot.service to override ExecStart= with your desired command line, until Ubuntu fixes this.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 11 '18 at 23:19

























        answered Jul 19 '16 at 19:33









        Michael HamptonMichael Hampton

        178k27325657




        178k27325657







        • 3





          What time window is "near to expiration"?

          – Andre Figueiredo
          May 11 '17 at 18:49






        • 1





          It may be better to user --renew-hook instead of --post-hook, to only restart if the cert is successfully renewed.

          – mwfearnley
          Oct 6 '17 at 9:27






        • 4





          For apache/httpd, certbot renew will just work™

          – aairey
          Oct 25 '17 at 11:39






        • 1





          I just wanted to add, rather than overriding ExecStart to reload nginx, just add an ExecStartPost line to certbot.service to reload your webserver after it's done: ExecStartPost=/usr/sbin/service nginx reload. Worked for me!

          – J.D. Mallen
          Dec 15 '18 at 6:16






        • 1





          @J.D.Mallen Using ExecStartPost= is a good idea. Why didn't I think of that? But be aware that the service command is deprecated; it won't be around forever. Switch to the corresponding systemctl commands.

          – Michael Hampton
          Dec 15 '18 at 15:51












        • 3





          What time window is "near to expiration"?

          – Andre Figueiredo
          May 11 '17 at 18:49






        • 1





          It may be better to user --renew-hook instead of --post-hook, to only restart if the cert is successfully renewed.

          – mwfearnley
          Oct 6 '17 at 9:27






        • 4





          For apache/httpd, certbot renew will just work™

          – aairey
          Oct 25 '17 at 11:39






        • 1





          I just wanted to add, rather than overriding ExecStart to reload nginx, just add an ExecStartPost line to certbot.service to reload your webserver after it's done: ExecStartPost=/usr/sbin/service nginx reload. Worked for me!

          – J.D. Mallen
          Dec 15 '18 at 6:16






        • 1





          @J.D.Mallen Using ExecStartPost= is a good idea. Why didn't I think of that? But be aware that the service command is deprecated; it won't be around forever. Switch to the corresponding systemctl commands.

          – Michael Hampton
          Dec 15 '18 at 15:51







        3




        3





        What time window is "near to expiration"?

        – Andre Figueiredo
        May 11 '17 at 18:49





        What time window is "near to expiration"?

        – Andre Figueiredo
        May 11 '17 at 18:49




        1




        1





        It may be better to user --renew-hook instead of --post-hook, to only restart if the cert is successfully renewed.

        – mwfearnley
        Oct 6 '17 at 9:27





        It may be better to user --renew-hook instead of --post-hook, to only restart if the cert is successfully renewed.

        – mwfearnley
        Oct 6 '17 at 9:27




        4




        4





        For apache/httpd, certbot renew will just work™

        – aairey
        Oct 25 '17 at 11:39





        For apache/httpd, certbot renew will just work™

        – aairey
        Oct 25 '17 at 11:39




        1




        1





        I just wanted to add, rather than overriding ExecStart to reload nginx, just add an ExecStartPost line to certbot.service to reload your webserver after it's done: ExecStartPost=/usr/sbin/service nginx reload. Worked for me!

        – J.D. Mallen
        Dec 15 '18 at 6:16





        I just wanted to add, rather than overriding ExecStart to reload nginx, just add an ExecStartPost line to certbot.service to reload your webserver after it's done: ExecStartPost=/usr/sbin/service nginx reload. Worked for me!

        – J.D. Mallen
        Dec 15 '18 at 6:16




        1




        1





        @J.D.Mallen Using ExecStartPost= is a good idea. Why didn't I think of that? But be aware that the service command is deprecated; it won't be around forever. Switch to the corresponding systemctl commands.

        – Michael Hampton
        Dec 15 '18 at 15:51





        @J.D.Mallen Using ExecStartPost= is a good idea. Why didn't I think of that? But be aware that the service command is deprecated; it won't be around forever. Switch to the corresponding systemctl commands.

        – Michael Hampton
        Dec 15 '18 at 15:51













        54














        I don't have enough reputation to comment, so I'll answer here. I recently (October 2017) installed and ran certbot on an Ubuntu 16.04 server and a renewal cron job was created automatically in /etc/cron.d/certbot.



        Here's the cron job that was created:



        0 */12 * * * root test -x /usr/bin/certbot -a ! -d /run/systemd/system && perl -e 'sleep int(rand(3600))' && certbot -q renew


        It would be a good idea to check, if this file already exists before creating a crontab entry.






        share|improve this answer




















        • 1





          I saw I had this as well after running certbot. Very nice that lets encrypt did this! It's a great project.

          – Bjorn Tipling
          Dec 11 '17 at 7:24







        • 7





          It's worth being aware that the above cron job won't run certbot renew if /run/systemd/system is present - this is because instead a systemd timer is running certbot - read more about certbot and systemd timers here.

          – Hamish Downer
          Aug 2 '18 at 19:55











        • Thanks for mentioning that a cronjob had already been installed. I was not aware of that till I read your post.

          – NilsB
          Dec 1 '18 at 6:58















        54














        I don't have enough reputation to comment, so I'll answer here. I recently (October 2017) installed and ran certbot on an Ubuntu 16.04 server and a renewal cron job was created automatically in /etc/cron.d/certbot.



        Here's the cron job that was created:



        0 */12 * * * root test -x /usr/bin/certbot -a ! -d /run/systemd/system && perl -e 'sleep int(rand(3600))' && certbot -q renew


        It would be a good idea to check, if this file already exists before creating a crontab entry.






        share|improve this answer




















        • 1





          I saw I had this as well after running certbot. Very nice that lets encrypt did this! It's a great project.

          – Bjorn Tipling
          Dec 11 '17 at 7:24







        • 7





          It's worth being aware that the above cron job won't run certbot renew if /run/systemd/system is present - this is because instead a systemd timer is running certbot - read more about certbot and systemd timers here.

          – Hamish Downer
          Aug 2 '18 at 19:55











        • Thanks for mentioning that a cronjob had already been installed. I was not aware of that till I read your post.

          – NilsB
          Dec 1 '18 at 6:58













        54












        54








        54







        I don't have enough reputation to comment, so I'll answer here. I recently (October 2017) installed and ran certbot on an Ubuntu 16.04 server and a renewal cron job was created automatically in /etc/cron.d/certbot.



        Here's the cron job that was created:



        0 */12 * * * root test -x /usr/bin/certbot -a ! -d /run/systemd/system && perl -e 'sleep int(rand(3600))' && certbot -q renew


        It would be a good idea to check, if this file already exists before creating a crontab entry.






        share|improve this answer















        I don't have enough reputation to comment, so I'll answer here. I recently (October 2017) installed and ran certbot on an Ubuntu 16.04 server and a renewal cron job was created automatically in /etc/cron.d/certbot.



        Here's the cron job that was created:



        0 */12 * * * root test -x /usr/bin/certbot -a ! -d /run/systemd/system && perl -e 'sleep int(rand(3600))' && certbot -q renew


        It would be a good idea to check, if this file already exists before creating a crontab entry.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jun 19 '18 at 12:22









        miyuru

        1146




        1146










        answered Oct 22 '17 at 15:34









        ishigoyaishigoya

        80635




        80635







        • 1





          I saw I had this as well after running certbot. Very nice that lets encrypt did this! It's a great project.

          – Bjorn Tipling
          Dec 11 '17 at 7:24







        • 7





          It's worth being aware that the above cron job won't run certbot renew if /run/systemd/system is present - this is because instead a systemd timer is running certbot - read more about certbot and systemd timers here.

          – Hamish Downer
          Aug 2 '18 at 19:55











        • Thanks for mentioning that a cronjob had already been installed. I was not aware of that till I read your post.

          – NilsB
          Dec 1 '18 at 6:58












        • 1





          I saw I had this as well after running certbot. Very nice that lets encrypt did this! It's a great project.

          – Bjorn Tipling
          Dec 11 '17 at 7:24







        • 7





          It's worth being aware that the above cron job won't run certbot renew if /run/systemd/system is present - this is because instead a systemd timer is running certbot - read more about certbot and systemd timers here.

          – Hamish Downer
          Aug 2 '18 at 19:55











        • Thanks for mentioning that a cronjob had already been installed. I was not aware of that till I read your post.

          – NilsB
          Dec 1 '18 at 6:58







        1




        1





        I saw I had this as well after running certbot. Very nice that lets encrypt did this! It's a great project.

        – Bjorn Tipling
        Dec 11 '17 at 7:24






        I saw I had this as well after running certbot. Very nice that lets encrypt did this! It's a great project.

        – Bjorn Tipling
        Dec 11 '17 at 7:24





        7




        7





        It's worth being aware that the above cron job won't run certbot renew if /run/systemd/system is present - this is because instead a systemd timer is running certbot - read more about certbot and systemd timers here.

        – Hamish Downer
        Aug 2 '18 at 19:55





        It's worth being aware that the above cron job won't run certbot renew if /run/systemd/system is present - this is because instead a systemd timer is running certbot - read more about certbot and systemd timers here.

        – Hamish Downer
        Aug 2 '18 at 19:55













        Thanks for mentioning that a cronjob had already been installed. I was not aware of that till I read your post.

        – NilsB
        Dec 1 '18 at 6:58





        Thanks for mentioning that a cronjob had already been installed. I was not aware of that till I read your post.

        – NilsB
        Dec 1 '18 at 6:58











        39














        The certbot documentation recommends running the script twice a day:




        Note:



        if you're setting up a cron or systemd job, we recommend running it twice per day (it won't do anything until your certificates are due for renewal or revoked, but running it regularly would give your site a chance of staying online in case a Let's Encrypt-initiated revocation happened for some reason). Please select a random minute within the hour for your renewal tasks.




        As Michael Hampton mentions the name has changed to certbot, but they still provide the -auto option that keeps itself updated. The certbot-auto command need root priviledges to run, so the line in your cron script should look something like this:



        52 0,12 * * * root /full/path/to/certbot-auto renew --quiet


        In my own case the certbot-auto script is placed in the git-user's home directory. The exact command is then



        52 0,12 * * * root /home/git/certbot-auto renew --quiet


        Note that the example in the documentation corresponds to a relative path, as indicated by the dot which can be confusing:



        ./path/to/certbot-auto renew --quiet



        Be sure to testrun the renew command in a shell beforehand to test the path, if the certificate isn't due for renewal nothing will happen (run this test without the --quiet flag to see what is happening).



        It is not strictly necessary to reload the server when the certificate is renewed in this way, since the path to the live certificate doesn't change if set up correctly.



        This is true if you are running apache - for nginx, consider adding a renew hook, such as:



        52 0,12 * * * root certbot renew --renew-hook 'service nginx reload'





        share|improve this answer




















        • 1





          I like how this is explained, detailing service restart is not needed (it could make a mess if someone is doing anything on it, having a chance twice a day to get caught) and mentioning privileges needed.

          – Gusstavv Gil
          Feb 21 '17 at 2:18






        • 2





          This is not true — it is necessary to reload the server, at least with Nginx — nginx appears to cache the initial certificate and does not register a new cert even if the file changes. See this post for info on using --renew-hook to only restart after a successful renewal: guyrutenberg.com/2017/01/01/…

          – Whatcould
          Aug 18 '17 at 1:43
















        39














        The certbot documentation recommends running the script twice a day:




        Note:



        if you're setting up a cron or systemd job, we recommend running it twice per day (it won't do anything until your certificates are due for renewal or revoked, but running it regularly would give your site a chance of staying online in case a Let's Encrypt-initiated revocation happened for some reason). Please select a random minute within the hour for your renewal tasks.




        As Michael Hampton mentions the name has changed to certbot, but they still provide the -auto option that keeps itself updated. The certbot-auto command need root priviledges to run, so the line in your cron script should look something like this:



        52 0,12 * * * root /full/path/to/certbot-auto renew --quiet


        In my own case the certbot-auto script is placed in the git-user's home directory. The exact command is then



        52 0,12 * * * root /home/git/certbot-auto renew --quiet


        Note that the example in the documentation corresponds to a relative path, as indicated by the dot which can be confusing:



        ./path/to/certbot-auto renew --quiet



        Be sure to testrun the renew command in a shell beforehand to test the path, if the certificate isn't due for renewal nothing will happen (run this test without the --quiet flag to see what is happening).



        It is not strictly necessary to reload the server when the certificate is renewed in this way, since the path to the live certificate doesn't change if set up correctly.



        This is true if you are running apache - for nginx, consider adding a renew hook, such as:



        52 0,12 * * * root certbot renew --renew-hook 'service nginx reload'





        share|improve this answer




















        • 1





          I like how this is explained, detailing service restart is not needed (it could make a mess if someone is doing anything on it, having a chance twice a day to get caught) and mentioning privileges needed.

          – Gusstavv Gil
          Feb 21 '17 at 2:18






        • 2





          This is not true — it is necessary to reload the server, at least with Nginx — nginx appears to cache the initial certificate and does not register a new cert even if the file changes. See this post for info on using --renew-hook to only restart after a successful renewal: guyrutenberg.com/2017/01/01/…

          – Whatcould
          Aug 18 '17 at 1:43














        39












        39








        39







        The certbot documentation recommends running the script twice a day:




        Note:



        if you're setting up a cron or systemd job, we recommend running it twice per day (it won't do anything until your certificates are due for renewal or revoked, but running it regularly would give your site a chance of staying online in case a Let's Encrypt-initiated revocation happened for some reason). Please select a random minute within the hour for your renewal tasks.




        As Michael Hampton mentions the name has changed to certbot, but they still provide the -auto option that keeps itself updated. The certbot-auto command need root priviledges to run, so the line in your cron script should look something like this:



        52 0,12 * * * root /full/path/to/certbot-auto renew --quiet


        In my own case the certbot-auto script is placed in the git-user's home directory. The exact command is then



        52 0,12 * * * root /home/git/certbot-auto renew --quiet


        Note that the example in the documentation corresponds to a relative path, as indicated by the dot which can be confusing:



        ./path/to/certbot-auto renew --quiet



        Be sure to testrun the renew command in a shell beforehand to test the path, if the certificate isn't due for renewal nothing will happen (run this test without the --quiet flag to see what is happening).



        It is not strictly necessary to reload the server when the certificate is renewed in this way, since the path to the live certificate doesn't change if set up correctly.



        This is true if you are running apache - for nginx, consider adding a renew hook, such as:



        52 0,12 * * * root certbot renew --renew-hook 'service nginx reload'





        share|improve this answer















        The certbot documentation recommends running the script twice a day:




        Note:



        if you're setting up a cron or systemd job, we recommend running it twice per day (it won't do anything until your certificates are due for renewal or revoked, but running it regularly would give your site a chance of staying online in case a Let's Encrypt-initiated revocation happened for some reason). Please select a random minute within the hour for your renewal tasks.




        As Michael Hampton mentions the name has changed to certbot, but they still provide the -auto option that keeps itself updated. The certbot-auto command need root priviledges to run, so the line in your cron script should look something like this:



        52 0,12 * * * root /full/path/to/certbot-auto renew --quiet


        In my own case the certbot-auto script is placed in the git-user's home directory. The exact command is then



        52 0,12 * * * root /home/git/certbot-auto renew --quiet


        Note that the example in the documentation corresponds to a relative path, as indicated by the dot which can be confusing:



        ./path/to/certbot-auto renew --quiet



        Be sure to testrun the renew command in a shell beforehand to test the path, if the certificate isn't due for renewal nothing will happen (run this test without the --quiet flag to see what is happening).



        It is not strictly necessary to reload the server when the certificate is renewed in this way, since the path to the live certificate doesn't change if set up correctly.



        This is true if you are running apache - for nginx, consider adding a renew hook, such as:



        52 0,12 * * * root certbot renew --renew-hook 'service nginx reload'






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Apr 4 '18 at 5:07









        Dave Jarvis

        19819




        19819










        answered Jan 9 '17 at 9:07









        glauxglaux

        49647




        49647







        • 1





          I like how this is explained, detailing service restart is not needed (it could make a mess if someone is doing anything on it, having a chance twice a day to get caught) and mentioning privileges needed.

          – Gusstavv Gil
          Feb 21 '17 at 2:18






        • 2





          This is not true — it is necessary to reload the server, at least with Nginx — nginx appears to cache the initial certificate and does not register a new cert even if the file changes. See this post for info on using --renew-hook to only restart after a successful renewal: guyrutenberg.com/2017/01/01/…

          – Whatcould
          Aug 18 '17 at 1:43













        • 1





          I like how this is explained, detailing service restart is not needed (it could make a mess if someone is doing anything on it, having a chance twice a day to get caught) and mentioning privileges needed.

          – Gusstavv Gil
          Feb 21 '17 at 2:18






        • 2





          This is not true — it is necessary to reload the server, at least with Nginx — nginx appears to cache the initial certificate and does not register a new cert even if the file changes. See this post for info on using --renew-hook to only restart after a successful renewal: guyrutenberg.com/2017/01/01/…

          – Whatcould
          Aug 18 '17 at 1:43








        1




        1





        I like how this is explained, detailing service restart is not needed (it could make a mess if someone is doing anything on it, having a chance twice a day to get caught) and mentioning privileges needed.

        – Gusstavv Gil
        Feb 21 '17 at 2:18





        I like how this is explained, detailing service restart is not needed (it could make a mess if someone is doing anything on it, having a chance twice a day to get caught) and mentioning privileges needed.

        – Gusstavv Gil
        Feb 21 '17 at 2:18




        2




        2





        This is not true — it is necessary to reload the server, at least with Nginx — nginx appears to cache the initial certificate and does not register a new cert even if the file changes. See this post for info on using --renew-hook to only restart after a successful renewal: guyrutenberg.com/2017/01/01/…

        – Whatcould
        Aug 18 '17 at 1:43






        This is not true — it is necessary to reload the server, at least with Nginx — nginx appears to cache the initial certificate and does not register a new cert even if the file changes. See this post for info on using --renew-hook to only restart after a successful renewal: guyrutenberg.com/2017/01/01/…

        – Whatcould
        Aug 18 '17 at 1:43












        9














        You shouldn't have to set up anything. Any recent Debian/Ubuntu install of certbot should install a systemd timer and a cron job (and the cron job will only run if systemd is not active, so you don't get both running).



        systemd timer



        You can check your systemd timers using command systemctl list-timers (or systemctl list-timers --all if you also want to show inactive timers). Something like this:



        % sudo systemctl list-timers
        NEXT LEFT LAST PASSED UNIT ACTIVATES
        Fri 2018-08-03 06:17:25 UTC 10h left Thu 2018-08-02 06:27:13 UTC 13h ago apt-daily-upgrade.timer apt-daily-upgrade.service
        Fri 2018-08-03 11:43:29 UTC 15h left Thu 2018-08-02 16:54:52 UTC 3h 7min ago certbot.timer certbot.service
        Fri 2018-08-03 12:44:58 UTC 16h left Thu 2018-08-02 19:14:58 UTC 47min ago apt-daily.timer apt-daily.service
        Fri 2018-08-03 19:43:44 UTC 23h left Thu 2018-08-02 19:43:44 UTC 18min ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
        Mon 2018-08-06 00:00:00 UTC 3 days left Mon 2018-07-30 00:00:09 UTC 3 days ago fstrim.timer fstrim.service


        The certbot timer should be here /lib/systemd/system/certbot.timer and it will execute the command specified in /lib/systemd/system/certbot.service



        certbot.timer will execute the `certbot.service at 12 am and 12 pm, after a random delay of up to 12 hours (43200 seconds).



        # cat /lib/systemd/system/certbot.timer
        [Unit]
        Description=Run certbot twice daily

        [Timer]
        OnCalendar=*-*-* 00,12:00:00
        RandomizedDelaySec=43200
        Persistent=true

        [Install]
        WantedBy=timers.target


        and certbot.service will execute the renew command.



        # cat /lib/systemd/system/certbot.service
        [Unit]
        Description=Certbot
        Documentation=file:///usr/share/doc/python-certbot-doc/html/index.html
        Documentation=https://letsencrypt.readthedocs.io/en/latest/
        [Service]
        Type=oneshot
        ExecStart=/usr/bin/certbot -q renew
        PrivateTmp=true


        cron job



        As others have mentioned, there is also a cron job installed in /etc/cron.d/certbot:



        # Eventually, this will be an opportunity to validate certificates
        # haven't been revoked, etc. Renewal will only occur if expiration
        # is within 30 days.
        SHELL=/bin/sh
        PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

        0 */12 * * * root test -x /usr/bin/certbot -a ! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew


        This is doing:




        • test -x /usr/bin/certbot -a ! -d /run/systemd/system - check if /usr/bin/certbot is an executable file and that /run/systemd/system is not a directory. Only continue to the next bit if this check succeeds.

          • The systemd part of the check effectively means that if systemd is running, don't run certbot from the cron job - leave that to the timer.



        • perl -e 'sleep int(rand(43200))' - sleep a random amount between 0 seconds and 12 hours (43200 = 12 x 60 x 60).


        • certbot -q renew check your certificates and renew any if required. The -q flag is "quiet" - don't produce any output unless there is an error.

        I was originally confused by the cron job as it wasn't going to run due to systemd, so how would certbot be run? I found the answer in this forum post which is what I based this answer on.






        share|improve this answer























        • "You shouldn't have to set up anything" but my cert expired recently, and I installed certbot about 3 months ago. /etc/cron.d/certbot exists, systemctl list-timers shows certbot.timer, but my certs weren't renewed. Running certbot manually worked fine, so I don't know what's going on. Ended up adding an old school crontab entry.

          – Dan Dascalescu
          Oct 16 '18 at 5:20











        • This is the most up to date and correct answer but with a caveat that it depends on what dist you are running: certbot.eff.org/docs/using.html#id8

          – olive_tree
          Nov 22 '18 at 20:16















        9














        You shouldn't have to set up anything. Any recent Debian/Ubuntu install of certbot should install a systemd timer and a cron job (and the cron job will only run if systemd is not active, so you don't get both running).



        systemd timer



        You can check your systemd timers using command systemctl list-timers (or systemctl list-timers --all if you also want to show inactive timers). Something like this:



        % sudo systemctl list-timers
        NEXT LEFT LAST PASSED UNIT ACTIVATES
        Fri 2018-08-03 06:17:25 UTC 10h left Thu 2018-08-02 06:27:13 UTC 13h ago apt-daily-upgrade.timer apt-daily-upgrade.service
        Fri 2018-08-03 11:43:29 UTC 15h left Thu 2018-08-02 16:54:52 UTC 3h 7min ago certbot.timer certbot.service
        Fri 2018-08-03 12:44:58 UTC 16h left Thu 2018-08-02 19:14:58 UTC 47min ago apt-daily.timer apt-daily.service
        Fri 2018-08-03 19:43:44 UTC 23h left Thu 2018-08-02 19:43:44 UTC 18min ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
        Mon 2018-08-06 00:00:00 UTC 3 days left Mon 2018-07-30 00:00:09 UTC 3 days ago fstrim.timer fstrim.service


        The certbot timer should be here /lib/systemd/system/certbot.timer and it will execute the command specified in /lib/systemd/system/certbot.service



        certbot.timer will execute the `certbot.service at 12 am and 12 pm, after a random delay of up to 12 hours (43200 seconds).



        # cat /lib/systemd/system/certbot.timer
        [Unit]
        Description=Run certbot twice daily

        [Timer]
        OnCalendar=*-*-* 00,12:00:00
        RandomizedDelaySec=43200
        Persistent=true

        [Install]
        WantedBy=timers.target


        and certbot.service will execute the renew command.



        # cat /lib/systemd/system/certbot.service
        [Unit]
        Description=Certbot
        Documentation=file:///usr/share/doc/python-certbot-doc/html/index.html
        Documentation=https://letsencrypt.readthedocs.io/en/latest/
        [Service]
        Type=oneshot
        ExecStart=/usr/bin/certbot -q renew
        PrivateTmp=true


        cron job



        As others have mentioned, there is also a cron job installed in /etc/cron.d/certbot:



        # Eventually, this will be an opportunity to validate certificates
        # haven't been revoked, etc. Renewal will only occur if expiration
        # is within 30 days.
        SHELL=/bin/sh
        PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

        0 */12 * * * root test -x /usr/bin/certbot -a ! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew


        This is doing:




        • test -x /usr/bin/certbot -a ! -d /run/systemd/system - check if /usr/bin/certbot is an executable file and that /run/systemd/system is not a directory. Only continue to the next bit if this check succeeds.

          • The systemd part of the check effectively means that if systemd is running, don't run certbot from the cron job - leave that to the timer.



        • perl -e 'sleep int(rand(43200))' - sleep a random amount between 0 seconds and 12 hours (43200 = 12 x 60 x 60).


        • certbot -q renew check your certificates and renew any if required. The -q flag is "quiet" - don't produce any output unless there is an error.

        I was originally confused by the cron job as it wasn't going to run due to systemd, so how would certbot be run? I found the answer in this forum post which is what I based this answer on.






        share|improve this answer























        • "You shouldn't have to set up anything" but my cert expired recently, and I installed certbot about 3 months ago. /etc/cron.d/certbot exists, systemctl list-timers shows certbot.timer, but my certs weren't renewed. Running certbot manually worked fine, so I don't know what's going on. Ended up adding an old school crontab entry.

          – Dan Dascalescu
          Oct 16 '18 at 5:20











        • This is the most up to date and correct answer but with a caveat that it depends on what dist you are running: certbot.eff.org/docs/using.html#id8

          – olive_tree
          Nov 22 '18 at 20:16













        9












        9








        9







        You shouldn't have to set up anything. Any recent Debian/Ubuntu install of certbot should install a systemd timer and a cron job (and the cron job will only run if systemd is not active, so you don't get both running).



        systemd timer



        You can check your systemd timers using command systemctl list-timers (or systemctl list-timers --all if you also want to show inactive timers). Something like this:



        % sudo systemctl list-timers
        NEXT LEFT LAST PASSED UNIT ACTIVATES
        Fri 2018-08-03 06:17:25 UTC 10h left Thu 2018-08-02 06:27:13 UTC 13h ago apt-daily-upgrade.timer apt-daily-upgrade.service
        Fri 2018-08-03 11:43:29 UTC 15h left Thu 2018-08-02 16:54:52 UTC 3h 7min ago certbot.timer certbot.service
        Fri 2018-08-03 12:44:58 UTC 16h left Thu 2018-08-02 19:14:58 UTC 47min ago apt-daily.timer apt-daily.service
        Fri 2018-08-03 19:43:44 UTC 23h left Thu 2018-08-02 19:43:44 UTC 18min ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
        Mon 2018-08-06 00:00:00 UTC 3 days left Mon 2018-07-30 00:00:09 UTC 3 days ago fstrim.timer fstrim.service


        The certbot timer should be here /lib/systemd/system/certbot.timer and it will execute the command specified in /lib/systemd/system/certbot.service



        certbot.timer will execute the `certbot.service at 12 am and 12 pm, after a random delay of up to 12 hours (43200 seconds).



        # cat /lib/systemd/system/certbot.timer
        [Unit]
        Description=Run certbot twice daily

        [Timer]
        OnCalendar=*-*-* 00,12:00:00
        RandomizedDelaySec=43200
        Persistent=true

        [Install]
        WantedBy=timers.target


        and certbot.service will execute the renew command.



        # cat /lib/systemd/system/certbot.service
        [Unit]
        Description=Certbot
        Documentation=file:///usr/share/doc/python-certbot-doc/html/index.html
        Documentation=https://letsencrypt.readthedocs.io/en/latest/
        [Service]
        Type=oneshot
        ExecStart=/usr/bin/certbot -q renew
        PrivateTmp=true


        cron job



        As others have mentioned, there is also a cron job installed in /etc/cron.d/certbot:



        # Eventually, this will be an opportunity to validate certificates
        # haven't been revoked, etc. Renewal will only occur if expiration
        # is within 30 days.
        SHELL=/bin/sh
        PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

        0 */12 * * * root test -x /usr/bin/certbot -a ! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew


        This is doing:




        • test -x /usr/bin/certbot -a ! -d /run/systemd/system - check if /usr/bin/certbot is an executable file and that /run/systemd/system is not a directory. Only continue to the next bit if this check succeeds.

          • The systemd part of the check effectively means that if systemd is running, don't run certbot from the cron job - leave that to the timer.



        • perl -e 'sleep int(rand(43200))' - sleep a random amount between 0 seconds and 12 hours (43200 = 12 x 60 x 60).


        • certbot -q renew check your certificates and renew any if required. The -q flag is "quiet" - don't produce any output unless there is an error.

        I was originally confused by the cron job as it wasn't going to run due to systemd, so how would certbot be run? I found the answer in this forum post which is what I based this answer on.






        share|improve this answer













        You shouldn't have to set up anything. Any recent Debian/Ubuntu install of certbot should install a systemd timer and a cron job (and the cron job will only run if systemd is not active, so you don't get both running).



        systemd timer



        You can check your systemd timers using command systemctl list-timers (or systemctl list-timers --all if you also want to show inactive timers). Something like this:



        % sudo systemctl list-timers
        NEXT LEFT LAST PASSED UNIT ACTIVATES
        Fri 2018-08-03 06:17:25 UTC 10h left Thu 2018-08-02 06:27:13 UTC 13h ago apt-daily-upgrade.timer apt-daily-upgrade.service
        Fri 2018-08-03 11:43:29 UTC 15h left Thu 2018-08-02 16:54:52 UTC 3h 7min ago certbot.timer certbot.service
        Fri 2018-08-03 12:44:58 UTC 16h left Thu 2018-08-02 19:14:58 UTC 47min ago apt-daily.timer apt-daily.service
        Fri 2018-08-03 19:43:44 UTC 23h left Thu 2018-08-02 19:43:44 UTC 18min ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
        Mon 2018-08-06 00:00:00 UTC 3 days left Mon 2018-07-30 00:00:09 UTC 3 days ago fstrim.timer fstrim.service


        The certbot timer should be here /lib/systemd/system/certbot.timer and it will execute the command specified in /lib/systemd/system/certbot.service



        certbot.timer will execute the `certbot.service at 12 am and 12 pm, after a random delay of up to 12 hours (43200 seconds).



        # cat /lib/systemd/system/certbot.timer
        [Unit]
        Description=Run certbot twice daily

        [Timer]
        OnCalendar=*-*-* 00,12:00:00
        RandomizedDelaySec=43200
        Persistent=true

        [Install]
        WantedBy=timers.target


        and certbot.service will execute the renew command.



        # cat /lib/systemd/system/certbot.service
        [Unit]
        Description=Certbot
        Documentation=file:///usr/share/doc/python-certbot-doc/html/index.html
        Documentation=https://letsencrypt.readthedocs.io/en/latest/
        [Service]
        Type=oneshot
        ExecStart=/usr/bin/certbot -q renew
        PrivateTmp=true


        cron job



        As others have mentioned, there is also a cron job installed in /etc/cron.d/certbot:



        # Eventually, this will be an opportunity to validate certificates
        # haven't been revoked, etc. Renewal will only occur if expiration
        # is within 30 days.
        SHELL=/bin/sh
        PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

        0 */12 * * * root test -x /usr/bin/certbot -a ! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew


        This is doing:




        • test -x /usr/bin/certbot -a ! -d /run/systemd/system - check if /usr/bin/certbot is an executable file and that /run/systemd/system is not a directory. Only continue to the next bit if this check succeeds.

          • The systemd part of the check effectively means that if systemd is running, don't run certbot from the cron job - leave that to the timer.



        • perl -e 'sleep int(rand(43200))' - sleep a random amount between 0 seconds and 12 hours (43200 = 12 x 60 x 60).


        • certbot -q renew check your certificates and renew any if required. The -q flag is "quiet" - don't produce any output unless there is an error.

        I was originally confused by the cron job as it wasn't going to run due to systemd, so how would certbot be run? I found the answer in this forum post which is what I based this answer on.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Aug 2 '18 at 20:14









        Hamish DownerHamish Downer

        6,64753048




        6,64753048












        • "You shouldn't have to set up anything" but my cert expired recently, and I installed certbot about 3 months ago. /etc/cron.d/certbot exists, systemctl list-timers shows certbot.timer, but my certs weren't renewed. Running certbot manually worked fine, so I don't know what's going on. Ended up adding an old school crontab entry.

          – Dan Dascalescu
          Oct 16 '18 at 5:20











        • This is the most up to date and correct answer but with a caveat that it depends on what dist you are running: certbot.eff.org/docs/using.html#id8

          – olive_tree
          Nov 22 '18 at 20:16

















        • "You shouldn't have to set up anything" but my cert expired recently, and I installed certbot about 3 months ago. /etc/cron.d/certbot exists, systemctl list-timers shows certbot.timer, but my certs weren't renewed. Running certbot manually worked fine, so I don't know what's going on. Ended up adding an old school crontab entry.

          – Dan Dascalescu
          Oct 16 '18 at 5:20











        • This is the most up to date and correct answer but with a caveat that it depends on what dist you are running: certbot.eff.org/docs/using.html#id8

          – olive_tree
          Nov 22 '18 at 20:16
















        "You shouldn't have to set up anything" but my cert expired recently, and I installed certbot about 3 months ago. /etc/cron.d/certbot exists, systemctl list-timers shows certbot.timer, but my certs weren't renewed. Running certbot manually worked fine, so I don't know what's going on. Ended up adding an old school crontab entry.

        – Dan Dascalescu
        Oct 16 '18 at 5:20





        "You shouldn't have to set up anything" but my cert expired recently, and I installed certbot about 3 months ago. /etc/cron.d/certbot exists, systemctl list-timers shows certbot.timer, but my certs weren't renewed. Running certbot manually worked fine, so I don't know what's going on. Ended up adding an old school crontab entry.

        – Dan Dascalescu
        Oct 16 '18 at 5:20













        This is the most up to date and correct answer but with a caveat that it depends on what dist you are running: certbot.eff.org/docs/using.html#id8

        – olive_tree
        Nov 22 '18 at 20:16





        This is the most up to date and correct answer but with a caveat that it depends on what dist you are running: certbot.eff.org/docs/using.html#id8

        – olive_tree
        Nov 22 '18 at 20:16











        5














        For LetsEncrypt certificate renewal, I generally use getssl. It is a very handy shell wrapper which can even install certificate on other machines via SSH connection.



        The cron entry is the following:



        01 23 * * * root /root/scripts/getssl/getssl -u -a -q >>/var/log/getssl.log 2>&1 ; /usr/sbin/apache2ctl graceful



        As already suggested, you should run it daily or, even better, twice a day.






        share|improve this answer



























          5














          For LetsEncrypt certificate renewal, I generally use getssl. It is a very handy shell wrapper which can even install certificate on other machines via SSH connection.



          The cron entry is the following:



          01 23 * * * root /root/scripts/getssl/getssl -u -a -q >>/var/log/getssl.log 2>&1 ; /usr/sbin/apache2ctl graceful



          As already suggested, you should run it daily or, even better, twice a day.






          share|improve this answer

























            5












            5








            5







            For LetsEncrypt certificate renewal, I generally use getssl. It is a very handy shell wrapper which can even install certificate on other machines via SSH connection.



            The cron entry is the following:



            01 23 * * * root /root/scripts/getssl/getssl -u -a -q >>/var/log/getssl.log 2>&1 ; /usr/sbin/apache2ctl graceful



            As already suggested, you should run it daily or, even better, twice a day.






            share|improve this answer













            For LetsEncrypt certificate renewal, I generally use getssl. It is a very handy shell wrapper which can even install certificate on other machines via SSH connection.



            The cron entry is the following:



            01 23 * * * root /root/scripts/getssl/getssl -u -a -q >>/var/log/getssl.log 2>&1 ; /usr/sbin/apache2ctl graceful



            As already suggested, you should run it daily or, even better, twice a day.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 9 '17 at 9:46









            shodanshokshodanshok

            27.8k35192




            27.8k35192





















                3














                As already mentioned by glaux:




                Note: if you're setting up a cron or systemd job, we recommend running
                it twice per day (it won't do anything until your certificates are due
                for renewal or revoked, but running it regularly would give your site
                a chance of staying online in case a Let's Encrypt-initiated
                revocation happened for some reason). Please select a random minute
                within the hour for your renewal tasks.




                Source: https://certbot.eff.org/all-instructions/#debian-8-jessie-apache



                So i ended up using this (running is twice a day, at 01:00 and at 13:00 everyday):



                6 1,13 * * * certbot renew --post-hook "service apache2 restart"


                or even better:



                6 1,13 * * * certbot renew --renew-hook "service apache2 restart"


                I didn't test but this should work also:



                6 1,13 * * * certbot renew --post-hook "/etc/init.d/apache2 restart"
                6 1,13 * * * certbot renew --renew-hook "/etc/init.d/apache2 restart"



                --pre-hook and --post-hook hooks run before and after every renewal attempt. If you want your hook to run only after a successful renewal,
                use --renew-hook in a command like this.




                Source: https://certbot.eff.org/docs/using.html






                share|improve this answer




















                • 1





                  "Please select a random minute within the hour for your renewal tasks."

                  – Isius
                  Aug 17 '17 at 15:55






                • 1





                  Per my note above, you'd be better off with --renew-hook, which restarts your server only when the cert is actually renewed.

                  – Whatcould
                  Aug 18 '17 at 1:48











                • @Isius thanks, i changed it to a random minute (6).

                  – Tadej
                  Aug 18 '17 at 6:19






                • 1





                  @JedatKinports: shouldn't the --post-hook and --renew-hook be service apache2 restart instead of service restart apache2?

                  – Paul Ratazzi
                  Apr 13 '18 at 18:29







                • 1





                  The command is service apache2 restart! The service restart apache2 isn't correct command/service.

                  – GTodorov
                  Jun 12 '18 at 15:33















                3














                As already mentioned by glaux:




                Note: if you're setting up a cron or systemd job, we recommend running
                it twice per day (it won't do anything until your certificates are due
                for renewal or revoked, but running it regularly would give your site
                a chance of staying online in case a Let's Encrypt-initiated
                revocation happened for some reason). Please select a random minute
                within the hour for your renewal tasks.




                Source: https://certbot.eff.org/all-instructions/#debian-8-jessie-apache



                So i ended up using this (running is twice a day, at 01:00 and at 13:00 everyday):



                6 1,13 * * * certbot renew --post-hook "service apache2 restart"


                or even better:



                6 1,13 * * * certbot renew --renew-hook "service apache2 restart"


                I didn't test but this should work also:



                6 1,13 * * * certbot renew --post-hook "/etc/init.d/apache2 restart"
                6 1,13 * * * certbot renew --renew-hook "/etc/init.d/apache2 restart"



                --pre-hook and --post-hook hooks run before and after every renewal attempt. If you want your hook to run only after a successful renewal,
                use --renew-hook in a command like this.




                Source: https://certbot.eff.org/docs/using.html






                share|improve this answer




















                • 1





                  "Please select a random minute within the hour for your renewal tasks."

                  – Isius
                  Aug 17 '17 at 15:55






                • 1





                  Per my note above, you'd be better off with --renew-hook, which restarts your server only when the cert is actually renewed.

                  – Whatcould
                  Aug 18 '17 at 1:48











                • @Isius thanks, i changed it to a random minute (6).

                  – Tadej
                  Aug 18 '17 at 6:19






                • 1





                  @JedatKinports: shouldn't the --post-hook and --renew-hook be service apache2 restart instead of service restart apache2?

                  – Paul Ratazzi
                  Apr 13 '18 at 18:29







                • 1





                  The command is service apache2 restart! The service restart apache2 isn't correct command/service.

                  – GTodorov
                  Jun 12 '18 at 15:33













                3












                3








                3







                As already mentioned by glaux:




                Note: if you're setting up a cron or systemd job, we recommend running
                it twice per day (it won't do anything until your certificates are due
                for renewal or revoked, but running it regularly would give your site
                a chance of staying online in case a Let's Encrypt-initiated
                revocation happened for some reason). Please select a random minute
                within the hour for your renewal tasks.




                Source: https://certbot.eff.org/all-instructions/#debian-8-jessie-apache



                So i ended up using this (running is twice a day, at 01:00 and at 13:00 everyday):



                6 1,13 * * * certbot renew --post-hook "service apache2 restart"


                or even better:



                6 1,13 * * * certbot renew --renew-hook "service apache2 restart"


                I didn't test but this should work also:



                6 1,13 * * * certbot renew --post-hook "/etc/init.d/apache2 restart"
                6 1,13 * * * certbot renew --renew-hook "/etc/init.d/apache2 restart"



                --pre-hook and --post-hook hooks run before and after every renewal attempt. If you want your hook to run only after a successful renewal,
                use --renew-hook in a command like this.




                Source: https://certbot.eff.org/docs/using.html






                share|improve this answer















                As already mentioned by glaux:




                Note: if you're setting up a cron or systemd job, we recommend running
                it twice per day (it won't do anything until your certificates are due
                for renewal or revoked, but running it regularly would give your site
                a chance of staying online in case a Let's Encrypt-initiated
                revocation happened for some reason). Please select a random minute
                within the hour for your renewal tasks.




                Source: https://certbot.eff.org/all-instructions/#debian-8-jessie-apache



                So i ended up using this (running is twice a day, at 01:00 and at 13:00 everyday):



                6 1,13 * * * certbot renew --post-hook "service apache2 restart"


                or even better:



                6 1,13 * * * certbot renew --renew-hook "service apache2 restart"


                I didn't test but this should work also:



                6 1,13 * * * certbot renew --post-hook "/etc/init.d/apache2 restart"
                6 1,13 * * * certbot renew --renew-hook "/etc/init.d/apache2 restart"



                --pre-hook and --post-hook hooks run before and after every renewal attempt. If you want your hook to run only after a successful renewal,
                use --renew-hook in a command like this.




                Source: https://certbot.eff.org/docs/using.html







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jun 18 '18 at 7:43

























                answered Jul 5 '17 at 9:49









                TadejTadej

                21124




                21124







                • 1





                  "Please select a random minute within the hour for your renewal tasks."

                  – Isius
                  Aug 17 '17 at 15:55






                • 1





                  Per my note above, you'd be better off with --renew-hook, which restarts your server only when the cert is actually renewed.

                  – Whatcould
                  Aug 18 '17 at 1:48











                • @Isius thanks, i changed it to a random minute (6).

                  – Tadej
                  Aug 18 '17 at 6:19






                • 1





                  @JedatKinports: shouldn't the --post-hook and --renew-hook be service apache2 restart instead of service restart apache2?

                  – Paul Ratazzi
                  Apr 13 '18 at 18:29







                • 1





                  The command is service apache2 restart! The service restart apache2 isn't correct command/service.

                  – GTodorov
                  Jun 12 '18 at 15:33












                • 1





                  "Please select a random minute within the hour for your renewal tasks."

                  – Isius
                  Aug 17 '17 at 15:55






                • 1





                  Per my note above, you'd be better off with --renew-hook, which restarts your server only when the cert is actually renewed.

                  – Whatcould
                  Aug 18 '17 at 1:48











                • @Isius thanks, i changed it to a random minute (6).

                  – Tadej
                  Aug 18 '17 at 6:19






                • 1





                  @JedatKinports: shouldn't the --post-hook and --renew-hook be service apache2 restart instead of service restart apache2?

                  – Paul Ratazzi
                  Apr 13 '18 at 18:29







                • 1





                  The command is service apache2 restart! The service restart apache2 isn't correct command/service.

                  – GTodorov
                  Jun 12 '18 at 15:33







                1




                1





                "Please select a random minute within the hour for your renewal tasks."

                – Isius
                Aug 17 '17 at 15:55





                "Please select a random minute within the hour for your renewal tasks."

                – Isius
                Aug 17 '17 at 15:55




                1




                1





                Per my note above, you'd be better off with --renew-hook, which restarts your server only when the cert is actually renewed.

                – Whatcould
                Aug 18 '17 at 1:48





                Per my note above, you'd be better off with --renew-hook, which restarts your server only when the cert is actually renewed.

                – Whatcould
                Aug 18 '17 at 1:48













                @Isius thanks, i changed it to a random minute (6).

                – Tadej
                Aug 18 '17 at 6:19





                @Isius thanks, i changed it to a random minute (6).

                – Tadej
                Aug 18 '17 at 6:19




                1




                1





                @JedatKinports: shouldn't the --post-hook and --renew-hook be service apache2 restart instead of service restart apache2?

                – Paul Ratazzi
                Apr 13 '18 at 18:29






                @JedatKinports: shouldn't the --post-hook and --renew-hook be service apache2 restart instead of service restart apache2?

                – Paul Ratazzi
                Apr 13 '18 at 18:29





                1




                1





                The command is service apache2 restart! The service restart apache2 isn't correct command/service.

                – GTodorov
                Jun 12 '18 at 15:33





                The command is service apache2 restart! The service restart apache2 isn't correct command/service.

                – GTodorov
                Jun 12 '18 at 15:33











                1














                This is what I use:



                /opt/letsencrypt/letsencrypt-auto renew


                gives output as:



                Upgrading certbot-auto 0.8.1 to 0.9.1...
                Replacing certbot-auto...
                Creating virtual environment...
                ...
                new certificate deployed with reload of apache server; fullchain is
                /etc/letsencrypt/live/host.simplecoin.cz/fullchain.pem
                -------------------------------------------------------------------------------

                Congratulations, all renewals succeeded. The following certs have been renewed:
                /etc/letsencrypt/live/host.simplecoin.cz/fullchain.pem (success)


                And its saying that apache is restarted already, so no need to do it over again. If I run it again:



                Cert not yet due for renewal


                therefore it's not problem to renew certificate daily, my cron is then:



                @daily /opt/letsencrypt/cronautorenew.sh


                I use script to tweak logging to separate file, so here is my cronautorenew.sh:



                #!/usr/bin/env bash
                printf "nattempt to renew certificates" >>/var/log/letsencrypt_cron.log 2>&1
                date >>/var/log/letsencrypt_cron.log 2>&1
                /opt/letsencrypt/letsencrypt-auto renew >>/var/log/letsencrypt_cron.log 2>&1
                printf "renew finishedn" >>/var/log/letsencrypt_cron.log 2>&1





                share|improve this answer



























                  1














                  This is what I use:



                  /opt/letsencrypt/letsencrypt-auto renew


                  gives output as:



                  Upgrading certbot-auto 0.8.1 to 0.9.1...
                  Replacing certbot-auto...
                  Creating virtual environment...
                  ...
                  new certificate deployed with reload of apache server; fullchain is
                  /etc/letsencrypt/live/host.simplecoin.cz/fullchain.pem
                  -------------------------------------------------------------------------------

                  Congratulations, all renewals succeeded. The following certs have been renewed:
                  /etc/letsencrypt/live/host.simplecoin.cz/fullchain.pem (success)


                  And its saying that apache is restarted already, so no need to do it over again. If I run it again:



                  Cert not yet due for renewal


                  therefore it's not problem to renew certificate daily, my cron is then:



                  @daily /opt/letsencrypt/cronautorenew.sh


                  I use script to tweak logging to separate file, so here is my cronautorenew.sh:



                  #!/usr/bin/env bash
                  printf "nattempt to renew certificates" >>/var/log/letsencrypt_cron.log 2>&1
                  date >>/var/log/letsencrypt_cron.log 2>&1
                  /opt/letsencrypt/letsencrypt-auto renew >>/var/log/letsencrypt_cron.log 2>&1
                  printf "renew finishedn" >>/var/log/letsencrypt_cron.log 2>&1





                  share|improve this answer

























                    1












                    1








                    1







                    This is what I use:



                    /opt/letsencrypt/letsencrypt-auto renew


                    gives output as:



                    Upgrading certbot-auto 0.8.1 to 0.9.1...
                    Replacing certbot-auto...
                    Creating virtual environment...
                    ...
                    new certificate deployed with reload of apache server; fullchain is
                    /etc/letsencrypt/live/host.simplecoin.cz/fullchain.pem
                    -------------------------------------------------------------------------------

                    Congratulations, all renewals succeeded. The following certs have been renewed:
                    /etc/letsencrypt/live/host.simplecoin.cz/fullchain.pem (success)


                    And its saying that apache is restarted already, so no need to do it over again. If I run it again:



                    Cert not yet due for renewal


                    therefore it's not problem to renew certificate daily, my cron is then:



                    @daily /opt/letsencrypt/cronautorenew.sh


                    I use script to tweak logging to separate file, so here is my cronautorenew.sh:



                    #!/usr/bin/env bash
                    printf "nattempt to renew certificates" >>/var/log/letsencrypt_cron.log 2>&1
                    date >>/var/log/letsencrypt_cron.log 2>&1
                    /opt/letsencrypt/letsencrypt-auto renew >>/var/log/letsencrypt_cron.log 2>&1
                    printf "renew finishedn" >>/var/log/letsencrypt_cron.log 2>&1





                    share|improve this answer













                    This is what I use:



                    /opt/letsencrypt/letsencrypt-auto renew


                    gives output as:



                    Upgrading certbot-auto 0.8.1 to 0.9.1...
                    Replacing certbot-auto...
                    Creating virtual environment...
                    ...
                    new certificate deployed with reload of apache server; fullchain is
                    /etc/letsencrypt/live/host.simplecoin.cz/fullchain.pem
                    -------------------------------------------------------------------------------

                    Congratulations, all renewals succeeded. The following certs have been renewed:
                    /etc/letsencrypt/live/host.simplecoin.cz/fullchain.pem (success)


                    And its saying that apache is restarted already, so no need to do it over again. If I run it again:



                    Cert not yet due for renewal


                    therefore it's not problem to renew certificate daily, my cron is then:



                    @daily /opt/letsencrypt/cronautorenew.sh


                    I use script to tweak logging to separate file, so here is my cronautorenew.sh:



                    #!/usr/bin/env bash
                    printf "nattempt to renew certificates" >>/var/log/letsencrypt_cron.log 2>&1
                    date >>/var/log/letsencrypt_cron.log 2>&1
                    /opt/letsencrypt/letsencrypt-auto renew >>/var/log/letsencrypt_cron.log 2>&1
                    printf "renew finishedn" >>/var/log/letsencrypt_cron.log 2>&1






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Oct 10 '16 at 11:50









                    Pavel NiedobaPavel Niedoba

                    14419




                    14419





















                        0














                        According to EFF certbot guide




                        Many Linux distributions provide automated renewal when you use the
                        packages installed through their system package manager.




                        If you are not sure whether or not your system has this already automated, check your system’s crontab (typically in /etc/crontab/ and /etc/cron.*/* $ crontab -l and systemd timers $ systemctl list-timers.






                        share|improve this answer



























                          0














                          According to EFF certbot guide




                          Many Linux distributions provide automated renewal when you use the
                          packages installed through their system package manager.




                          If you are not sure whether or not your system has this already automated, check your system’s crontab (typically in /etc/crontab/ and /etc/cron.*/* $ crontab -l and systemd timers $ systemctl list-timers.






                          share|improve this answer

























                            0












                            0








                            0







                            According to EFF certbot guide




                            Many Linux distributions provide automated renewal when you use the
                            packages installed through their system package manager.




                            If you are not sure whether or not your system has this already automated, check your system’s crontab (typically in /etc/crontab/ and /etc/cron.*/* $ crontab -l and systemd timers $ systemctl list-timers.






                            share|improve this answer













                            According to EFF certbot guide




                            Many Linux distributions provide automated renewal when you use the
                            packages installed through their system package manager.




                            If you are not sure whether or not your system has this already automated, check your system’s crontab (typically in /etc/crontab/ and /etc/cron.*/* $ crontab -l and systemd timers $ systemctl list-timers.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered May 12 at 23:51









                            SuhaybSuhayb

                            1011




                            1011



























                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Server Fault!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f790772%2fcron-job-for-lets-encrypt-renewal%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

                                Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

                                What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company