systemd.service 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. [Unit]
  2. Description=flohmarkt server
  3. After=network.target couchdb.service
  4. [Service]
  5. Type=simple
  6. User=__APP__
  7. Group=__APP__
  8. WorkingDirectory=__FLOHMARKT_APP_DIR__
  9. Environment='VENV_DIR=__FLOHMARKT_VENV_DIR__' 'LANG=en_GB.UTF-8'
  10. ExecStart=/bin/bash -c "set -o pipefail; __FLOHMARKT_VENV_DIR__/bin/uvicorn --factory --host 127.0.0.1 --port __PORT__ flohmarkt.web:start 2>&1 | /usr/bin/ts '%%Y-%%m-%%d %%H:%%M:%%S'"
  11. Restart=on-failure
  12. RestartSec=5s
  13. # nicer logfile naming https://codeberg.org/flohmarkt/flohmarkt_ynh/issues/38
  14. StandardOutput=append:__FLOHMARKT_LOGFILE__
  15. StandardError=inherit
  16. # Sandboxing options to harden security
  17. # Depending on specificities of your service/app, you may need to tweak these
  18. # .. but this should be a good baseline
  19. # Details for these options: https://www.freedesktop.org/software/systemd/man/systemd.exec.html
  20. NoNewPrivileges=yes
  21. PrivateTmp=yes
  22. PrivateDevices=yes
  23. RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
  24. RestrictNamespaces=yes
  25. RestrictRealtime=yes
  26. DevicePolicy=closed
  27. ProtectSystem=full
  28. ProtectControlGroups=yes
  29. ProtectKernelModules=yes
  30. ProtectKernelTunables=yes
  31. LockPersonality=yes
  32. SystemCallFilter=~@clock @debug @module @mount @obsolete @reboot @setuid @swap
  33. # Denying access to capabilities that should not be relevant for webapps
  34. # Doc: https://man7.org/linux/man-pages/man7/capabilities.7.html
  35. CapabilityBoundingSet=~CAP_RAWIO CAP_MKNOD
  36. CapabilityBoundingSet=~CAP_AUDIT_CONTROL CAP_AUDIT_READ CAP_AUDIT_WRITE
  37. CapabilityBoundingSet=~CAP_SYS_BOOT CAP_SYS_TIME CAP_SYS_MODULE CAP_SYS_PACCT
  38. CapabilityBoundingSet=~CAP_LEASE CAP_LINUX_IMMUTABLE CAP_IPC_LOCK
  39. CapabilityBoundingSet=~CAP_BLOCK_SUSPEND CAP_WAKE_ALARM
  40. CapabilityBoundingSet=~CAP_SYS_TTY_CONFIG
  41. CapabilityBoundingSet=~CAP_MAC_ADMIN CAP_MAC_OVERRIDE
  42. CapabilityBoundingSet=~CAP_NET_ADMIN CAP_NET_BROADCAST CAP_NET_RAW
  43. CapabilityBoundingSet=~CAP_SYS_ADMIN CAP_SYS_PTRACE CAP_SYSLOG
  44. [Install]
  45. WantedBy=multi-user.target