systemd.service 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. [Unit]
  2. Description=Small description of the service
  3. After=network.target
  4. [Service]
  5. Type=simple
  6. User=__APP__
  7. Group=__APP__
  8. WorkingDirectory=__INSTALL_DIR__/
  9. EnvironmentFile=__INSTALL_DIR__/.env
  10. ExecStart=/usr/bin/bash -c 'source __INSTALL_DIR__/venv/bin/activate && open-webui serve'
  11. StandardOutput=append:/var/log/__APP__/__APP__.log
  12. StandardError=inherit
  13. ### Depending on specificities of your service/app, you may need to tweak these
  14. ### .. but this should be a good baseline
  15. # Sandboxing options to harden security
  16. # Details for these options: https://www.freedesktop.org/software/systemd/man/systemd.exec.html
  17. NoNewPrivileges=yes
  18. PrivateTmp=yes
  19. PrivateDevices=yes
  20. RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK
  21. RestrictNamespaces=yes
  22. RestrictRealtime=yes
  23. DevicePolicy=closed
  24. ProtectClock=yes
  25. ProtectHostname=yes
  26. ProtectProc=invisible
  27. ProtectSystem=full
  28. ProtectControlGroups=yes
  29. ProtectKernelModules=yes
  30. ProtectKernelTunables=yes
  31. LockPersonality=yes
  32. SystemCallArchitectures=native
  33. SystemCallFilter=~@clock @debug @module @mount @obsolete @reboot @setuid @swap @cpu-emulation @privileged
  34. # Denying access to capabilities that should not be relevant for webapps
  35. # Doc: https://man7.org/linux/man-pages/man7/capabilities.7.html
  36. CapabilityBoundingSet=~CAP_RAWIO CAP_MKNOD
  37. CapabilityBoundingSet=~CAP_AUDIT_CONTROL CAP_AUDIT_READ CAP_AUDIT_WRITE
  38. CapabilityBoundingSet=~CAP_SYS_BOOT CAP_SYS_TIME CAP_SYS_MODULE CAP_SYS_PACCT
  39. CapabilityBoundingSet=~CAP_LEASE CAP_LINUX_IMMUTABLE CAP_IPC_LOCK
  40. CapabilityBoundingSet=~CAP_BLOCK_SUSPEND CAP_WAKE_ALARM
  41. CapabilityBoundingSet=~CAP_SYS_TTY_CONFIG
  42. CapabilityBoundingSet=~CAP_MAC_ADMIN CAP_MAC_OVERRIDE
  43. CapabilityBoundingSet=~CAP_NET_ADMIN CAP_NET_BROADCAST CAP_NET_RAW
  44. CapabilityBoundingSet=~CAP_SYS_ADMIN CAP_SYS_PTRACE CAP_SYSLOG
  45. [Install]
  46. WantedBy=multi-user.target