Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

fleetd: allow users to turn off force flag for systemd.LinkUnitFiles() #1696

Open
wants to merge 1 commit into
base: master
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
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Config struct {
UnitsDirectory string
SystemdUser bool
AuthorizedKeysFile string
SystemdLinkUnitForce bool
}

func (c *Config) Capabilities() machine.Capabilities {
Expand Down
2 changes: 2 additions & 0 deletions fleetd/fleetd.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func Main() {
cfgset.Bool("disable_watches", false, "Disable the use of etcd watches. Increases scheduling latency")
cfgset.Bool("verify_units", false, "DEPRECATED - This option is ignored")
cfgset.String("authorized_keys_file", "", "DEPRECATED - This option is ignored")
cfgset.Bool("systemd_link_unit_force", false, "When true, turn on force flag for LinkUnitFiles)")

globalconf.Register("", cfgset)
cfg, err := getConfig(cfgset, *cfgPath)
Expand Down Expand Up @@ -237,6 +238,7 @@ func getConfig(flagset *flag.FlagSet, userCfgFile string) (*config.Config, error
SystemdUser: (*flagset.Lookup("systemd_user")).Value.(flag.Getter).Get().(bool),
TokenLimit: (*flagset.Lookup("token_limit")).Value.(flag.Getter).Get().(int),
AuthorizedKeysFile: (*flagset.Lookup("authorized_keys_file")).Value.(flag.Getter).Get().(string),
SystemdLinkUnitForce: (*flagset.Lookup("systemd_link_unit_force")).Value.(flag.Getter).Get().(bool),
}

if cfg.VerifyUnits {
Expand Down
2 changes: 1 addition & 1 deletion functional/systemd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestSystemdUnitFlow(t *testing.T) {
}
defer os.RemoveAll(uDir)

mgr, err := systemd.NewSystemdUnitManager(uDir, false)
mgr, err := systemd.NewSystemdUnitManager(uDir, false, false)
if err != nil {
t.Fatalf("Failed initializing SystemdUnitManager: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion registry/rpc/registrymux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestRegistryMuxUnitManagement(t *testing.T) {
PublicIP: "127.0.0.1",
Metadata: make(map[string]string, 0),
}
mgr, err := systemd.NewSystemdUnitManager(uDir, false)
mgr, err := systemd.NewSystemdUnitManager(uDir, false, false)
if err != nil {
// NOTE: ideally we should fail with t.Fatalf(), but then it would always
// fail on travis CI, because apparently systemd dbus socket is not
Expand Down
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func New(cfg config.Config, listeners []net.Listener) (*Server, error) {
return nil, err
}

mgr, err := systemd.NewSystemdUnitManager(cfg.UnitsDirectory, cfg.SystemdUser)
mgr, err := systemd.NewSystemdUnitManager(cfg.UnitsDirectory, cfg.SystemdUser, cfg.SystemdLinkUnitForce)
if err != nil {
return nil, err
}
Expand Down
6 changes: 4 additions & 2 deletions systemd/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ import (
type systemdUnitManager struct {
systemd *dbus.Conn
unitsDir string
luForce bool

hashes map[string]unit.Hash
mutex sync.RWMutex
}

func NewSystemdUnitManager(uDir string, systemdUser bool) (*systemdUnitManager, error) {
func NewSystemdUnitManager(uDir string, systemdUser bool, systemdLUForce bool) (*systemdUnitManager, error) {
var systemd *dbus.Conn
var err error
if systemdUser {
Expand All @@ -60,6 +61,7 @@ func NewSystemdUnitManager(uDir string, systemdUser bool) (*systemdUnitManager,
mgr := systemdUnitManager{
systemd: systemd,
unitsDir: uDir,
luForce: systemdLUForce,
hashes: hashes,
mutex: sync.RWMutex{},
}
Expand Down Expand Up @@ -265,7 +267,7 @@ func (m *systemdUnitManager) writeUnit(name string, contents string) error {
return err
}

_, err = m.systemd.LinkUnitFiles([]string{ufPath}, true, true)
_, err = m.systemd.LinkUnitFiles([]string{ufPath}, true, m.luForce)
return err
}

Expand Down