~mvo/snappy/snappy-snapfs-refactor-ftw

« back to all changes in this revision

Viewing changes to systemd/systemd.go

  • Committer: John R. Lenton
  • Date: 2015-04-02 22:57:40 UTC
  • mto: (289.9.4 framework-policy)
  • mto: This revision was merged to the branch mainline in revision 316.
  • Revision ID: jlenton@gmail.com-20150402225740-gi7ijj9o2uddhqiv
renamed systemctl to systemd

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 *
16
16
 */
17
17
 
18
 
package systemctl
 
18
package systemd
19
19
 
20
20
import (
21
21
        "fmt"
50
50
// systemctl. It's exported so it can be overridden by testing.
51
51
var SystemctlCmd = run
52
52
 
53
 
// SystemCtl exposes a minimal interface to manage systemd via the systemctl command.
54
 
type SystemCtl interface {
 
53
// Systemd exposes a minimal interface to manage systemd via the systemctl command.
 
54
type Systemd interface {
55
55
        DaemonReload() error
56
56
        Enable(service string) error
57
57
        Disable(service string) error
59
59
        Stop(service string) error
60
60
}
61
61
 
62
 
// New returns a SystemCtl that uses the given rootDir
63
 
func New(rootDir string) SystemCtl {
64
 
        return &systemCtl{rootDir: rootDir}
 
62
// New returns a Systemd that uses the given rootDir
 
63
func New(rootDir string) Systemd {
 
64
        return &systemd{rootDir: rootDir}
65
65
}
66
66
 
67
 
type systemCtl struct {
 
67
type systemd struct {
68
68
        rootDir string
69
69
}
70
70
 
71
71
// DaemonReload reloads systemd's configuration.
72
 
func (*systemCtl) DaemonReload() error {
 
72
func (*systemd) DaemonReload() error {
73
73
        _, err := SystemctlCmd("daemon-reload")
74
74
        return err
75
75
}
76
76
 
77
77
// Enable the given service
78
 
func (s *systemCtl) Enable(serviceName string) error {
 
78
func (s *systemd) Enable(serviceName string) error {
79
79
        _, err := SystemctlCmd("--root", s.rootDir, "enable", serviceName)
80
80
        return err
81
81
}
82
82
 
83
83
// Disable the given service
84
 
func (s *systemCtl) Disable(serviceName string) error {
 
84
func (s *systemd) Disable(serviceName string) error {
85
85
        _, err := SystemctlCmd("--root", s.rootDir, "disable", serviceName)
86
86
        return err
87
87
}
88
88
 
89
89
// Start the given service
90
 
func (*systemCtl) Start(serviceName string) error {
 
90
func (*systemd) Start(serviceName string) error {
91
91
        _, err := SystemctlCmd("start", serviceName)
92
92
        return err
93
93
}
94
94
 
95
95
// Stop the given service, and wait until it has stopped.
96
 
func (*systemCtl) Stop(serviceName string) error {
 
96
func (*systemd) Stop(serviceName string) error {
97
97
        if _, err := SystemctlCmd("stop", serviceName); err != nil {
98
98
                return err
99
99
        }
119
119
        return nil
120
120
}
121
121
 
122
 
// Error is returned if the systemctl command failed
 
122
// Error is returned if the systemd action failed
123
123
type Error struct {
124
124
        cmd      []string
125
125
        exitCode int
129
129
        return fmt.Sprintf("%v failed with exit status %d", e.cmd, e.exitCode)
130
130
}
131
131
 
132
 
// Timeout is returned if the systemctl action failed to reach the
 
132
// Timeout is returned if the systemd action failed to reach the
133
133
// expected state in a reasonable amount of time
134
134
type Timeout struct {
135
135
        action  string