~sergiusens/snappy/recovery

« back to all changes in this revision

Viewing changes to systemd/systemd.go

  • Committer: Sergio Schvezov
  • Date: 2015-07-30 18:46:26 UTC
  • mfrom: (581.1.2 uflash)
  • Revision ID: sergio.schvezov@canonical.com-20150730184626-m3r662bwu4v8xdnq
Merged uflash into recovery.

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
        Kill(service, signal string) error
69
69
        Restart(service string, timeout time.Duration) error
70
70
        GenServiceFile(desc *ServiceDescription) string
 
71
        Status(service string) (string, error)
71
72
}
72
73
 
73
74
// ServiceDescription describes a snappy systemd service
83
84
        StopTimeout time.Duration
84
85
        AaProfile   string
85
86
        IsFramework bool
 
87
        IsNetworked bool
86
88
        BusName     string
87
89
        UdevAppName string
88
90
}
140
142
        return err
141
143
}
142
144
 
 
145
var statusregex = regexp.MustCompile(`(?m)^(?:(.*?)=(.*))?$`)
 
146
 
 
147
func (s *systemd) Status(serviceName string) (string, error) {
 
148
        bs, err := SystemctlCmd("show", "--property=Id,LoadState,ActiveState,SubState", serviceName)
 
149
        if err != nil {
 
150
                return "", err
 
151
        }
 
152
 
 
153
        load, active, sub := "", "", ""
 
154
 
 
155
        for _, bs := range statusregex.FindAllSubmatch(bs, -1) {
 
156
                if len(bs[0]) > 0 {
 
157
                        k := string(bs[1])
 
158
                        v := string(bs[2])
 
159
                        switch k {
 
160
                        case "LoadState":
 
161
                                load = v
 
162
                        case "ActiveState":
 
163
                                active = v
 
164
                        case "SubState":
 
165
                                sub = v
 
166
                        }
 
167
                }
 
168
        }
 
169
 
 
170
        return fmt.Sprintf("%s; %s (%s)", load, active, sub), nil
 
171
}
 
172
 
143
173
// Stop the given service, and wait until it has stopped.
144
174
func (s *systemd) Stop(serviceName string, timeout time.Duration) error {
145
175
        if _, err := SystemctlCmd("stop", serviceName); err != nil {
176
206
{{if .IsFramework}}Before=ubuntu-snappy.frameworks.target
177
207
After=ubuntu-snappy.frameworks-pre.target
178
208
Requires=ubuntu-snappy.frameworks-pre.target{{else}}After=ubuntu-snappy.frameworks.target
179
 
Requires=ubuntu-snappy.frameworks.target{{end}}
 
209
Requires=ubuntu-snappy.frameworks.target{{end}}{{if .IsNetworked}}
 
210
After=snappy-wait4network.service
 
211
Requires=snappy-wait4network.service{{end}}
180
212
X-Snappy=yes
181
213
 
182
214
[Service]