1
// Copyright 2015 CoreOS, Inc.
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
18
"github.com/godbus/dbus"
21
// From the systemd docs:
23
// The properties array of StartTransientUnit() may take many of the settings
24
// that may also be configured in unit files. Not all parameters are currently
25
// accepted though, but we plan to cover more properties with future release.
26
// Currently you may set the Description, Slice and all dependency types of
27
// units, as well as RemainAfterExit, ExecStart for service units,
28
// TimeoutStopUSec and PIDs for scope units, and CPUAccounting, CPUShares,
29
// BlockIOAccounting, BlockIOWeight, BlockIOReadBandwidth,
30
// BlockIOWriteBandwidth, BlockIODeviceWeight, MemoryAccounting, MemoryLimit,
31
// DevicePolicy, DeviceAllow for services/scopes/slices. These fields map
32
// directly to their counterparts in unit files and as normal D-Bus object
33
// properties. The exception here is the PIDs field of scope units which is
34
// used for construction of the scope only and specifies the initial PIDs to
35
// add to the scope object.
37
type Property struct {
42
type PropertyCollection struct {
47
type execStart struct {
48
Path string // the binary path to execute
49
Args []string // an array with all arguments to pass to the executed command, starting with argument 0
50
UncleanIsFailure bool // a boolean whether it should be considered a failure if the process exits uncleanly
53
// PropExecStart sets the ExecStart service property. The first argument is a
54
// slice with the binary path to execute followed by the arguments to pass to
55
// the executed command. See
56
// http://www.freedesktop.org/software/systemd/man/systemd.service.html#ExecStart=
57
func PropExecStart(command []string, uncleanIsFailure bool) Property {
58
execStarts := []execStart{
62
UncleanIsFailure: uncleanIsFailure,
68
Value: dbus.MakeVariant(execStarts),
72
// PropRemainAfterExit sets the RemainAfterExit service property. See
73
// http://www.freedesktop.org/software/systemd/man/systemd.service.html#RemainAfterExit=
74
func PropRemainAfterExit(b bool) Property {
76
Name: "RemainAfterExit",
77
Value: dbus.MakeVariant(b),
81
// PropDescription sets the Description unit property. See
82
// http://www.freedesktop.org/software/systemd/man/systemd.unit#Description=
83
func PropDescription(desc string) Property {
86
Value: dbus.MakeVariant(desc),
90
func propDependency(name string, units []string) Property {
93
Value: dbus.MakeVariant(units),
97
// PropRequires sets the Requires unit property. See
98
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Requires=
99
func PropRequires(units ...string) Property {
100
return propDependency("Requires", units)
103
// PropRequiresOverridable sets the RequiresOverridable unit property. See
104
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#RequiresOverridable=
105
func PropRequiresOverridable(units ...string) Property {
106
return propDependency("RequiresOverridable", units)
109
// PropRequisite sets the Requisite unit property. See
110
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Requisite=
111
func PropRequisite(units ...string) Property {
112
return propDependency("Requisite", units)
115
// PropRequisiteOverridable sets the RequisiteOverridable unit property. See
116
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#RequisiteOverridable=
117
func PropRequisiteOverridable(units ...string) Property {
118
return propDependency("RequisiteOverridable", units)
121
// PropWants sets the Wants unit property. See
122
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Wants=
123
func PropWants(units ...string) Property {
124
return propDependency("Wants", units)
127
// PropBindsTo sets the BindsTo unit property. See
128
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#BindsTo=
129
func PropBindsTo(units ...string) Property {
130
return propDependency("BindsTo", units)
133
// PropRequiredBy sets the RequiredBy unit property. See
134
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#RequiredBy=
135
func PropRequiredBy(units ...string) Property {
136
return propDependency("RequiredBy", units)
139
// PropRequiredByOverridable sets the RequiredByOverridable unit property. See
140
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#RequiredByOverridable=
141
func PropRequiredByOverridable(units ...string) Property {
142
return propDependency("RequiredByOverridable", units)
145
// PropWantedBy sets the WantedBy unit property. See
146
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#WantedBy=
147
func PropWantedBy(units ...string) Property {
148
return propDependency("WantedBy", units)
151
// PropBoundBy sets the BoundBy unit property. See
152
// http://www.freedesktop.org/software/systemd/main/systemd.unit.html#BoundBy=
153
func PropBoundBy(units ...string) Property {
154
return propDependency("BoundBy", units)
157
// PropConflicts sets the Conflicts unit property. See
158
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Conflicts=
159
func PropConflicts(units ...string) Property {
160
return propDependency("Conflicts", units)
163
// PropConflictedBy sets the ConflictedBy unit property. See
164
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#ConflictedBy=
165
func PropConflictedBy(units ...string) Property {
166
return propDependency("ConflictedBy", units)
169
// PropBefore sets the Before unit property. See
170
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Before=
171
func PropBefore(units ...string) Property {
172
return propDependency("Before", units)
175
// PropAfter sets the After unit property. See
176
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#After=
177
func PropAfter(units ...string) Property {
178
return propDependency("After", units)
181
// PropOnFailure sets the OnFailure unit property. See
182
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#OnFailure=
183
func PropOnFailure(units ...string) Property {
184
return propDependency("OnFailure", units)
187
// PropTriggers sets the Triggers unit property. See
188
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Triggers=
189
func PropTriggers(units ...string) Property {
190
return propDependency("Triggers", units)
193
// PropTriggeredBy sets the TriggeredBy unit property. See
194
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#TriggeredBy=
195
func PropTriggeredBy(units ...string) Property {
196
return propDependency("TriggeredBy", units)
199
// PropPropagatesReloadTo sets the PropagatesReloadTo unit property. See
200
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#PropagatesReloadTo=
201
func PropPropagatesReloadTo(units ...string) Property {
202
return propDependency("PropagatesReloadTo", units)
205
// PropRequiresMountsFor sets the RequiresMountsFor unit property. See
206
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#RequiresMountsFor=
207
func PropRequiresMountsFor(units ...string) Property {
208
return propDependency("RequiresMountsFor", units)
211
// PropSlice sets the Slice unit property. See
212
// http://www.freedesktop.org/software/systemd/man/systemd.resource-control.html#Slice=
213
func PropSlice(slice string) Property {
216
Value: dbus.MakeVariant(slice),