Can't start Caddy with systemd service file no error shown

1. Caddy version (caddy version):

v2.4.3 h1:Y1FaV2N4WO3rBqxSYA8UZsZTQdN+PwcoOcAiZTM8C0I=

2. How I run Caddy:

I use a systemd service file, sudo systemctl start caddy
The file is down below.

a. System environment:

CentOS7

b. Command:

sudo systemctl start caddy

c. Service/unit/compose file:

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target

[Service]
Type=notify
User=mobiuspod
Group=mobiuspod
ExecStart=/usr/bin/caddy run --environ --config /home/mobiuspod/mobiuspod/application/third_party/mercure/Caddyfile
ExecReload=/usr/bin/caddy reload --config /home/mobiuspod/mobiuspod/application/third_party/mercure/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

d. My complete Caddyfile or JSON config:

# Learn how to configure the Mercure.rocks Hub on https://mercure.rocks/docs/hub/config
{
    http_port 4133
    https_port 4134

    # Debug mode (disable it in production!)
    {$DEBUG}
    # HTTP/3 support
    servers {
        protocol {
            experimental_http3
        }
    }
}

{$SERVER_NAME:mercure.mobiuspod.com}

tls /etc/ssl/private/mercure_mobiuspod_com.cert.pem /etc/ssl/private/mercure_mobiuspod_com.key.pem

log {
    output file /home/mobiuspod/caddy_access.log
}
route {
    encode zstd gzip
    
    mercure {
        # Transport to use (default to Bolt)
        transport_url {$MERCURE_TRANSPORT_URL:bolt://mercure.db}
        # Publisher JWT key
        publisher_jwt xxxxxx
        # Subscriber JWT key
        subscriber_jwt xxxxxx
        # Extra directives
        {$MERCURE_EXTRA_DIRECTIVES}
    }

    respond /healthz 200

    respond "Not Found" 404
}

3. The problem I’m having:

When I run caddy with systemd all seems to work from the log but systemd just ends with caddy service failed and no reason is shown in the logs see below.

### 4. Error messages and/or full log output:
[root@host mercure]# journalctl -xef -u caddy.service
-- Logs begin at Sun 2021-08-15 02:00:34 EDT. --
Aug 17 06:54:03 host.server.biz systemd[1]: Starting Caddy...
-- Subject: Unit caddy.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit caddy.service has begun starting up.
Aug 17 06:54:03 host.server.biz caddy[59214]: caddy.HomeDir=/home/mobiuspod
Aug 17 06:54:03 host.server.biz caddy[59214]: caddy.AppDataDir=/home/mobiuspod/.local                         /share/caddy
Aug 17 06:54:03 host.server.biz caddy[59214]: caddy.AppConfigDir=/home/mobiuspod/.con                         fig/caddy
Aug 17 06:54:03 host.server.biz caddy[59214]: caddy.ConfigAutosavePath=/home/mobiuspo                         d/.config/caddy/autosave.json
Aug 17 06:54:03 host.server.biz caddy[59214]: caddy.Version=v2.4.3 h1:Y1FaV2N4WO3rBqx                         SYA8UZsZTQdN+PwcoOcAiZTM8C0I=
Aug 17 06:54:03 host.server.biz caddy[59214]: runtime.GOOS=linux
Aug 17 06:54:03 host.server.biz caddy[59214]: runtime.GOARCH=amd64
Aug 17 06:54:03 host.server.biz caddy[59214]: runtime.Compiler=gc
Aug 17 06:54:03 host.server.biz caddy[59214]: runtime.NumCPU=4
Aug 17 06:54:03 host.server.biz caddy[59214]: runtime.GOMAXPROCS=4
Aug 17 06:54:03 host.server.biz caddy[59214]: runtime.Version=go1.16
Aug 17 06:54:03 host.server.biz caddy[59214]: os.Getwd=/
Aug 17 06:54:03 host.server.biz caddy[59214]: LANG=en_US.UTF-8
Aug 17 06:54:03 host.server.biz caddy[59214]: PATH=/usr/local/sbin:/usr/local/bin:/us                         r/sbin:/usr/bin
Aug 17 06:54:03 host.server.biz caddy[59214]: NOTIFY_SOCKET=/run/systemd/notify
Aug 17 06:54:03 host.server.biz caddy[59214]: HOME=/home/mobiuspod
Aug 17 06:54:03 host.server.biz caddy[59214]: LOGNAME=mobiuspod
Aug 17 06:54:03 host.server.biz caddy[59214]: USER=mobiuspod
Aug 17 06:54:03 host.server.biz caddy[59214]: SHELL=/bin/bash
Aug 17 06:54:03 host.server.biz caddy[59214]: {"level":"info","ts":1629197643.230864,                         "msg":"using provided configuration","config_file":"/home/mobiuspod/mobiuspod/application/thir                         d_party/mercure/Caddyfile","config_adapter":""}
Aug 17 06:54:03 host.server.biz caddy[59214]: {"level":"warn","ts":1629197643.2321334                         ,"msg":"input is not formatted with 'caddy fmt'","adapter":"caddyfile","file":"/home/mobiuspod                         /mobiuspod/application/third_party/mercure/Caddyfile","line":3}
Aug 17 06:54:03 host.server.biz caddy[59214]: {"level":"info","ts":1629197643.2330837                         ,"logger":"admin","msg":"admin endpoint started","address":"tcp/localhost:2019","enforce_origi                         n":false,"origins":["localhost:2019","[::1]:2019","127.0.0.1:2019"]}
Aug 17 06:54:03 host.server.biz caddy[59214]: {"level":"info","ts":1629197643.2332985                         ,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"                         0xc00037e7e0"}
Aug 17 06:54:03 host.server.biz caddy[59214]: {"level":"info","ts":1629197643.233713,                         "logger":"http","msg":"skipping automatic certificate management because one or more matching                          certificates are already loaded","domain":"mercure.mobiuspod.com","server_name":"srv0"}
Aug 17 06:54:03 host.server.biz caddy[59214]: {"level":"info","ts":1629197643.233724,                         "logger":"http","msg":"enabling automatic HTTP->HTTPS redirects","server_name":"srv0"}
Aug 17 06:54:03 host.server.biz systemd[1]: Started Caddy.
-- Subject: Unit caddy.service has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit caddy.service has finished starting up.
--
-- The start-up result is done.
Aug 17 06:54:03 host.server.biz systemd[1]: caddy.service: main process exited, code=                         exited, status=1/FAILURE
Aug 17 06:54:03 host.server.biz systemd[1]: Unit caddy.service entered failed state.
Aug 17 06:54:03 host.server.biz systemd[1]: caddy.service failed.


5. What I already tried:

6. Links to relevant resources:

OK, I fixed it myself by using this caddy.service file

[Unit]
Description=Caddy webserver
Documentation=https://caddyserver.com/
After=network.target

[Service]
User=mobiuspod
#Group=some_group
WorkingDirectory=/home/mobiuspod
LimitNOFILE=4096
ExecStart=/usr/bin/caddy run --environ --config /home/mobiuspod/mobiuspod/application/third_party/mercure/Caddyfile
Restart=on-failure
StartLimitInterval=600

[Install]
WantedBy=multi-user.target

We strongly recommend using the systemd service file we crafted for Caddy.

Since you’re running on ubuntu, you can install Caddy from our APT repo, then since you’re using a custom build of Caddy, you can replace the binary with these instructions, so you continue to get updates to the support files:

1 Like

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