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 // PropType sets the Type service property. See
82 // http://www.freedesktop.org/software/systemd/man/systemd.service.html#Type=
83 func PropType(t string) Property {
86 Value: dbus.MakeVariant(t),
90 // PropDescription sets the Description unit property. See
91 // http://www.freedesktop.org/software/systemd/man/systemd.unit#Description=
92 func PropDescription(desc string) Property {
95 Value: dbus.MakeVariant(desc),
99 func propDependency(name string, units []string) Property {
102 Value: dbus.MakeVariant(units),
106 // PropRequires sets the Requires unit property. See
107 // http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Requires=
108 func PropRequires(units ...string) Property {
109 return propDependency("Requires", units)
112 // PropRequiresOverridable sets the RequiresOverridable unit property. See
113 // http://www.freedesktop.org/software/systemd/man/systemd.unit.html#RequiresOverridable=
114 func PropRequiresOverridable(units ...string) Property {
115 return propDependency("RequiresOverridable", units)
118 // PropRequisite sets the Requisite unit property. See
119 // http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Requisite=
120 func PropRequisite(units ...string) Property {
121 return propDependency("Requisite", units)
124 // PropRequisiteOverridable sets the RequisiteOverridable unit property. See
125 // http://www.freedesktop.org/software/systemd/man/systemd.unit.html#RequisiteOverridable=
126 func PropRequisiteOverridable(units ...string) Property {
127 return propDependency("RequisiteOverridable", units)
130 // PropWants sets the Wants unit property. See
131 // http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Wants=
132 func PropWants(units ...string) Property {
133 return propDependency("Wants", units)
136 // PropBindsTo sets the BindsTo unit property. See
137 // http://www.freedesktop.org/software/systemd/man/systemd.unit.html#BindsTo=
138 func PropBindsTo(units ...string) Property {
139 return propDependency("BindsTo", units)
142 // PropRequiredBy sets the RequiredBy unit property. See
143 // http://www.freedesktop.org/software/systemd/man/systemd.unit.html#RequiredBy=
144 func PropRequiredBy(units ...string) Property {
145 return propDependency("RequiredBy", units)
148 // PropRequiredByOverridable sets the RequiredByOverridable unit property. See
149 // http://www.freedesktop.org/software/systemd/man/systemd.unit.html#RequiredByOverridable=
150 func PropRequiredByOverridable(units ...string) Property {
151 return propDependency("RequiredByOverridable", units)
154 // PropWantedBy sets the WantedBy unit property. See
155 // http://www.freedesktop.org/software/systemd/man/systemd.unit.html#WantedBy=
156 func PropWantedBy(units ...string) Property {
157 return propDependency("WantedBy", units)
160 // PropBoundBy sets the BoundBy unit property. See
161 // http://www.freedesktop.org/software/systemd/main/systemd.unit.html#BoundBy=
162 func PropBoundBy(units ...string) Property {
163 return propDependency("BoundBy", units)
166 // PropConflicts sets the Conflicts unit property. See
167 // http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Conflicts=
168 func PropConflicts(units ...string) Property {
169 return propDependency("Conflicts", units)
172 // PropConflictedBy sets the ConflictedBy unit property. See
173 // http://www.freedesktop.org/software/systemd/man/systemd.unit.html#ConflictedBy=
174 func PropConflictedBy(units ...string) Property {
175 return propDependency("ConflictedBy", units)
178 // PropBefore sets the Before unit property. See
179 // http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Before=
180 func PropBefore(units ...string) Property {
181 return propDependency("Before", units)
184 // PropAfter sets the After unit property. See
185 // http://www.freedesktop.org/software/systemd/man/systemd.unit.html#After=
186 func PropAfter(units ...string) Property {
187 return propDependency("After", units)
190 // PropOnFailure sets the OnFailure unit property. See
191 // http://www.freedesktop.org/software/systemd/man/systemd.unit.html#OnFailure=
192 func PropOnFailure(units ...string) Property {
193 return propDependency("OnFailure", units)
196 // PropTriggers sets the Triggers unit property. See
197 // http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Triggers=
198 func PropTriggers(units ...string) Property {
199 return propDependency("Triggers", units)
202 // PropTriggeredBy sets the TriggeredBy unit property. See
203 // http://www.freedesktop.org/software/systemd/man/systemd.unit.html#TriggeredBy=
204 func PropTriggeredBy(units ...string) Property {
205 return propDependency("TriggeredBy", units)
208 // PropPropagatesReloadTo sets the PropagatesReloadTo unit property. See
209 // http://www.freedesktop.org/software/systemd/man/systemd.unit.html#PropagatesReloadTo=
210 func PropPropagatesReloadTo(units ...string) Property {
211 return propDependency("PropagatesReloadTo", units)
214 // PropRequiresMountsFor sets the RequiresMountsFor unit property. See
215 // http://www.freedesktop.org/software/systemd/man/systemd.unit.html#RequiresMountsFor=
216 func PropRequiresMountsFor(units ...string) Property {
217 return propDependency("RequiresMountsFor", units)
220 // PropSlice sets the Slice unit property. See
221 // http://www.freedesktop.org/software/systemd/man/systemd.resource-control.html#Slice=
222 func PropSlice(slice string) Property {
225 Value: dbus.MakeVariant(slice),
229 // PropPids sets the PIDs field of scope units used in the initial construction
230 // of the scope only and specifies the initial PIDs to add to the scope object.
231 // See https://www.freedesktop.org/wiki/Software/systemd/ControlGroupInterface/#properties
232 func PropPids(pids ...uint32) Property {
235 Value: dbus.MakeVariant(pids),