Supervised Caddy
Jan 31, 2017Caddy, the HTTP/2 web server with automatic HTTPS, is easy to configure and use. The release package contains information about executing Caddy as a service, e.g. with Systemd or Upstart.
This post shows a configuration using Supervisor a process control and monitoring system. Benefits are: reboot safe execution, automatic restart after crashes and execution as a non-root user.
The following steps were tried on Ubuntu 14.04/16.04 and Debian 8.
Prepare Caddy
- Copy the Caddy executable to
/usr/local/bin
. If you use any plugins (e.g. Hugo) you might want to copy other required binaries as well. - Create directory for log files:
mkdir /var/log/caddy
chown www-data:www-data /var/log/caddy
- Create working directory for Caddy:
mkdir -p /etc/caddy/ssl
chown www-data:www-data /etc/caddy/ssl
- Copy your Caddyfile to
/etc/caddy
. Logfiles should be written to/var/log/caddy
. - Allow Caddy to use privileged ports
setcap cap_net_bind_service=+ep /usr/local/bin/caddy
Prepare Supervisor
- Install the required package:
sudo apt-get install supervisor
- Create
/etc/supervisor/conf.d/caddy.conf
[program:caddy]
command=/usr/local/bin/caddy -agree=true -email=<your mail> -conf=/etc/caddy/Caddyfile
environment=CADDYPATH=/etc/caddy/ssl
directory=/var/log/caddy
user=www-data
stdout_logfile=/var/log/caddy/caddy.log
stderr_logfile=/var/log/caddy/caddy.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs=600
startretries=3
Manage Caddy execution
Supervised processes can be managed using supervisorctl
.
# supervisorctl status
caddy RUNNING pid 954, uptime 1 day, 21:16:16
root@mschoebel:~# supervisorctl restart caddy
caddy: stopped
caddy: started
Caddy output (e.g. during startup) is written to /var/log/caddy/caddy.log
.
Tweet Follow @schoebel