Caddy won't start

1. Output of caddy version:

v2.5.2 h1:eCJdLyEyAGzuQTa5Mh3gETnYWDClo1LjtQm2q9RNZrs=

2. How I run Caddy:

a. System environment:

AlmaLinux 8.6

b. Command:

systemctl start caddy

c. Service/unit/compose file:

[root@sub ~]# systemctl cat caddy
# /run/systemd/generator.late/caddy.service
# Automatically generated by systemd-sysv-generator

[Unit]
Documentation=man:systemd-sysv-generator(8)
SourcePath=/etc/rc.d/init.d/caddy
Description=LSB: It can help you improve network speed
Before=multi-user.target
Before=multi-user.target
Before=multi-user.target
Before=graphical.target
After=network-online.target
Wants=network-online.target

[Service]
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
SuccessExitStatus=5 6
ExecStart=/etc/rc.d/init.d/caddy start
ExecStop=/etc/rc.d/init.d/caddy stop
[root@sub~]# systemctl status caddy
● caddy.service - LSB: It can help you improve network speed
   Loaded: loaded (/etc/rc.d/init.d/caddy; generated)
   Active: active (exited) since Tue 2022-08-02 22:25:31 EDT; 8h ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1379 ExecStart=/etc/rc.d/init.d/caddy start (code=exited, status=0/SUCCESS)
    Tasks: 0 (limit: 4945)
   Memory: 0B
   CGroup: /system.slice/caddy.service

Aug 02 22:25:30 sub.example.com systemd[1]: Starting LSB: It can help you improve network speed...
Aug 02 22:25:31 sub.example.com caddy[1379]: Starting caddy success
Aug 02 22:25:31 sub.example.com systemd[1]: Started LSB: It can help you improve network speed.

d. My complete Caddy config:

sub.example.com:443 {
     header {
        Strict-Transport-Security "max-age=31536000; includeSubDomains"
        -Server
    }
    encode gzip
    log {
        output file /var/log/caddy-access.log
        format json
    }
    tls /root/.acme.sh/sub.example.com_ecc/fullchain.cer /root/.acme.sh/sub.example.com_ecc/sub.example.com.key {
        protocols tls1.3
    }
    reverse_proxy /dueIU localhost:11563   
    reverse_proxy 127.0.0.1:8563 {
        #
    }
}

3. The problem I’m having:

Everything works just fine except I cannot start Caddy after I manually stop it if I use systemctl start caddy Restarting Caddy also fails with systemctl restart caddy I have to reboot the server to get Caddy to run again.

4. Error messages and/or full log output:

Aug 02 22:07:23 cloud.servutech.com caddy[1863]: Starting caddy failed
Aug 02 22:07:23 cloud.servutech.com systemd[1]: caddy.service: Control process exited, code=exited status=1
Aug 02 22:07:23 cloud.servutech.com systemd[1]: caddy.service: Failed with result 'exit-code'.
Aug 02 22:07:23 cloud.servutech.com systemd[1]: Failed to start LSB: It can help you improve network speed.
Aug 02 22:07:49 cloud.servutech.com systemd[1]: caddy.service: Found left-over process 1872 (caddy) in control group while starting unit. Ignoring.
Aug 02 22:07:49 cloud.servutech.com systemd[1]: This usually indicates unclean termination of a previous run, or service implementation deficiencies.
Aug 02 22:07:49 cloud.servutech.com systemd[1]: Starting LSB: It can help you improve network speed...
Aug 02 22:07:49 cloud.servutech.com caddy[1895]: /etc/rc.d/init.d/caddy: line 33: [: 1872: binary operator expected
Aug 02 22:07:49 cloud.servutech.com caddy[1895]: Starting caddy failed
Aug 02 22:07:49 cloud.servutech.com systemd[1]: caddy.service: Control process exited, code=exited status=1
Aug 02 22:07:49 cloud.servutech.com systemd[1]: caddy.service: Failed with result 'exit-code'.
Aug 02 22:07:49 cloud.servutech.com systemd[1]: Failed to start LSB: It can help you improve network speed.

5. What I already tried:

6. Links to relevant resources:

Hi @jeffshead, could you include your unit file and Caddy config?

2 Likes

I added the unit and Caddy config to the original post.

The Caddy installation was automated via a Github script which is just one part of a web app.

The official, supported unit file for using Caddy with systemd is here: https://github.com/caddyserver/dist/blob/2831baf7660fd84ad36789fc0ead6fd33118115b/init/caddy.service

It appears your unit file uses that init script as an alternative to interacting with the Caddy binary directly, as in the officially distributed version.

We might still be able to help figure out what’s going on, though.

The log output indicates there is an error with this script, /etc/rc.d/init.d/caddy.

Can you share its contents? Can you also please link that installer script?

2 Likes

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