1
// -*- Mode: Go; indent-tabs-mode: t -*-
4
* Copyright (C) 2014-2017 Canonical Ltd
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 3 as
8
* published by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
26
// RestartCondition encapsulates the different systemd 'restart' options
27
type RestartCondition string
29
// These are the supported restart conditions
31
RestartNever RestartCondition = "never"
32
RestartOnSuccess RestartCondition = "on-success"
33
RestartOnFailure RestartCondition = "on-failure"
34
RestartOnAbnormal RestartCondition = "on-abnormal"
35
RestartOnAbort RestartCondition = "on-abort"
36
RestartAlways RestartCondition = "always"
39
var RestartMap = map[string]RestartCondition{
41
"never": RestartNever,
42
"on-success": RestartOnSuccess,
43
"on-failure": RestartOnFailure,
44
"on-abnormal": RestartOnAbnormal,
45
"on-abort": RestartOnAbort,
46
"always": RestartAlways,
49
// ErrUnknownRestartCondition is returned when trying to unmarshal an unknown restart condition
50
var ErrUnknownRestartCondition = errors.New("invalid restart condition")
52
func (rc RestartCondition) String() string {
59
// UnmarshalYAML so RestartCondition implements yaml's Unmarshaler interface
60
func (rc *RestartCondition) UnmarshalYAML(unmarshal func(interface{}) error) error {
63
if err := unmarshal(&v); err != nil {
67
nrc, ok := RestartMap[v]
69
return ErrUnknownRestartCondition