~sinzui/ubuntu/vivid/juju-core/vivid-1.24.6

« back to all changes in this revision

Viewing changes to src/github.com/coreos/go-systemd/dbus/properties.go

  • Committer: Curtis Hovey
  • Date: 2015-09-30 14:14:54 UTC
  • mfrom: (1.1.34)
  • Revision ID: curtis@hovey.name-20150930141454-o3ldf23dzyjio6c0
Backport of 1.24.6 from wily. (LP: #1500916)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
// PropDescription sets the Description unit property. See
 
82
// http://www.freedesktop.org/software/systemd/man/systemd.unit#Description=
 
83
func PropDescription(desc string) Property {
 
84
        return Property{
 
85
                Name:  "Description",
 
86
                Value: dbus.MakeVariant(desc),
 
87
        }
 
88
}
 
89
 
 
90
func propDependency(name string, units []string) Property {
 
91
        return Property{
 
92
                Name:  name,
 
93
                Value: dbus.MakeVariant(units),
 
94
        }
 
95
}
 
96
 
 
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)
 
101
}
 
102
 
 
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)
 
107
}
 
108
 
 
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)
 
113
}
 
114
 
 
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)
 
119
}
 
120
 
 
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)
 
125
}
 
126
 
 
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)
 
131
}
 
132
 
 
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)
 
137
}
 
138
 
 
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)
 
143
}
 
144
 
 
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)
 
149
}
 
150
 
 
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)
 
155
}
 
156
 
 
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)
 
161
}
 
162
 
 
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)
 
167
}
 
168
 
 
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)
 
173
}
 
174
 
 
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)
 
179
}
 
180
 
 
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)
 
185
}
 
186
 
 
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)
 
191
}
 
192
 
 
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)
 
197
}
 
198
 
 
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)
 
203
}
 
204
 
 
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)
 
209
}
 
210
 
 
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 {
 
214
        return Property{
 
215
                Name:  "Slice",
 
216
                Value: dbus.MakeVariant(slice),
 
217
        }
 
218
}