Hi, I'm using certbot 0.3.1 (python).
I have several domains and I created a script containing a command necessary to run to contatenate private and public certificates for haproxy. Here the script:
#!/bin/bash
DOMAIN=$1
FULLCHAIN_PATH="/etc/letsencrypt/live/${DOMAIN}/fullchain.pem"
PRIVKEY_PATH="/etc/letsencrypt/live/${DOMAIN}/privkey.pem"
CERT_PATH="/etc/letsencrypt/live/${DOMAIN}/haproxy_cert.pem"
cat "${FULLCHAIN_PATH}" "${PRIVKEY_PATH}" > "${CERT_PATH}"
systemctl restart haproxy
I saved the script at /etc/letsencrypt/renewal-hooks/deploy/concatenate_for_haproxy.sh
If I run this script manually (to test it), via shell, like this:
./concatenate_for_haproxy.sh mydomain.com
It works perfectly fine: it concatenates the 2 pem files and restarts haproxy.
The problem is that it doesn't work automatically, as I would like it to work.
I was hoping to have a universal way to configure this, instead, for each domain, I had to create a conf file inside /etc/letsencrypt/renewal-hooks/deploy
And for each domain I the conf looks like this:
/etc/letsencrypt/renewal-hooks/deploy/domain1.com.conf
deploy-hook = "/etc/letsencrypt/renewal-hooks/deploy/concatenate_for_haproxy.sh domain1.com"
What I noticed several times (it drives me nuts and finally I took the time to come to ask for some support) is that when the certificates are renewed, my script is called, but I see a 0 bytes file located at /etc/letsencrypt/live/haproxy_cert.pem
Expected: a file with contents concatenated at /etc/letsencrypt/live/domain1.com/haproxy_cert.pem
So, I think the issue is that the argument that it should pass to the sh script I created, is not passed to it.
So in my domain1.com, this doesn't work (notice domain1.com
passed as argument tot he sh script):
deploy-hook = "/etc/letsencrypt/renewal-hooks/deploy/concatenate_for_haproxy.sh domain1.com"
I would like to avoid copying the sh file and edit it for each file, I actualy think it's also not efficient to have a different conf file for each domain that does the same thing.
Imagine if I had 1000 domains, I would need o have 1000 conf files pointing to 1000 copies of the same sh file? See what I mean, it's quite inefficient.
But if there is no way to do this in an elegent "centralized" way using just one script as I prepared concatenate_for_haproxy.sh
my workaround will be the following:
Make a copy of concatenate_for_haproxy.sh
for each domain, then instead of getting the argument as I'm getting it now via $1, I will just edit it manually in the file. Then call the copy of concatenate_for_haproxy.sh
for each domain, e.g. renamed to concatenate_for_haproxy-domain1-com.sh
without passing domain1.com
as argument in the conf file...
Is the conf file really not supporting to add an argument to a command to call?
Maybe the argument needs to be scaped differently or so, forgive me if I didn't get that.
Thanks in advance for your help, hope to solve this in an elegant way, cheers