Startup of Caddy (2) before Redis is ready

1. The problem I’m having:

I am using REDIS-SERVER for cerificate storage. When rebooting the server (Ubuntu), CADDY won’t start due to connection failure with the REDIS-SERVER.
It is not ready for any connection (yet).

2. Error messages and/or full log output:

caddy[837]: Error: loading initial config: loading new config: loading storage module: loading module 'redis': provision caddy.storage.redis: dial tcp 127.0.0.1:6379: connect: connection refused

3. Caddy version:

v2.7.6 h1:w0NymbG2m9PcvKWsrXO6EEkY9Ru4FJK8uQbYcev1p3A=

4. How I installed and ran Caddy:

Caddy installed by APT install caddy

a. System environment:

OS Ubuntu server 22.04 LTS

b. Command:

c. Service/unit/compose file:

d. My complete Caddy config:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

5. Links to relevant resources:

Sorry, the first message and did not know how that worked.
I would like to have a solution to delay the start of CADDY or that the startup of CADDY is done after REDIS is ready to accept a connection.

Anyone a suggestion?

I think systemd has a way of configuring a unit (such as Caddy) to not start until after another one has… but I’m not sure how to do that tbh.

1 Like

You might be able to do it like this inside the caddy systemd unit file.

[Unit]
After=network.target redis.service
Wants=redis.service

With After= you make sure that caddy starts after network becomes available and after redis.service, and additionally with Wants= it will try to start redis before it starts itself.

This implied your unit file for redis is called redis.service.

2 Likes

You can also configure Caddy’s service to restart on failure, see the systemd overrides docs:

Also, consider using GitHub - pberkel/caddy-storage-redis instead which is a more modern/polished Redis plugin for Caddy. It does have a different store model though so Caddy will issue new certs unless you export/import the existing certs when swapping. If you only have a handful of certs, you don’t need to do migrate anything, you can just let Caddy issue fresh certificates.

1 Like

Hi Fransislavoie, I do use the pberkel plugin, thanks.
And I will look into the systemd options. However I am not interested in a situation where caddy in invitit restarting.
Regards, Rick.

Hi Monviech,
I will look for this configuration. Seems to me the option I am looking for.
Let you know if that worked.
Regards,
Rick.

I have modified the caddy.service according to your advice:

[Unit]
Description=Caddy
Documentation=Welcome — Caddy Documentation
After=network.target network-online.target redis.service
Requires=network-online.target
Wants= redis.service

This file is located at:
/lib/systemd/system on Ubuntu 22.04 Server

Test: After a reboot, no failures on start of Caddy. It looks good.

2 Likes

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