mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-19 00:36:38 +00:00
[client] Create networkd.conf.d if it doesn't exist (#4764)
This commit is contained in:
@@ -259,6 +259,7 @@ func isServiceRunning() (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
networkdConf = "/etc/systemd/networkd.conf"
|
||||||
networkdConfDir = "/etc/systemd/networkd.conf.d"
|
networkdConfDir = "/etc/systemd/networkd.conf.d"
|
||||||
networkdConfFile = "/etc/systemd/networkd.conf.d/99-netbird.conf"
|
networkdConfFile = "/etc/systemd/networkd.conf.d/99-netbird.conf"
|
||||||
networkdConfContent = `# Created by NetBird to prevent systemd-networkd from removing
|
networkdConfContent = `# Created by NetBird to prevent systemd-networkd from removing
|
||||||
@@ -273,12 +274,16 @@ ManageForeignRoutingPolicyRules=no
|
|||||||
// configureSystemdNetworkd creates a drop-in configuration file to prevent
|
// configureSystemdNetworkd creates a drop-in configuration file to prevent
|
||||||
// systemd-networkd from removing NetBird's routes and policy rules.
|
// systemd-networkd from removing NetBird's routes and policy rules.
|
||||||
func configureSystemdNetworkd() error {
|
func configureSystemdNetworkd() error {
|
||||||
parentDir := filepath.Dir(networkdConfDir)
|
if _, err := os.Stat(networkdConf); os.IsNotExist(err) {
|
||||||
if _, err := os.Stat(parentDir); os.IsNotExist(err) {
|
log.Debug("systemd-networkd not in use, skipping configuration")
|
||||||
log.Debug("systemd networkd.conf.d parent directory does not exist, skipping configuration")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nolint:gosec // standard networkd permissions
|
||||||
|
if err := os.MkdirAll(networkdConfDir, 0755); err != nil {
|
||||||
|
return fmt.Errorf("create networkd.conf.d directory: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
// nolint:gosec // standard networkd permissions
|
// nolint:gosec // standard networkd permissions
|
||||||
if err := os.WriteFile(networkdConfFile, []byte(networkdConfContent), 0644); err != nil {
|
if err := os.WriteFile(networkdConfFile, []byte(networkdConfContent), 0644); err != nil {
|
||||||
return fmt.Errorf("write networkd configuration: %w", err)
|
return fmt.Errorf("write networkd configuration: %w", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user