Skip to content

Commit

Permalink
feat: explicitly start and stop canonical-facts
Browse files Browse the repository at this point in the history
Running 'rhc connect' will explicitly activate and start the
rhc-canonical-facts.timer unit. Likewise, running 'rhc disconnect' will
explicitly deactivate and stop the rhc-canonical-facts.timer unit.
  • Loading branch information
subpop authored and Archana-PandeyM committed Nov 13, 2024
1 parent da19acd commit 61021cd
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
systemd "github.com/coreos/go-systemd/v22/dbus"
)

// activateService tries to enable and start yggdrasil service.
// The service can be branded to rhcd on RHEL
// activateService tries to enable and start the rhc-canonical-facts.timer and
// yggdrasil.service.
func activateService() error {
ctx := context.Background()
conn, err := systemd.NewSystemConnectionContext(ctx)
Expand All @@ -18,14 +18,17 @@ func activateService() error {
defer conn.Close()

unitName := ServiceName + ".service"
timerName := "rhc-canonical-facts.timer"

if _, _, err := conn.EnableUnitFilesContext(ctx, []string{unitName}, false, true); err != nil {
if _, _, err := conn.EnableUnitFilesContext(ctx, []string{unitName, timerName}, false, true); err != nil {
return err
}

done := make(chan string)
if _, err := conn.StartUnitContext(ctx, unitName, "replace", done); err != nil {
return err
for _, unit := range []string{"rhc-canonical-facts.service", timerName, unitName} {
if _, err := conn.StartUnitContext(ctx, unit, "replace", done); err != nil {
return err
}
}
<-done
properties, err := conn.GetUnitPropertiesContext(ctx, unitName)
Expand All @@ -45,8 +48,8 @@ func activateService() error {
return nil
}

// deactivateService tries to stop and disable yggdrasil service.
// The service can be branded to rhcd on RHEL
// deactivateService tries to stop and disable the rhc-canonical-facts.timer and
// yggdrasil.service.
func deactivateService() error {
// Use simple background context without anything extra
ctx := context.Background()
Expand All @@ -57,14 +60,17 @@ func deactivateService() error {
defer conn.Close()

unitName := ServiceName + ".service"
timerName := "rhc-canonical-facts.timer"

done := make(chan string)
if _, err := conn.StopUnitContext(ctx, unitName, "replace", done); err != nil {
return err
for _, unit := range []string{timerName, unitName} {
if _, err := conn.StopUnitContext(ctx, unit, "replace", done); err != nil {
return err
}
}
<-done

if _, err := conn.DisableUnitFilesContext(ctx, []string{unitName}, false); err != nil {
if _, err := conn.DisableUnitFilesContext(ctx, []string{timerName, unitName}, false); err != nil {
return err
}

Expand Down

0 comments on commit 61021cd

Please sign in to comment.