Caddy runs fine from command line, but not as a service

I’ve been trying things for the last hout, with no luck. Here’s where I’m at:

My Caddyfile is at /home/caddy/Caddyfile
‘caddy’ is at /usr/local/bin/caddy
/usr/local/bin/caddy -log stdout -agree=true -conf=/home/caddy/Caddyfile runs fin when logged in as the caddy user

Contents of /etc/systemd/system/caddy.service

[Unit]
Description=Caddy HTTP/2 web server
Documentation=https://caddyserver.com/docs
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service

[Service]
Restart=on-failure
StartLimitInterval=86400
StartLimitBurst=5

; User and group the process will run as.
User=caddy
Group=caddy

; Letsencrypt-issued certificates will be written to this directory.
# Environment=CADDYPATH=/etc/ssl/caddy

; Always set "-root" to something safe in case it gets forgotten in the Caddyfile.
ExecStart=/usr/local/bin/caddy -log stdout -agree=true -conf=/home/caddy/Caddyfile
# -root=/var/tmp
ExecReload=/bin/kill -USR1 $MAINPID

; Limit the number of file descriptors; see `man systemd.exec` for more limit settings.
LimitNOFILE=1048576
; Unmodified caddy is not expected to use more than that.
LimitNPROC=64

; Use private /tmp and /var/tmp, which are discarded after caddy stops.
# PrivateTmp=true
; Use a minimal /dev
# PrivateDevices=true
; Hide /home, /root, and /run/user. Nobody will steal your SSH-keys.
# ProtectHome=true
; Make /usr, /boot, /etc and possibly some more folders read-only.
ProtectSystem=full
; … except /etc/ssl/caddy, because we want Letsencrypt-certificates there.
;   This merely retains r/w access rights, it does not add any new. Must still be writable on the host!
# ReadWriteDirectories=/etc/ssl/caddy

; The following additional security directives only work with systemd v229 or later.
; They further retrict privileges that can be gained by caddy. Uncomment if you like.
; Note that you may have to add capabilities required by any plugins in use.
;CapabilityBoundingSet=CAP_NET_BIND_SERVICE
;AmbientCapabilities=CAP_NET_BIND_SERVICE
;NoNewPrivileges=true

[Install]
WantedBy=multi-user.target

An excerpt from sudo journalctl -u caddy:

Jun 18 12:17:04 Yamato systemd[1]: Started Caddy HTTP/2 web server.
Jun 18 12:17:04 Yamato caddy[18518]: Activating privacy features... done.
Jun 18 12:17:04 Yamato caddy[18518]: From http://25.4.88.33:3000/Minecraft/Launcher
Jun 18 12:17:04 Yamato caddy[18518]:  * branch            update-site -> FETCH_HEAD
Jun 18 12:17:04 Yamato caddy[18518]: Already up-to-date.
Jun 18 12:17:04 Yamato caddy[18518]: 2017/06/18 12:17:04 http://25.4.88.33:3000/Minecraft/Launcher.git pulled.
Jun 18 12:17:04 Yamato systemd[1]: caddy.service: Main process exited, code=exited, status=1/FAILURE
Jun 18 12:17:04 Yamato systemd[1]: caddy.service: Unit entered failed state.
Jun 18 12:17:04 Yamato systemd[1]: caddy.service: Failed with result 'exit-code'.
Jun 18 12:17:04 Yamato systemd[1]: caddy.service: Service hold-off time over, scheduling restart.
Jun 18 12:17:04 Yamato systemd[1]: Stopped Caddy HTTP/2 web server.

Does anyone know what’s up? I’m extremely confused.

It may have been in combination with a few other things, but it was finally solved when I gave my error log an absolute path. Weird.

Oh, and I disabled systemd-networkd-wait-online.service in Wants

It’s usually possible to replace this with your system’s network manager. Not sure what your system is, but as an example I believe Ubuntu 16.04 ships with Network Manager, and the service you want to target for it is networkmanager-wait-online.service.

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