본문으로 건너뛰기
  1. Memo/

Caddy의 systemd 서비스

·
서버 Linux Caddy
작성자
hw5e
page.hw5e.cc

패키지 관리자를 통해 caddy를 설치한 경우 보통 서비스를 자동으로 만들어 줄 것이다. 소스를 직접 빌드하거나 바이너리만 따로 받아서 설치한 경우 공식 문서에서 서비스를 직접 등록하는 법을 알려준다 caddy 공식 문서에는 직접 서비스를 생성하는 법을 알려주고 패키지 매니저로 설치하면 보통 이걸 자동으로 해준다.

[rocky@instance-rocky ~]$ sudo cat /usr/lib/systemd/system/caddy.service 
# caddy.service
#
# For using Caddy with a config file.
#
# Make sure the ExecStart and ExecReload commands are correct
# for your installation.
#
# See https://caddyserver.com/docs/install for instructions.
#
# WARNING: This service does not use the --resume flag, so if you
# use the API to make changes, they will be overwritten by the
# Caddyfile next time the service is restarted. If you intend to
# use Caddy's API to configure it, add the --resume flag to the
# `caddy run` command or use the caddy-api.service file instead.

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target

[Service]
Type=notify
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile --force
TimeoutStopSec=5s
LimitNOFILE=1048576
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

caddy는 nginx와는 달리 기본적으로 /etc/caddy/Caddyfile이 기본값으로 설정된 것이 아니라 서비스에서 실행될 때 인수로 caddy파일을 지정하는 것으로 보인다. 그리고 nginx에서는 nginx.conf에서 nginx의 사용자를 지정하는데 caddy는 서비스에서 사용자와 그룹을 caddy로 지정한다.

systemctl을 통해 실행한다면 caddy가 접근하는 파일들이 caddy 유저, 그룹이 접근할 수 있어야 한다.

Reply by Email