Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: make /var/lib/netbird paths configurable #3084

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions client/configs/configs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package configs

import (
"os"
"path/filepath"
"runtime"
)

var StateDir string

func init() {
StateDir = os.Getenv("NB_STATE_DIR")
if StateDir != "" {
return
}
switch runtime.GOOS {
case "windows":
StateDir = filepath.Join(os.Getenv("PROGRAMDATA"), "Netbird")
case "darwin", "linux":
StateDir = "/var/lib/netbird"
case "freebsd", "openbsd", "netbsd", "dragonfly":
StateDir = "/var/db/netbird"
}
}
18 changes: 18 additions & 0 deletions client/internal/dns/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//go:build !android

package dns

import (
"github.com/netbirdio/netbird/client/configs"
"os"
"path/filepath"
)

var fileUncleanShutdownResolvConfLocation string

func init() {
fileUncleanShutdownResolvConfLocation = os.Getenv("NB_UNCLEAN_SHUTDOWN_RESOLV_FILE")
if fileUncleanShutdownResolvConfLocation == "" {
fileUncleanShutdownResolvConfLocation = filepath.Join(configs.StateDir, "resolv.conf")
}
}
5 changes: 0 additions & 5 deletions client/internal/dns/consts_freebsd.go

This file was deleted.

7 changes: 0 additions & 7 deletions client/internal/dns/consts_linux.go

This file was deleted.

15 changes: 4 additions & 11 deletions client/internal/statemanager/path.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
package statemanager

import (
"github.com/netbirdio/netbird/client/configs"
"os"
"path/filepath"
"runtime"
)

// GetDefaultStatePath returns the path to the state file based on the operating system
// It returns an empty string if the path cannot be determined.
func GetDefaultStatePath() string {
switch runtime.GOOS {
case "windows":
return filepath.Join(os.Getenv("PROGRAMDATA"), "Netbird", "state.json")
case "darwin", "linux":
return "/var/lib/netbird/state.json"
case "freebsd", "openbsd", "netbsd", "dragonfly":
return "/var/db/netbird/state.json"
if path := os.Getenv("NB_DNS_STATE_FILE"); path != "" {
return path
}

return ""

return filepath.Join(configs.StateDir, "state.json")
}
Loading