cert-renewer@.service 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. [Unit]
  2. Description=Certificate renewer for %I
  3. After=network-online.target
  4. Documentation=https://smallstep.com/docs/step-ca/certificate-authority-server-production
  5. StartLimitIntervalSec=0
  6. [Service]
  7. Type=oneshot
  8. User=root
  9. Environment=STEPPATH=/etc/step-ca \
  10. CERT_LOCATION=/etc/step/certs/%i.crt \
  11. KEY_LOCATION=/etc/step/certs/%i.key
  12. ; ExecStartPre checks if the certificate is ready for renewal,
  13. ; based on the exit status of the command.
  14. ; (In systemd 243 and above, you can use ExecCondition= here.)
  15. ExecStartPre=/usr/bin/bash -c \
  16. 'step certificate inspect $CERT_LOCATION --format json --roots "$STEPPATH/certs/root_ca.crt" | \
  17. jq -e "(((.validity.start | fromdate) + \
  18. ((.validity.end | fromdate) - (.validity.start | fromdate)) * 0.66) \
  19. - now) <= 0" > /dev/null'
  20. ; ExecStart renews the certificate, if ExecStartPre was successful.
  21. ExecStart=/usr/bin/step ca renew --force $CERT_LOCATION $KEY_LOCATION
  22. ; Try to reload or restart the systemd service that relies on this cert-renewer
  23. ExecStartPost=/usr/bin/bash -c 'systemctl --quiet is-enabled %i && systemctl try-reload-or-restart %i'
  24. [Install]
  25. WantedBy=multi-user.target