Letsencrypt renew not working with cronjob, manually it works


#1

hi there,

I’ve troubles with the letsencrypt renew script.
I’ve added an cronjob on my debian 8 server with the following command

0 6 1 * * /root/.local/share/letsencrypt/bin/letsencrypt renew

in the logs I’ve got the following error:

2016-05-01 04:00:06,689:INFO:letsencrypt.cli:Could not choose appropriate plugin: The apache plugin is not working; there may be problems with your existing configuration.
The error was: NoInstallationError()
2016-05-01 04:00:06,690:WARNING:letsencrypt.cli:Attempting to renew cert from /etc/letsencrypt/renewal/xxx.conf produced an unexpected error: The apache plugin is not working; there may be problems with your existing configuration.
The error was: NoInstallationError(). Skipping.

but if I execute the same command manually, it workes without any errors

my letsencrypt version is 0.4.2


Renew runs but always fails in crontab, works in shell
#2

When something runs fine manually but fails when put in crontab, the most common reason is that the environment cron sees is not quite the same as yours. Basically if you do “env”, you will see a bunch of environment variables (such as PATH, etc). If whatever you run as cron relies on any of those variables, but they are missing - the task will fail. Some scripts can even fail if you don’t do “cd” into particular directory before executing the command :slight_smile:


#3

hm, so what to do excactly? :confused:


#4

I’m not using the official client, but you could start with changing into the directory where the script is before executing it and see if that helped. You can simply add either

cd /root/.local/share/letsencrypt/bin/ &&
or
cd /root/.local/share/letsencrypt/bin/ ;

before the command.

The difference is that in the former case the command will be executed if directory change actually worked, in the latter it will be executed regardless of the “cd” outcome.


#5

Something else you could perhaps try.

  • Create a bash script with your renew command-line in it.
  • Make it executable
  • Run the bash script manually to see if it works
  • Then automate the running of that bash script from Cron.

I prefer doing things this way with bash scripts because things sometimes can go wrong with passing command line’s directly to cron.

Just my five cents worth, hope it helps.


#6

thanks for you answers, I’ll try it and will post again with the result


#7

I’ve made an bash script with the following commands

#!/bin/sh

cd /root/.local/share/letsencrypt/bin/
/root/.local/share/letsencrypt/bin/letsencrypt renew

but I’ve got the same errors in the letsencrypt log file

2016-06-14 07:50:04,907:DEBUG:letsencrypt.storage:Should renew, less than 30 days before certificate expiry 2016-05-16 13:24:00 UTC.
2016-06-14 07:50:04,907:INFO:letsencrypt.cli:Cert is due for renewal, auto-renewing...
2016-06-14 07:50:04,910:DEBUG:letsencrypt.cli:Requested authenticator apache and installer apache
2016-06-14 07:50:04,912:DEBUG:letsencrypt.plugins.disco:No installation (PluginEntryPoint#apache): 
Traceback (most recent call last):
  File "/root/.local/share/letsencrypt/local/lib/python2.7/site-packages/letsencrypt/plugins/disco.py", line 103, in prepare
    self._initialized.prepare()
  File "/root/.local/share/letsencrypt/local/lib/python2.7/site-packages/letsencrypt_apache/configurator.py", line 152, in prepare
    raise errors.NoInstallationError
NoInstallationError
2016-06-14 07:50:04,912:DEBUG:letsencrypt.display.ops:No candidate plugin
2016-06-14 07:50:04,912:DEBUG:letsencrypt.display.ops:No candidate plugin
2016-06-14 07:50:04,912:DEBUG:letsencrypt.cli:Selected authenticator None and installer None
2016-06-14 07:50:04,912:INFO:letsencrypt.cli:Could not choose appropriate plugin: The apache plugin is not working; there may be problems with your existing configuration.
The error was: NoInstallationError()

am I really the only one who wants to auto renew the letsencrypt certificate with an cronjob on debian? :pensive:

if I run the script manually it works…


#8

As I said earlier, it is usually because the cron sees a bit different environment. You may need to export extended PATH in that script you have created. See this thread as a reference on fixing similar issue:


#9

thanks again, the other thread showed the solution

my .bash script now looks like this:

#!/bin/sh

PATH=output of echo $PATH
/root/.local/share/letsencrypt/bin/letsencrypt renew

and now it works


Crontab renew fails
#10

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.