diff --git a/client/cmd/service.go b/client/cmd/service.go index 156e67d6d..27823cfc7 100644 --- a/client/cmd/service.go +++ b/client/cmd/service.go @@ -37,7 +37,7 @@ func newSVCConfig() *service.Config { } if runtime.GOOS == "linux" { - config.EnvVars["SYSTEMD_UNIT"] = serviceName + config.EnvVars["NB_SERVICE"] = serviceName } return config diff --git a/client/internal/debug/debug_linux.go b/client/internal/debug/debug_linux.go index 4626cd9a2..de9adc693 100644 --- a/client/internal/debug/debug_linux.go +++ b/client/internal/debug/debug_linux.go @@ -55,8 +55,8 @@ func (g *BundleGenerator) trySystemdLogFallback() error { // getServiceName gets the service name from environment or defaults to netbird func getServiceName() string { - if unitName := os.Getenv("SYSTEMD_UNIT"); unitName != "" { - log.Debugf("Detected SYSTEMD_UNIT environment variable: %s", unitName) + if unitName := os.Getenv("NB_SERVICE"); unitName != "" { + log.Debugf("Detected NB_SERVICE environment variable: %s", unitName) return unitName } diff --git a/release_files/systemd/netbird@.service b/release_files/systemd/netbird@.service index 095c3142d..99d0791f4 100644 --- a/release_files/systemd/netbird@.service +++ b/release_files/systemd/netbird@.service @@ -1,21 +1,29 @@ [Unit] Description=Netbird Client (%i) Documentation=https://netbird.io/docs -After=network-online.target syslog.target NetworkManager.service +After=network-online.target syslog.target Wants=network-online.target [Service] Type=simple +Environment=NB_CONFIG=/etc/netbird/%i.json +Environment=NB_STATE_DIR=/var/lib/netbird/%i +Environment=NB_LOG_FILE=/var/log/netbird/%i/client.log +Environment=NB_DAEMON_ADDR=unix:///var/run/netbird/%i.sock +Environment=NB_SERVICE=%N +# for compatibility with older versions +Environment=SYSTEMD_UNIT=%N EnvironmentFile=-/etc/default/netbird -ExecStart=/usr/bin/netbird service run --log-file /var/log/netbird/client-%i.log --config /etc/netbird/%i.json --daemon-addr unix:///var/run/netbird/%i.sock $FLAGS +EnvironmentFile=-/etc/default/netbird-%i +ExecStart=/usr/bin/netbird service run $FLAGS Restart=on-failure RestartSec=5 TimeoutStopSec=10 -CacheDirectory=netbird +CacheDirectory=netbird/%i ConfigurationDirectory=netbird -LogsDirectory=netbird +LogsDirectory=netbird/%i RuntimeDirectory=netbird -StateDirectory=netbird +StateDirectory=netbird/%i # sandboxing LockPersonality=yes