This is my sing-box@.service, using DynamicUser:
/etc/systemd/system/sing-box@.service
[Unit]
Description=sing-box service
Documentation=https://sing-box.sagernet.org
After=network.target nss-lookup.target network-online.target
[Service]
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_RAW CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_RAW CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH
DynamicUser=yes
CacheDirectory=sing-box-%i
CacheDirectoryMode=755
LoadCredential=config.json:/etc/sing-box/%i.json
ExecStart=/usr/bin/sing-box run -c ${CREDENTIALS_DIRECTORY}/config.json -D ${CACHE_DIRECTORY}
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=10s
LimitNOFILE=infinity
[Install]
WantedBy=multi-user.target
/etc/systemd/system/sing-box@PROFILE.service.d/override.conf
[Service]
LoadCredential=cert:/etc/letsencrypt/live/EXAMPLE.COM/fullchain.pem
LoadCredential=key:/etc/letsencrypt/live/EXAMPLE.COM/privkey.pem
PROFILE.json
"tls": {
...
"key_path": "/run/credentials/sing-box@PROFILE.service/key",
"certificate_path": "/run/credentials/sing-box@PROFILE.service/cert"
}
Pinned Comments
everyx commented on 2026-03-06 01:13 (UTC)
This package will be automatically updated via CI. Please mark it as expired only if it has not been updated within 24 hours after a new version is released.