-
Notifications
You must be signed in to change notification settings - Fork 562
/
restartcond.go
77 lines (64 loc) · 2.09 KB
/
restartcond.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2014-2017 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package snap
import (
"errors"
)
// RestartCondition encapsulates the different systemd 'restart' options
type RestartCondition string
// These are the supported restart conditions
const (
RestartNever RestartCondition = "never"
RestartOnSuccess RestartCondition = "on-success"
RestartOnFailure RestartCondition = "on-failure"
RestartOnAbnormal RestartCondition = "on-abnormal"
RestartOnAbort RestartCondition = "on-abort"
RestartOnWatchdog RestartCondition = "on-watchdog"
RestartAlways RestartCondition = "always"
)
var RestartMap = map[string]RestartCondition{
"no": RestartNever,
"never": RestartNever,
"on-success": RestartOnSuccess,
"on-failure": RestartOnFailure,
"on-abnormal": RestartOnAbnormal,
"on-abort": RestartOnAbort,
"on-watchdog": RestartOnWatchdog,
"always": RestartAlways,
}
// ErrUnknownRestartCondition is returned when trying to unmarshal an unknown restart condition
var ErrUnknownRestartCondition = errors.New("invalid restart condition")
func (rc RestartCondition) String() string {
if rc == "never" {
return "no"
}
return string(rc)
}
// UnmarshalYAML so RestartCondition implements yaml's Unmarshaler interface
func (rc *RestartCondition) UnmarshalYAML(unmarshal func(interface{}) error) error {
var v string
if err := unmarshal(&v); err != nil {
return err
}
nrc, ok := RestartMap[v]
if !ok {
return ErrUnknownRestartCondition
}
*rc = nrc
return nil
}