Can't start Caddy as systemd service due to "Network service is not active"

Following Cannot start Caddy as a systemd service :

I have the exact same issue. Caddy works just fine by launching it as a command line, but service fails to start and I have this errors in the syslog :

Aug 24 11:11:14 voiretmanger systemd[1]: Network Service is not active.
Aug 24 11:11:14 voiretmanger systemd[1]: Dependency failed for Wait for Network to be Configured.
Aug 24 11:11:14 voiretmanger systemd[1]: systemd-networkd-wait-online.service: Job systemd-networkd-wait-online.service/start failed with result 'dependency'.
Aug 24 11:11:14 voiretmanger systemd[1]: Started Caddy HTTP/2 web server.

I’m using the official Caddy service and everything was working fine for several months, until I had to update my Caddyfile to add a site.

I tried to find the solution in the previous thread mentioned earlier, but I was not able to make it work. If I remove the systemd-networkd-wait-online.service directive, I don’t have the network error in the syslog, but Caddy does not start either. It just fails silently, as far as I can tell. If there is log somewhere indicating what’s happening, I have not found it.

Here’s the output of a service status :

➜  ~ service caddy status
● caddy.service - Caddy HTTP/2 web server
   Loaded: loaded (/home/nicolas/config/etc/systemd/system/caddy.service; enabled; vendor preset: enabled)
   Active: active (running) since ven. 2018-08-24 11:11:14 CEST; 5min ago
     Docs: https://caddyserver.com/docs
  Process: 14160 ExecReload=/bin/kill -USR1 $MAINPID (code=exited, status=0/SUCCESS)
 Main PID: 14286 (caddy)
    Tasks: 7
   Memory: 10.0M
      CPU: 165ms
   CGroup: /system.slice/caddy.service
           └─14286 /usr/local/bin/caddy -agree=true -email=nicolinux@gmail.com -conf=/etc/caddy/Caddyfile -root=/var/www

août 24 11:11:14 voiretmanger systemd[1]: Started Caddy HTTP/2 web server.
août 24 11:12:59 voiretmanger systemd[1]: Started Caddy HTTP/2 web server.

The service file is visible here, the caddyfile is available here. I’m running Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-133-generic x86_64).

Let me know if you need more information.

OK, I feel stupid. The error with Network service not active was not at fault, the service could not get a certificate for one domain. :man_facepalming:

I was not seing any error, since I forgot to add the -log stdout directive in my service. With this change, I was able to see the error with this domain and now the service works just fine.

One thing though : why did it work using the command line and not the service then ? Moreover, the certificate is indeed stored inside the sites subfolder where SSL certificates are stored. I don’t understand why the service could not use it… :thinking:

Anyway, sorry for this post. Maybe it will be useful for somebody else…