Unable to lunch caddy on ubuntu 16 with systemd

I did an update to ubuntu 16.04. and now I try to replace upstart with systemd. But for now I was not able to get caddy running with systemd. When I start it with sudo ./caddy -conf="/etc/caddy/Caddyfile" the websites are running. But unfortunately not with systemd.

My systemd file:

   [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 -email email@xyz.com  -agree=true -conf=/etc/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

Do you know what to do here?
Which permissions are correct to set up?
/etc/ssl/caddy
/usr/local/bin/caddy
/etc/caddy/Caddyfile
/var/www/

Caddy is v0.10.3

forgot to post the logfile. Here it is:

-- Logs begin at Fr 2017-06-16 10:36:18 CEST. --
Jun 16 14:06:44 v22016043535433702 systemd[1]: Started Caddy HTTP/2 web server.
Jun 16 14:06:44 v22016043535433702 caddy[4262]: Activating privacy features... done.
Jun 16 14:06:44 v22016043535433702 caddy[4262]: 2017/06/16 14:06:44 open access.log: permission denied
Jun 16 14:06:44 v22016043535433702 systemd[1]: caddy.service: Main process exited, code=exited, status=1/FAILURE
Jun 16 14:06:44 v22016043535433702 systemd[1]: caddy.service: Unit entered failed state.
Jun 16 14:06:44 v22016043535433702 systemd[1]: caddy.service: Failed with result 'exit-code'.
Jun 16 14:06:44 v22016043535433702 systemd[1]: caddy.service: Service hold-off time over, scheduling restart.
Jun 16 14:06:44 v22016043535433702 systemd[1]: Stopped Caddy HTTP/2 web server.
Jun 16 14:06:44 v22016043535433702 systemd[1]: caddy.service: Start request repeated too quickly.
Jun 16 14:06:44 v22016043535433702 systemd[1]: Failed to start Caddy HTTP/2 web server.

ok finally it works now. Just thought that I have not to look into the Caddyfile because it worked manuel. That was terrible wrong of course.
It was just because of the permission for error log. www-data was writing error log into the caddy folder which is owned by root.
I deleted the error log in the Caddyfile and it works now.

Do you have any suggestions were to safe the error log? Would you safe it in /etc/caddy/ ?

I bet you can add a /var/log/caddy directory to created by systemd's tmpfiles.d(5) with the correct permissions so that www-data can write there.

Some more reference in a ServerFault quesion and the source where I found this in an askubuntu question.

2 Likes

thank you very much!

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