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

Support for targeting systemd --user #1393

Merged
merged 2 commits into from
Jul 11, 2016
Merged
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
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type Config struct {
DisableEngine bool
DisableWatches bool
VerifyUnits bool
UnitsDirectory string
SystemdUser bool
AuthorizedKeysFile string
}

Expand Down
4 changes: 4 additions & 0 deletions fleetd/fleetd.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ func main() {
cfgset.String("public_ip", "", "IP address that fleet machine should publish")
cfgset.String("metadata", "", "List of key-value metadata to assign to the fleet machine")
cfgset.String("agent_ttl", agent.DefaultTTL, "TTL in seconds of fleet machine state in etcd")
cfgset.String("units_directory", "/run/fleet/units/", "Path to the fleet units directory")
cfgset.Bool("systemd_user", false, "When true use systemd --user)")
cfgset.Int("token_limit", 100, "Maximum number of entries per page returned from API requests")
cfgset.Bool("disable_engine", false, "Disable the engine entirely, use with care")
cfgset.Bool("disable_watches", false, "Disable the use of etcd watches. Increases scheduling latency")
Expand Down Expand Up @@ -225,6 +227,8 @@ func getConfig(flagset *flag.FlagSet, userCfgFile string) (*config.Config, error
DisableEngine: (*flagset.Lookup("disable_engine")).Value.(flag.Getter).Get().(bool),
DisableWatches: (*flagset.Lookup("disable_watches")).Value.(flag.Getter).Get().(bool),
VerifyUnits: (*flagset.Lookup("verify_units")).Value.(flag.Getter).Get().(bool),
UnitsDirectory: (*flagset.Lookup("units_directory")).Value.(flag.Getter).Get().(string),
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),
}
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)
mgr, err := systemd.NewSystemdUnitManager(uDir, false)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dongsupark Fixed functional/systemd_test.go here.
Thanks again for the reminder!

if err != nil {
t.Fatalf("Failed initializing SystemdUnitManager: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func New(cfg config.Config, listeners []net.Listener) (*Server, error) {
return nil, err
}

mgr, err := systemd.NewSystemdUnitManager(systemd.DefaultUnitsDirectory)
mgr, err := systemd.NewSystemdUnitManager(cfg.UnitsDirectory, cfg.SystemdUser)
if err != nil {
return nil, err
}
Expand Down
15 changes: 9 additions & 6 deletions systemd/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ import (
"github.com/coreos/fleet/unit"
)

const (
DefaultUnitsDirectory = "/run/fleet/units/"
)

type systemdUnitManager struct {
systemd *dbus.Conn
unitsDir string
Expand All @@ -40,8 +36,8 @@ type systemdUnitManager struct {
mutex sync.RWMutex
}

func NewSystemdUnitManager(uDir string) (*systemdUnitManager, error) {
systemd, err := dbus.New()
func NewSystemdUnitManager(uDir string, systemdUser bool) (*systemdUnitManager, error) {
systemd, err := createDbusConnection(systemdUser)
if err != nil {
return nil, err
}
Expand All @@ -64,6 +60,13 @@ func NewSystemdUnitManager(uDir string) (*systemdUnitManager, error) {
return &mgr, nil
}

func createDbusConnection(systemdUser bool) (*dbus.Conn, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indirection of this function seems unnecessary - I'd just inline the conditional into NewSystemdUnitManager

if systemdUser {
return dbus.NewUserConnection()
}
return dbus.New()
}

func hashUnitFiles(dir string) (map[string]unit.Hash, error) {
uNames, err := lsUnitsDir(dir)
if err != nil {
Expand Down