Unable to launch caddy on Ubuntu 16

I have a stock Unbuntu 16.06 droplet from DigitalOcean. I installed caddy with the tutorial caddy file and that worked. I then pointed a domain to the server and updated the caddy file. Now no matter what I do the caddy service will not start/restart. It constantly gets:

Started Caddy HTTP/2 web server.
Network Service is not active.
Dependency failed for Wait for Network to be Configured.

even with

sudo systemctl daemon-reload
sudo systemctl reset-failed
sudo systemctl start caddy

nothing happens.

Hi @ahwulf, welcome to the Caddy community.

Can you let us know what your systemd unit file looks like (systemctl cat caddy)?

[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=www-data
Group=www-data

; 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=/etc/caddy/Caddyfile -root=/var
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 o
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

I’m not on DigitalOcean (although I love their guides), but does their stock Ubuntu install come with systemd-networkd or does it come with NetworkManager?

You might need to change the line to the following if it’s the latter:

Wants=network-online.target networkmanager-wait-online.service

Now I get a different problem.

Where can caddy write a log file if its running as user www-data? All the places I’ve tried have permission denied which seems to kill the launch.

But without a log file it runs now. Not used to running things on linux.

NM I figured it out. Thanks for the help!

For anyone else who might be looking, my understanding is that the usual procedure is to log to stdout, which should get picked up by systemd-journald. Other than that, ensuring the directory you want to write your logs to is group-writable and group-owned by www-data is a good way to go about it.

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