Want Caddy to run automatically on boot

Hi, New to Caddy, I would like to have Caddy start automatically on reboot. I’m running Caddy as a reverse proxy on Centos 7 operating system. I’d like to have Caddy start when I boot the computer its running on. This is in case of power fail or the hypervisor needs to reboot etc. Can someone give directions or point me to resources that explain how to do it.

I’ve searched this form for:

  • start auto boot
  • systemd Centos
    but haven’t found what I’m looking for.

Thanks, I enjoy how Caddy obtains certificates for you automatically using Let’s Encrypt!!

You can find an example systemd service here, but here’s mine:

/etc/systemd/systemd/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-abnormal
LimitNOFILE=16384

EnvironmentFile=/etc/default/caddy

ExecStart=/usr/local/bin/caddy -log stdout -ca=${TLS_CA} -agree=true -conf=${CONFIG_FILE} -root=${ROOT_DIR} -email ${TLS_EMAIL} -port ${DEFAULT_PORT}
ExecReload=/bin/kill -USR1 $MAINPID

; Use graceful shutdown with a reasonable timeout
KillMode=mixed
KillSignal=SIGQUIT
TimeoutStopSec=5s

[Install]
WantedBy=multi-user.target

/etc/default/caddy

# Caddy Defaults
CONFIG_FILE="/mnt/web-balancer/caddy.cf"
DEFAULT_PORT="80"

## CloudFlare
CF_API_EMAIL="<email>"
CF_API_KEY="<API>"

## TLS Options
TLS_EMAIL="pki@domain.com"
# Staging
#TLS_CA="https://acme-staging-v02.api.letsencrypt.org/directory"
# Production
#TLS_CA="https://acme-v02.api.letsencrypt.org/directory"
# Caddy uses this for it's home directory
# https://caddyserver.com/docs/automatic-https
CADDYPATH="/mnt/web-balancer/"
ROOT_DIR="/mnt/web-balancer"

All of our (community-maintained) init script examples are here:

https://github.com/mholt/caddy/tree/master/dist/init/

OK, Thanks for the help. I used the directions at: https://github.com/mholt/caddy/tree/master/dist/init/linux-systemd
3 things: GID 33 was already in use on Centos 7 for tape drive access. You can see what groups are in use by: cat /etc/group I used 34 instread. Also needed to sudo yum install wget. For reverse proxy only setup, where you are not serving files, you can skip setting up the /var/www directory steps.

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