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

Evaluate the use of the Systemd DBus API using the go-systemd binding package #21

Open
ema-pe opened this issue Nov 20, 2024 · 0 comments
Labels
dfaas-agent Related to the agent component enhancement New feature or request

Comments

@ema-pe
Copy link
Collaborator

ema-pe commented Nov 20, 2024

Currently, the DFaaS agent restarts the HAProxy service by executing a command defined in the configuration file:

https://github.com/unimib-datAI/dfaas/blob/034794c87d7bfe638c098c40f09811cb0c35048b/dfaasagent.env#L23C38-L23C80

The command is executed using the os/exec package, which creates a temporary bash shell and checks the exit code:

// UpdateHAConfig updates the HAProxy config file
func (updater *Updater) UpdateHAConfig(content interface{}) error {
f, err := os.Create(updater.HAConfigFilePath)
if err != nil {
return errors.Wrap(err, "Error while opening the HAProxy configuration file for writing")
}
defer f.Close()
err = updater.template.Execute(f, content)
if err != nil {
return errors.Wrap(err, "Error while applying the HAProxy configuration template to the data")
}
cmd := exec.Command("bash", "-c", updater.CmdOnUpdated)
if updateStdoutDebugLogging {
cmd.Stdout = os.Stdout
}
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
return errors.Wrap(err, "Error while executing the HAProxy configuration update command (command: \""+updater.CmdOnUpdated+"\")")
}
return nil
}

This implementation works, but can be improved: we can call systemd API via DBus and this opens a lot of possibilities (for example, we can restart, reload the service or introspect it). For the Go language there is go-systemd, a module that exposes the DBus systemd API to the language (
https://pkg.go.dev/github.com/coreos/go-systemd/v22/dbus). We should evaluate whether using the DBus API is better for the agent than running the systemd command directly, since it introduces a new dependency (and the DBus server must be running).

@ema-pe ema-pe added enhancement New feature or request dfaas-agent Related to the agent component labels Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dfaas-agent Related to the agent component enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant