Search code examples
bashcronroothaproxy

Crontab and haproxy


I have a strange behavior which i do not understand: I'm running haproxy as loadbalancer and security shield in front of other web containers.

The haproxy is running fine and uses my configured letsencrypt file.

So far so fine.

When the ssl certificate is running out, a new one including all needed key files is generated and replaces the key files.

After that, the haproxy must reload its config.

Now: when i call

cd /etc/haproxy
service haproxy reload

or the script itself from commandline, everything runs absolutely fine.

As soon as i call it via cron, it doesn't work!?!? There is no error, and the reconfigure script is run till its end. /etc/haproxy/bin/request_letsencrypt_certificate.sh:

#!/bin/bash
cd /etc/haproxy
service haproxy reload

crontab -e as root:

 # LetsEnrcrypt | recert
    * * * * * /etc/haproxy/bin/request_letsencrypt_certificate.sh

(i changed to run every minute for testing purposes) When using echo test>run.txt the file is created every minute, so the script is started successfully, but the service command seems to be not executed?

What could be thy problem, why on commandline it works, but from cron not?

Both action are taken with root permissions as root itself (and when dumping the user in cron-call via whoami in the script, "root" is confirmed at runtime)


Solution

  • Does it work if you change service to /sbin/service to ensure that it's in the PATH? You also probably don't need cd /etc/haproxy in the script.