Salut à tous,
Je me permets de répondre à ce post même s’il est déjà résolu.
J’ai eu exactement le même problème que Kapu06 mais je n’ai pas trouvé mon
bonheur dans le post: j’ai corrigé le problème d’une manière différente.
Le tutoriel dont Kapu06 fait mention propose un script pour automatiser le renew
du certificat:
https://raw.githubusercontent.com/alexAubin/letsencrypt_ynh/131a7071faea0f1374faf04784024e7cab69703a/sources/certificateRenewer
Ce script doit être copié dans le répertoire: /etc/cron.weekly
Dans ce script, le programme ${LEBIN} est exécuté (le tutoriel y fait mention en
tant que “/root/letsencrypt/letsencrypt-auto”) avec le nom de domaine en option.
Ce nom de domaine est obtenu avec une commande grep dans le fichier
${LERENEWAL}, dans mon cas: “/etc/letsencrypt/renewal”.
Malheureuement, avec mon installation, la commande grep renvoie une chaine vide
à la place du nom de domaine. Du coup, j’ai l’erreur “Requested domain is not a
FQDN” (où on devrait voir apparaitre le nom de domaine).
En effet, le programme exécute la commande suivante:
/root/letsencrypt/letsencrypt-auto certonly
–renew-by-default
–config “/etc/letsencrypt/conf.ini”
–domains ""
Qui renvoie l’erreur en question.
Dans mon cas, le nom de domaine est identique au nom du certificat (il me semble
que c’est un cas particulier).
Donc, j’ai modifié la fonction “renewCertificate” dans le script pour utiliser
le nom du certificat dans le cas où la commande grep renvoie une chaine vide, la
fonction ressemle maintenant à ça:
function renewCertificate()
{
local CERT_NAME=$1
local LOG_FILE=$2
rm ${LOG_FILE}
touch ${LOG_FILE}
local CERT_FILE="${LELIVE}/${CERT_NAME}/cert.pem"
local CERT_CONF="${LERENEWAL}/${CERT_NAME}.conf"
# Parse "domains = xxxx", we might need to remove the last character
# if it's a comma
local DOMAINS=$(grep -o --perl-regex "(?<=domains \= ).*" "${CERT_CONF}")
if [ "${DOMAINS}" = "" ]
then
echo "Unable to define domain from file: ${CERT_CONF}" > ${LOG_FILE} 2>&1
echo "Trying to use certificate name as domain: ${CERT_NAME}" >> ${LOG_FILE}
DOMAINS=${CERT_NAME}
fi
local LAST_CHAR=$(echo ${DOMAINS} | awk '{print substr($0,length,1)}')
if [ "${LAST_CHAR}" = "," ]
then
local DOMAINS=$(echo ${DOMAINS} |awk '{print substr($0, 1, length-1)}')
fi
# Recreate the webroot folder (expected to be in /tmp/)
WEBROOT_PATH=$(cat $CERT_CONF \
| grep webroot_path \
| tr ',' ' ' \
| awk '{print $3}')
mkdir -p ${WEBROOT_PATH}
${LEBIN} certonly \
--renew-by-default \
--config "${LECFG}" \
--domains "${DOMAINS}" \
>> ${LOG_FILE} 2>&1
}
J’ai essayé de renouveler le certificat avec cette nouvelle version et ça a
fonctionné. Maintenant, je suis sûr que mon cron weekly va renouveler comme
attendu.
Same message in english:
Hello everyone,
I feel like I had to add some informations even if the post has already been
closed.
I had the exact same problem as Kapu06 but the post did not help me to resolve
it: I used a different method.
The tutorial Kapu06 mentioned explains how to get a script to automatize the
renew of the certificate:
https://raw.githubusercontent.com/alexAubin/letsencrypt_ynh/131a7071faea0f1374faf04784024e7cab69703a/sources/certificateRenewer
This script must be located in directory: /etc/cron.weekly
In this script, program ${LEBIN} is executed (the tutorial refers to it as
"/root/letsencrypt/letsencrypt-auto") with the domain name as option. This
domain name must be obtained through grep command in file ${LERENEWAL},
"/etc/letsencrypt/renewal" in my case.
Unfortunately, with my installation, the grep command returned an empty string
instead of the domain name. Hence the error message “Requested domain is not a
FQDN” (the domain name should appear in this string).
Indeed, the program executes the following command:
/root/letsencrypt/letsencrypt-auto certonly
–renew-by-default
–config “/etc/letsencrypt/conf.ini”
–domains ""
Which returns the error message.
In my case, the domain name is identical to the certificate name (it seems to be
a particular case).
So, basically, I modified the “renewCertificate” function in the script to use
the certificate name as domain name in case grep command returns an empty
string, the function is now as follows:
function renewCertificate()
{
local CERT_NAME=$1
local LOG_FILE=$2
rm ${LOG_FILE}
touch ${LOG_FILE}
local CERT_FILE="${LELIVE}/${CERT_NAME}/cert.pem"
local CERT_CONF="${LERENEWAL}/${CERT_NAME}.conf"
# Parse "domains = xxxx", we might need to remove the last character
# if it's a comma
local DOMAINS=$(grep -o --perl-regex "(?<=domains \= ).*" "${CERT_CONF}")
if [ "${DOMAINS}" = "" ]
then
echo "Unable to define domain from file: ${CERT_CONF}" > ${LOG_FILE} 2>&1
echo "Trying to use certificate name as domain: ${CERT_NAME}" >> ${LOG_FILE}
DOMAINS=${CERT_NAME}
fi
local LAST_CHAR=$(echo ${DOMAINS} | awk '{print substr($0,length,1)}')
if [ "${LAST_CHAR}" = "," ]
then
local DOMAINS=$(echo ${DOMAINS} |awk '{print substr($0, 1, length-1)}')
fi
# Recreate the webroot folder (expected to be in /tmp/)
WEBROOT_PATH=$(cat $CERT_CONF \
| grep webroot_path \
| tr ',' ' ' \
| awk '{print $3}')
mkdir -p ${WEBROOT_PATH}
${LEBIN} certonly \
--renew-by-default \
--config "${LECFG}" \
--domains "${DOMAINS}" \
>> ${LOG_FILE} 2>&1
}
I tried to renew the certificate using this new version and in worked. Now I am
sure that my weekly cron will renew them as expected.
alb