Tizen_4.0 base
[platform/upstream/docker-engine.git] / vendor / github.com / coreos / go-systemd / dbus / properties.go
1 // Copyright 2015 CoreOS, Inc.
2 //
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
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
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.
14
15 package dbus
16
17 import (
18         "github.com/godbus/dbus"
19 )
20
21 // From the systemd docs:
22 //
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.
36
37 type Property struct {
38         Name  string
39         Value dbus.Variant
40 }
41
42 type PropertyCollection struct {
43         Name       string
44         Properties []Property
45 }
46
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
51 }
52
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{
59                 execStart{
60                         Path:             command[0],
61                         Args:             command,
62                         UncleanIsFailure: uncleanIsFailure,
63                 },
64         }
65
66         return Property{
67                 Name:  "ExecStart",
68                 Value: dbus.MakeVariant(execStarts),
69         }
70 }
71
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 {
75         return Property{
76                 Name:  "RemainAfterExit",
77                 Value: dbus.MakeVariant(b),
78         }
79 }
80
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 {
84         return Property{
85                 Name:  "Type",
86                 Value: dbus.MakeVariant(t),
87         }
88 }
89
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 {
93         return Property{
94                 Name:  "Description",
95                 Value: dbus.MakeVariant(desc),
96         }
97 }
98
99 func propDependency(name string, units []string) Property {
100         return Property{
101                 Name:  name,
102                 Value: dbus.MakeVariant(units),
103         }
104 }
105
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)
110 }
111
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)
116 }
117
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)
122 }
123
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)
128 }
129
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)
134 }
135
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)
140 }
141
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)
146 }
147
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)
152 }
153
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)
158 }
159
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)
164 }
165
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)
170 }
171
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)
176 }
177
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)
182 }
183
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)
188 }
189
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)
194 }
195
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)
200 }
201
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)
206 }
207
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)
212 }
213
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)
218 }
219
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 {
223         return Property{
224                 Name:  "Slice",
225                 Value: dbus.MakeVariant(slice),
226         }
227 }
228
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 {
233         return Property{
234                 Name:  "PIDs",
235                 Value: dbus.MakeVariant(pids),
236         }
237 }