-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathactivate.go
62 lines (49 loc) · 1.89 KB
/
activate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"context"
"fmt"
systemd "github.com/redhatinsights/rhc/internal/systemd"
)
// activateService tries to enable and start the rhc-canonical-facts.timer,
// rhc-canonical-facts.service and yggdrasil.service.
func activateService() error {
conn, err := systemd.NewConnectionContext(context.Background(), systemd.ConnectionTypeSystem)
if err != nil {
return fmt.Errorf("cannot connect to systemd: %v", err)
}
defer conn.Close()
if err := conn.EnableUnit("rhc-canonical-facts.timer", true, false); err != nil {
return fmt.Errorf("cannot enable rhc-canonical-facts.timer: %v", err)
}
// Start the canonical-facts service immediately, so the facts get generated
// and written out before yggdrasil.service starts.
if err := conn.StartUnit("rhc-canonical-facts.service", false); err != nil {
return fmt.Errorf("cannot start rhc-canonical-facts.service: %v", err)
}
if err := conn.EnableUnit("yggdrasil.service", true, false); err != nil {
return fmt.Errorf("cannot enable yggdrasil.service: %v", err)
}
if err := conn.Reload(); err != nil {
return fmt.Errorf("cannot reload systemd: %v", err)
}
return nil
}
// deactivateService tries to stop and disable the rhc-canonical-facts.timer,
// rhc-canonical-facts.service and yggdrasil.service.
func deactivateService() error {
conn, err := systemd.NewConnectionContext(context.Background(), systemd.ConnectionTypeSystem)
if err != nil {
return fmt.Errorf("cannot connect to systemd: %v", err)
}
defer conn.Close()
if err := conn.DisableUnit("rhc-canonical-facts.timer", true, false); err != nil {
return fmt.Errorf("cannot disable rhc-canonical-facts.timer: %v", err)
}
if err := conn.DisableUnit("yggdrasil.service", true, false); err != nil {
return fmt.Errorf("cannot disable yggdrasil.service: %v", err)
}
if err := conn.Reload(); err != nil {
return fmt.Errorf("cannot reload systemd: %v", err)
}
return nil
}