caddy.service 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. {{ ansible_managed | comment(decoration="; ") }}
  2. ; source: https://github.com/mholt/caddy/blob/master/dist/init/linux-systemd/caddy.service
  3. ; version: 6be0386
  4. ; changes: Set variables via Ansible
  5. [Unit]
  6. Description=Caddy HTTP/2 web server
  7. Documentation=https://caddyserver.com/docs
  8. After=network-online.target
  9. {% if caddy_systemd_network_dependency == true %}
  10. Wants=network-online.target systemd-networkd-wait-online.service
  11. {% endif %}
  12. {% if caddy_systemd_version | int >= 230 %}
  13. StartLimitIntervalSec={{ caddy_systemd_restart_startlimitinterval }}
  14. StartLimitBurst={{ caddy_systemd_restart_startlimitburst }}
  15. {% endif %}
  16. [Service]
  17. Restart={{ caddy_systemd_restart }}
  18. {% if caddy_systemd_version | int < 230 %}
  19. StartLimitInterval={{ caddy_systemd_restart_startlimitinterval }}
  20. StartLimitBurst={{ caddy_systemd_restart_startlimitburst }}
  21. {% endif %}
  22. ; User and group the process will run as.
  23. User={{ caddy_user }}
  24. Group={{ caddy_user }}
  25. ; Letsencrypt-issued certificates will be written to this directory.
  26. Environment=CADDYPATH={{ caddy_certs_dir }}
  27. ExecStart="{{ caddy_bin_dir }}/caddy" run --environ --config "{{ caddy_conf_dir }}/Caddyfile" {{ caddy_additional_args }}
  28. ExecReload="{{ caddy_bin_dir }}/caddy" reload --config "{{ caddy_conf_dir }}/Caddyfile"
  29. ; Limit the number of file descriptors; see `man systemd.exec` for more limit settings.
  30. LimitNOFILE=1048576
  31. {% if caddy_systemd_nproc_limit > 0 %}
  32. ; Limit the number of caddy threads.
  33. LimitNPROC={{ caddy_systemd_nproc_limit }}
  34. {% endif %}
  35. ; Use private /tmp and /var/tmp, which are discarded after caddy stops.
  36. PrivateTmp={{ caddy_systemd_private_tmp }}
  37. ; Use a minimal /dev
  38. PrivateDevices={{ caddy_systemd_private_devices }}
  39. ; Hide /home, /root, and /run/user. Nobody will steal your SSH-keys.
  40. ProtectHome={{ caddy_systemd_protect_home }}
  41. ; Make /usr, /boot, /etc and possibly some more folders read-only.
  42. ProtectSystem={{ caddy_systemd_protect_system }}
  43. ; … except {{ caddy_certs_dir }}, because we want Letsencrypt-certificates there.
  44. ; This merely retains r/w access rights, it does not add any new. Must still be writable on the host!
  45. ReadWriteDirectories={{ caddy_certs_dir }}
  46. {% if caddy_systemd_capabilities_enabled %}
  47. ; The following additional security directives only work with systemd v229 or later.
  48. ; They further retrict privileges that can be gained by caddy.
  49. ; Note that you may have to add capabilities required by any plugins in use.
  50. CapabilityBoundingSet={{ caddy_systemd_capabilities }}
  51. AmbientCapabilities={{ caddy_systemd_capabilities }}
  52. NoNewPrivileges=true
  53. {% endif %}
  54. {% if caddy_environment_variables|length %}
  55. ; Additional environment variables:
  56. {% for key, value in caddy_environment_variables.items() %}
  57. Environment={{ key }}={{ value }}
  58. {% endfor %}
  59. {% endif %}
  60. [Install]
  61. WantedBy=multi-user.target