From 6c2bf36dab31b9edad6191b916ee473a60fb3e83 Mon Sep 17 00:00:00 2001 From: Andreas Linz Date: Thu, 17 Mar 2016 12:37:15 +0100 Subject: [PATCH] Add systemd unit file and some usage instructions Add systemd service file for caddy Add some README with basic setup instructions Explain how to view the service configuration Add a note about permissions Add a comment about run user and group service->service unit A systemd service can consist of different units. A unit configuration file has the `.service` file ending which is a bit confusing, so please be considerate if I'm confusing `service` and `unit` in the README Fix typos/reword Add contact information --- dist/init/linux-systemd/README.md | 40 ++++++++++++++++++++++++++ dist/init/linux-systemd/caddy@.service | 21 ++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 dist/init/linux-systemd/README.md create mode 100644 dist/init/linux-systemd/caddy@.service diff --git a/dist/init/linux-systemd/README.md b/dist/init/linux-systemd/README.md new file mode 100644 index 000000000..e18f75243 --- /dev/null +++ b/dist/init/linux-systemd/README.md @@ -0,0 +1,40 @@ +# systemd unit for caddy + +Please do not hesitate to ask [me](mailto:klingt.net+caddy@gmail.com) if you've any questions. + +## Quickstart + +- install the unit configuration file: `cp caddy@.service /etc/systemd/system` +- reload the systemd daemon: `systemctl deamon-reload` +- make sure to [configure](#configuration) the service unit before starting caddy +- start caddy: `systemctl start caddy@someuser` +- enable the service (automatically start on boot): `systemctl enable caddy@someuser` +- the `.caddy` folder will be created inside the users home directory that runs caddy, i.e. `/home/someuser/.caddy` for `systemctl start caddy@someuser` + +## Configuration + +- do not edit the systemd unit directly, use systemd's builtin tools: + - `systemctl edit caddy@` to make user local modifications to the service unit + - `systemctl edit --full caddy@` to make system-wide modifications +- in most cases it's enough to adapt the `ExecStart` directive: + - `systemctl edit caddy@` + - systemd needs absolute paths, therefore make sure that the path to caddy is correct + - example: + +```ini +[Service] +; reset the original setting +ExecStart= +ExecStart=/usr/bin/caddy -conf="/etc/caddy/myCaddy.conf" -agree -email="my@mail.address" +``` + +- to view your configuration use `systemctl cat caddy@` +- double check the permissions of your web root path to make sure that caddy can access it as its run user and group + +## Tips + +- use `log stdout` and `errors stderr` in your Caddyfile to make use of `journalctl` +- `journalctl` is systemd's log query tool +- lets say you want all the log entries for caddy since the last boot beginning from the last entry: `journalctl --reverse --boot --unit caddy@someuser` +- maybe you want to follow caddys log output: `journalctl -fu caddy@someuser` +- to send a signal to a service units main PID, e.g. let caddy reload its config: `systemctl kill --signal=USR1 caddy@someuser` diff --git a/dist/init/linux-systemd/caddy@.service b/dist/init/linux-systemd/caddy@.service new file mode 100644 index 000000000..7bb4f552a --- /dev/null +++ b/dist/init/linux-systemd/caddy@.service @@ -0,0 +1,21 @@ +; see `man systemd.unit` for configuration details +; the man section also explains *specifiers* `%x` + +[Unit] +Description=Caddy HTTP/2 web server %I +Documentation=https://caddyserver.com/docs +After=network.target + +[Service] +; run user and group for caddy +User=%i +Group=http +ExecStart=/usr/bin/caddy -agree=true -conf=/etc/caddy/Caddyfile +Restart=on-failure +; create a private temp folder that is not shared with other processes +PrivateTmp=true +; limit the number of file descriptors, see `man systemd.exec` for more limit settings +LimitNOFILE=8192 + +[Install] +WantedBy=multi-user.target