openshift-origin-node 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of openshift-origin-node might be problematic. Click here for more details.

Files changed (51) hide show
  1. data/COPYRIGHT +1 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +11 -0
  4. data/README.md +3 -0
  5. data/Rakefile +28 -0
  6. data/bin/oo-add-alias +93 -0
  7. data/bin/oo-app-create +110 -0
  8. data/bin/oo-app-destroy +100 -0
  9. data/bin/oo-app-state-show +74 -0
  10. data/bin/oo-authorized-ssh-key-add +83 -0
  11. data/bin/oo-authorized-ssh-key-remove +82 -0
  12. data/bin/oo-broker-auth-key-add +84 -0
  13. data/bin/oo-broker-auth-key-remove +72 -0
  14. data/bin/oo-cartridge-info +70 -0
  15. data/bin/oo-cartridge-list +70 -0
  16. data/bin/oo-connector-execute +94 -0
  17. data/bin/oo-env-var-add +81 -0
  18. data/bin/oo-env-var-remove +78 -0
  19. data/bin/oo-get-quota +64 -0
  20. data/bin/oo-remove-alias +93 -0
  21. data/bin/oo-set-quota +59 -0
  22. data/conf/node.conf +30 -0
  23. data/conf/resource_limits.template +67 -0
  24. data/lib/openshift-origin-node.rb +29 -0
  25. data/lib/openshift-origin-node/config.rb +21 -0
  26. data/lib/openshift-origin-node/environment.rb +26 -0
  27. data/lib/openshift-origin-node/model/application_container.rb +298 -0
  28. data/lib/openshift-origin-node/model/frontend_httpd.rb +346 -0
  29. data/lib/openshift-origin-node/model/node.rb +134 -0
  30. data/lib/openshift-origin-node/model/unix_user.rb +738 -0
  31. data/lib/openshift-origin-node/plugins/unix_user_observer.rb +86 -0
  32. data/lib/openshift-origin-node/utils/shell_exec.rb +115 -0
  33. data/lib/openshift-origin-node/version.rb +23 -0
  34. data/misc/bin/oo-admin-ctl-cgroups +482 -0
  35. data/misc/bin/oo-cgroup-read +25 -0
  36. data/misc/bin/oo-get-mcs-level +29 -0
  37. data/misc/bin/oo-trap-user +248 -0
  38. data/misc/bin/rhcsh +155 -0
  39. data/misc/bin/setup_pam_fs_limits.sh +146 -0
  40. data/misc/bin/teardown_pam_fs_limits.sh +73 -0
  41. data/misc/doc/cgconfig.conf +26 -0
  42. data/misc/etc/openshift-run.conf +1 -0
  43. data/misc/init/openshift-cgroups +56 -0
  44. data/misc/services/openshift-cgroups.service +14 -0
  45. data/openshift-origin-node.gemspec +31 -0
  46. data/rubygem-openshift-origin-node.spec +263 -0
  47. data/test/test_helper.rb +20 -0
  48. data/test/unit/frontend_httpd_test.rb +144 -0
  49. data/test/unit/unix_user_test.rb +95 -0
  50. data/test/unit/version_test.rb +45 -0
  51. metadata +230 -0
@@ -0,0 +1,86 @@
1
+ require 'rubygems'
2
+ require 'singleton'
3
+ require 'openshift-origin-node/config'
4
+ require 'openshift-origin-node/model/unix_user'
5
+ require 'openshift-origin-node/utils/shell_exec'
6
+
7
+ module OpenShift
8
+ class UnixUserObserver
9
+ include OpenShift::Utils::ShellExec
10
+ include Object::Singleton
11
+
12
+ def update(*args)
13
+ method = args.first
14
+ args = args.drop(1)
15
+ send(method, *args)
16
+ end
17
+
18
+ def before_unix_user_create(user)
19
+ end
20
+
21
+ def after_unix_user_create(user)
22
+ out,err,rc = shellCmd("service cgconfig status > /dev/null 2>&1")
23
+ if rc == 0
24
+ out,err,rc = shellCmd("/usr/bin/oo-admin-ctl-cgroups startuser #{user.name} > /dev/null")
25
+ raise OpenShift::UserCreationException.new("Unable to setup cgroups for #{user.name}: stdout -- #{out} stderr --#{err}}") unless rc == 0
26
+ end
27
+ end
28
+
29
+ def before_initialize_homedir(user)
30
+ end
31
+
32
+ def after_initialize_homedir(user)
33
+ cmd = "/bin/sh #{File.join('/usr/libexec/openshift/lib', "setup_pam_fs_limits.sh")} #{user.name} #{user.quota_blocks ? user.quota_blocks : ''} #{user.quota_files ? user.quota_files : ''}"
34
+ out,err,rc = shellCmd(cmd)
35
+ raise OpenShift::UserCreationException.new("Unable to setup pam/fs limits for #{user.name}: stdout -- #{out} stderr -- #{err}") unless rc == 0
36
+ end
37
+
38
+
39
+ def before_unix_user_destroy(user)
40
+ cmd = "/bin/sh #{File.join('/usr/libexec/openshift/lib', "setup_pam_fs_limits.sh")} #{user.name} 0 0 0"
41
+ out,err,rc = shellCmd(cmd)
42
+ raise OpenShift::UserCreationException.new("Unable to setup pam/fs/nproc limits for #{user.name}") unless rc == 0
43
+
44
+ out,err,rc = shellCmd("service cgconfig status > /dev/null")
45
+ if rc == 0
46
+ shellCmd("/usr/bin/oo-admin-ctl-cgroups freezeuser #{user.name} > /dev/null") if rc == 0
47
+ end
48
+
49
+ last_access_dir = OpenShift::Config.instance.get("LAST_ACCESS_DIR")
50
+ shellCmd("rm -f #{last_access_dir}/#{user.name} > /dev/null")
51
+ end
52
+
53
+ def before_initialize_openshift_port_proxy(user)
54
+ end
55
+
56
+ def after_initialize_openshift_port_proxy(user)
57
+ end
58
+
59
+ def after_unix_user_destroy(user)
60
+ out,err,rc = shellCmd("service cgconfig status > /dev/null")
61
+ shellCmd("/usr/bin/oo-admin-ctl-cgroups thawuser #{user.name} > /dev/null") if rc == 0
62
+ shellCmd("/usr/bin/oo-admin-ctl-cgroups stopuser #{user.name} > /dev/null") if rc == 0
63
+
64
+ cmd = "/bin/sh #{File.join("/usr/libexec/openshift/lib", "teardown_pam_fs_limits.sh")} #{user.name}"
65
+ out,err,rc = shellCmd(cmd)
66
+ raise OpenShift::UserCreationException.new("Unable to teardown pam/fs/nproc limits for #{user.name}") unless rc == 0
67
+ end
68
+
69
+ def before_add_ssh_key(user,key)
70
+ end
71
+
72
+ def after_add_ssh_key(user,key)
73
+ ssh_dir = File.join(user.homedir, ".ssh")
74
+ cmd = "restorecon -R #{ssh_dir}"
75
+ shellCmd(cmd)
76
+ end
77
+
78
+ def before_remove_ssh_key(user,key)
79
+ end
80
+
81
+ def after_remove_ssh_key(user,key)
82
+ end
83
+ end
84
+
85
+ OpenShift::UnixUser.add_observer(UnixUserObserver.instance)
86
+ end
@@ -0,0 +1,115 @@
1
+ #--
2
+ # Copyright 2010 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #++
16
+
17
+ require 'rubygems'
18
+ require 'open4'
19
+
20
+ module OpenShift::Utils
21
+ class ShellExecutionException < Exception
22
+ attr_accessor :rc, :stdout, :stderr
23
+ def initialize(msg, rc=-1, stdout = nil, stderr = nil)
24
+ super msg
25
+ self.rc = rc
26
+ self.stdout = stdout
27
+ self.stderr = stderr
28
+ end
29
+ end
30
+ end
31
+
32
+ module OpenShift::Utils::ShellExec
33
+
34
+ def shellCmd(cmd, pwd = ".", ignore_err = true, expected_rc = 0, timeout = 3600)
35
+ OpenShift::Utils::ShellExec.shellCmd(cmd, pwd, ignore_err, expected_rc, timeout)
36
+ end
37
+
38
+ # Public: Execute shell command.
39
+ #
40
+ # iv - A String value for the IV file.
41
+ # cmd - A String value of the command to run.
42
+ # pwd - A String value of target working directory.
43
+ # ignore_err - A Boolean value to determine if errors should be ignored.
44
+ # expected_rc - A Integer value for the expected return code of cmd.
45
+ #
46
+ # Examples
47
+ # OpenShift::Utils::ShellExec.shellCmd('ls /etc/passwd')
48
+ # # => ["/etc/passwd\n","", 0]
49
+ #
50
+ # Returns An Array with [stdout, stderr, return_code]
51
+ def self.shellCmd(cmd, pwd = ".", ignore_err = true, expected_rc = 0, timeout = 3600)
52
+ out = err = rc = nil
53
+ begin
54
+ # Using Open4 spawn with cwd isn't thread safe
55
+ m_cmd = "cd #{pwd} && ( #{cmd} )"
56
+ pid, stdin, stdout, stderr = Open4.popen4ext(true, m_cmd)
57
+ begin
58
+ stdin.close
59
+ Timeout::timeout(timeout) do
60
+ out = stdout.read
61
+ err = stderr.read
62
+ end
63
+ rescue Timeout::Error
64
+ pstree = Hash.new{|a,b| a[b]=[b]}
65
+ pppids = Hash[*`ps -e -opid,ppid --no-headers`.map{|p| p.to_i}]
66
+ pppids.each do |l_pid, l_ppid|
67
+ pstree[l_ppid] << pstree[l_pid]
68
+ end
69
+ Process.kill("KILL", *(pstree[pid].flatten))
70
+ raise OpenShift::Utils::ShellExecutionException.new(
71
+ "Shell command '#{cmd}'' timed out (timeout is #{timeout})", -1. out, err)
72
+ ensure
73
+ stdout.close
74
+ stderr.close
75
+ rc = Process::waitpid2(pid)[1].exitstatus
76
+ end
77
+ rescue Exception => e
78
+ raise OpenShift::Utils::ShellExecutionException.new(e.message, rc, out, err
79
+ ) unless ignore_err
80
+ end
81
+
82
+ if !ignore_err and rc != expected_rc
83
+ raise OpenShift::Utils::ShellExecutionException.new(
84
+ "Shell command '#{cmd}' returned an error. rc=#{rc}", rc, out, err)
85
+ end
86
+ return [out, err, rc]
87
+ end
88
+
89
+ def self.run_as(uid, gid, cmd, pwd = ".", ignore_err = true, expected_rc = 0, timeout = 3600)
90
+ mcs_level, err, rc = OpenShift::Utils::ShellExec.shellCmd("/usr/bin/oo-get-mcs-level #{uid}", pwd, true, 0, timeout)
91
+ raise OpenShift::Utils::ShellExecutionException.new(
92
+ "Shell command '#{cmd}' returned an error. rc=#{rc}. output=#{err}", rc, mcs_level, err) if 0 != rc
93
+
94
+ command = "/usr/bin/runcon -r system_r -t openshift_t -l #{mcs_level.chomp} #{cmd}"
95
+ pid = fork {
96
+ Process::GID.change_privilege(gid.to_i)
97
+ Process::UID.change_privilege(uid.to_i)
98
+ out, err, rc = OpenShift::Utils::ShellExec.shellCmd(command, pwd, true, 0, timeout)
99
+ exit $?.exitstatus
100
+ }
101
+
102
+ if pid
103
+ Process.wait(pid)
104
+ rc = $?.exitstatus
105
+ if !ignore_err and rc != expected_rc
106
+ raise OpenShift::Utils::ShellExecutionException.new(
107
+ "Shell command '#{command}' returned an error. rc=#{rc}", rc)
108
+ end
109
+ return rc
110
+ else
111
+ raise OpenShift::Utils::ShellExecutionException.new(
112
+ "Shell command '#{command}' fork failed in run_as().")
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,23 @@
1
+ #--
2
+ # Copyright 2010 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #++
16
+
17
+
18
+ module OpenShift
19
+ VERSION = File.open("#{File.dirname(__FILE__)}/../../rubygem-openshift-origin-node.spec"
20
+ ).readlines.delete_if{ |x| !x.match(/Version:/)
21
+ }.first.split(':')[1].strip
22
+ SDK_PATH = File.dirname(__FILE__)
23
+ end
@@ -0,0 +1,482 @@
1
+ #!/bin/bash
2
+ lockfile=/var/lock/subsys/os-cgroups
3
+
4
+ # import openshift node configuration
5
+ if [ -f /etc/openshift/node.conf ]
6
+ then
7
+ . /etc/openshift/node.conf
8
+ fi
9
+
10
+ # import resource limit tuning values for cgroups
11
+ if [ -f /etc/openshift/resource_limits.conf ]
12
+ then
13
+ . /etc/openshift/resource_limits.conf
14
+ fi
15
+
16
+ RETVAL=0
17
+ GROUP_RETVAL=0
18
+
19
+ #
20
+ # Set defaults if not provided
21
+ #
22
+ GEAR_GECOS=${GEAR_GECOS:="OpenShift guest"}
23
+
24
+ OPENSHIFT_CGROUP_ROOT=${OPENSHIFT_CGROUP_ROOT:="/openshift"}
25
+ OPENSHIFT_CGROUP_SUBSYSTEMS=${OPENSHIFT_CGROUP_SUBSYSTEMS:="cpu,cpuacct,memory,net_cls,freezer"}
26
+
27
+ CGROUP_RULES_FILE=${CGROUP_RULES_FILE:="/etc/cgrules.conf"}
28
+
29
+ CPU_VARS="cfs_period_us cfs_quota_us rt_period_us rt_runtime_us shares"
30
+ MEM_VARS="limit_in_bytes memsw_limit_in_bytes soft_limit_in_bytes swappiness"
31
+
32
+ # Get a user's UID
33
+ function uid() {
34
+ # USERNAME=$1
35
+ getent passwd | grep -e "^$1:" | cut -d: -f3
36
+ }
37
+
38
+ # ============================================================================
39
+ # Functions for setting the net class
40
+ # ============================================================================
41
+
42
+ #
43
+ # Convert an MCS pair into a cgroup net class id
44
+ #
45
+ function classid() {
46
+ # major: 1, minor UID
47
+ printf "0x1%04x" $1
48
+ }
49
+
50
+ function set_net_cls() {
51
+ # USERNAME=$1
52
+ CGPATH=openshift/$1
53
+ USERID=`uid $1`
54
+ USERCLASSID=`classid $USERID`
55
+ cgset -r net_cls.classid=$USERCLASSID $CGPATH
56
+ }
57
+
58
+ # ==========================================================================
59
+ # Functions for tuning the user's CPU limits in cgroups
60
+ # ==========================================================================
61
+ CPUVARS="cfs_period_us cfs_quota_us rt_period_us rt_runtime_us shares"
62
+ function set_cpu() {
63
+ # USERNAME=$1
64
+ CGPATH=openshift/$1
65
+
66
+ for VARNAME in $CPUVARS
67
+ do
68
+ # cgroups names can have periods(.) shell varnames can't
69
+ SAFENAME=`echo $VARNAME | tr . _`
70
+ VALUE=`eval echo \\$cpu_$SAFENAME`
71
+ if [ -n "${VALUE}" ]
72
+ then
73
+ # TODO: get per-app increments
74
+ cgset -r "cpu.$VARNAME=$VALUE" $CGPATH
75
+ fi
76
+ done
77
+ }
78
+
79
+ # ==========================================================================
80
+ # Functions for tuning the user's memory limits in cgroups
81
+ # ==========================================================================
82
+ MEMVARS="limit_in_bytes memsw.limit_in_bytes soft_limit_in_bytes swappiness"
83
+ function set_memory() {
84
+ # USERNAME=$1
85
+ CGPATH=openshift/$1
86
+
87
+ # for each var get and set the value
88
+ for VARNAME in $MEMVARS
89
+ do
90
+ # cgroups names can have periods(.) shell varnames can't
91
+ SAFENAME=`echo $VARNAME | tr . _`
92
+ VALUE=`eval echo \\$memory_$SAFENAME`
93
+ if [ -n "${VALUE}" ]
94
+ then
95
+ # TODO: get per-app increments
96
+ cgset -r "memory.$VARNAME=$VALUE" $CGPATH
97
+ fi
98
+ done
99
+ }
100
+
101
+ # ==========================================================================
102
+ # Functions for tuning the user's memory limits in cgroups
103
+ # ==========================================================================
104
+ BLKIOVARS="weight weight_device"
105
+ function set_blkio() {
106
+ # USERNAME=$1
107
+ CGPATH=/$1
108
+
109
+ # for each var get and set the value
110
+ for VARNAME in $BLKIOVARS
111
+ do
112
+ # cgroups names can have periods(.) shell varnames can't
113
+ SAFENAME=`echo $VARNAME | tr . _`
114
+ VALUE=`eval echo \\$blkio_$SAFENAME`
115
+ if [ -n "${VALUE}" ]
116
+ then
117
+ # TODO: get per-app increments
118
+ # TODO: weight_device should really use the user's home device
119
+ # and set the rest (if any) to 0
120
+ # cgset -r "blkio.$VARNAME=$VALUE" $CGPATH
121
+ echo nothing >>/dev/null
122
+ fi
123
+ done
124
+ }
125
+
126
+ # List the openshift guest users
127
+ #
128
+ openshift_users() {
129
+ getent passwd | grep "${GEAR_GECOS}" | cut -d: -f1
130
+ }
131
+
132
+ valid_user() {
133
+ # check if the user name exists and is tagged as a openshift guest user
134
+ getent passwd | grep ":${GEAR_GECOS}:" | cut -d: -f1 | grep -e "^$1\$" >/dev/null 2>&1
135
+ }
136
+
137
+ #
138
+ # Create a new openshift user cgroup
139
+ #
140
+ add_cgroup() {
141
+ # USERNAME=$1
142
+ cgcreate -t $1:$1 -g ${OPENSHIFT_CGROUP_SUBSYSTEMS}:${OPENSHIFT_CGROUP_ROOT}/$1
143
+ }
144
+
145
+ #
146
+ # Delete a openshift user cgroup
147
+ #
148
+ delete_cgroup() {
149
+ # USERNAME=$1
150
+ cgdelete ${OPENSHIFT_CGROUP_SUBSYSTEMS}:${OPENSHIFT_CGROUP_ROOT}/$1
151
+ }
152
+
153
+
154
+ #
155
+ # check which user cgroups exist
156
+ #
157
+ cgroup_user_subsystems() {
158
+ # USERNAME=$1
159
+ lscgroup | grep ":${OPENSHIFT_CGROUP_ROOT}/$1\$" | cut -d: -f1
160
+ }
161
+
162
+ #
163
+ # Check that a group binding rule exists for a user
164
+ #
165
+ cgroup_rule_exists() {
166
+ #USERNAME=$1
167
+ # remove comments, get first field, match exactly, quiet
168
+ grep -v '^#' ${CGROUP_RULES_FILE} | cut -f1 | grep -q -x $1
169
+ }
170
+
171
+
172
+ #
173
+ # Bind the user to the cgroup: update /etc/cgrules.conf and kick cgred
174
+ #
175
+ add_cgroup_rule() {
176
+ # USERNAME=$1
177
+ cat <<EOF >>${CGROUP_RULES_FILE}
178
+ $1 $OPENSHIFT_CGROUP_SUBSYSTEMS $OPENSHIFT_CGROUP_ROOT/$1
179
+ EOF
180
+ }
181
+
182
+ #
183
+ # Unbind the user from any cgroup
184
+ #
185
+ delete_cgroup_rule() {
186
+ # USERNAME=$1
187
+ sed -i -e "/^$1\s/d" ${CGROUP_RULES_FILE}
188
+ }
189
+
190
+ #
191
+ # Add the user's processes to the new group
192
+ #
193
+ collect_tasks() {
194
+ # USERNAME=$1
195
+
196
+ # add existing processes to the group
197
+ for PID in $(ps -opid= -u $1) ; do
198
+ echo $PID > /cgroup/all/${OPENSHIFT_CGROUP_ROOT}/$1/tasks
199
+ done
200
+ }
201
+
202
+ startuser() {
203
+ NEWUSER=$1
204
+
205
+ echo -n "starting cgroups for $NEWUSER..."
206
+
207
+ add_cgroup $NEWUSER
208
+ if [ $? != 0 ]
209
+ then
210
+ RETVAL=$?
211
+ fi
212
+
213
+ set_cpu $NEWUSER
214
+ set_memory $NEWUSER
215
+ #set_blkio $NEWUSER
216
+ set_net_cls $NEWUSER
217
+
218
+ # CHECK: don't trust old rules
219
+ if ( cgroup_rule_exists $NEWUSER )
220
+ then
221
+ delete_cgroup_rule $NEWUSER
222
+ fi
223
+ add_cgroup_rule $NEWUSER
224
+ if [ $? != 0 ]
225
+ then
226
+ RETVAL=$?
227
+ fi
228
+
229
+ collect_tasks $NEWUSER
230
+
231
+ if [ $RETVAL -eq 0 ]
232
+ then
233
+ echo -n " [OK] "
234
+ else
235
+ GROUP_RETVAL=$(($GROUP_RETVAL+1))
236
+ echo -n " [FAILED] "
237
+ fi
238
+ echo
239
+ }
240
+
241
+ startall() {
242
+ echo "Initializing Openshift guest control groups: "
243
+
244
+ if !(service cgconfig status >/dev/null)
245
+ then
246
+ RETVAL=1
247
+ GROUP_RETVAL=3
248
+ echo "cgconfig service not running. attempting to start it"
249
+ service cgconfig start
250
+ return $GROUP_RETVAL
251
+ fi
252
+
253
+ if !(service cgconfig status >/dev/null)
254
+ then
255
+ RETVAL=1
256
+ GROUP_RETVAL=3
257
+ echo "cgconfig service not running."
258
+
259
+ return $GROUP_RETVAL
260
+ fi
261
+
262
+ # don't start if not configured for openshift
263
+ if [ ! -d /cgroup/all ]
264
+ then
265
+ echo "cgconfig not set for Openshift: /cgconfig/all does not exist"
266
+ RETVAL=1
267
+ GROUP_RETVAL=3
268
+ return $GROUP_RETVAL
269
+ fi
270
+
271
+ # create the root of the openshift user control group
272
+ add_cgroup # defaults to creating the root group
273
+ RETVAL=$?
274
+
275
+ # This won't scale forever, but works fine in the '100 or so' range
276
+ for USERNAME in `openshift_users`
277
+ do
278
+ startuser $USERNAME
279
+ done
280
+
281
+ # kick the Cgroups rules daemon
282
+ #service cgred reload
283
+ pkill -USR2 cgrulesengd
284
+
285
+ [ $GROUP_RETVAL -eq 0 ] && touch ${lockfile}
286
+ [ $GROUP_RETVAL -eq 0 ] && (echo -n "[ OK ]") || (echo -n "[ FAILED ]")
287
+
288
+ echo -n $"Openshift cgroups initialized"
289
+ echo
290
+ return $GROUP_RETVAL
291
+ echo
292
+ echo "WARNING !!! WARNING !!! WARNING !!!"
293
+ echo "Cgroups may have just restarted. It's important to confirm all the openshift apps are actively running."
294
+ echo "It's suggested you run service openshift restart now"
295
+ echo "WARNING !!! WARNING !!! WARNING !!!"
296
+ echo
297
+ }
298
+
299
+ stopuser() {
300
+ DELUSER=$1
301
+ echo -n "stopping cgroups for $DELUSER..."
302
+
303
+ # kill any processes owned by these users
304
+ #pkill -u $DELUSER
305
+
306
+ # remove the user's cgroup
307
+ delete_cgroup $DELUSER
308
+ if [ $? != 0 ]
309
+ then
310
+ RETVAL=$?
311
+ fi
312
+
313
+ # remove the user's cgroup binding rule
314
+ delete_cgroup_rule $DELUSER
315
+ if [ $? != 0 ]
316
+ then
317
+ RETVAL=$?
318
+ fi
319
+
320
+ if [ $RETVAL -eq 0 ]
321
+ then
322
+ echo -n "[ OK ]"
323
+ else
324
+ GROUP_RETVAL=$(($GROUP_RETVAL+1))
325
+ echo -n "[ FAILED ]"
326
+ fi
327
+ }
328
+
329
+ stopall() {
330
+ echo "Removing Openshift guest control groups: "
331
+
332
+ if !(service cgconfig status >/dev/null)
333
+ then
334
+ RETVAL=1
335
+ GROUP_RETVAL=3
336
+ echo "cgconfig service not running"
337
+
338
+ return $GROUP_RETVAL
339
+ fi
340
+
341
+ # This won't scale forever, but works fine in the '100 or so' range
342
+ for USERNAME in `openshift_users`
343
+ do
344
+ stopuser $USERNAME
345
+ done
346
+
347
+ # notify the cgroup rule daemon
348
+ #service cgred reload
349
+ pkill -USR2 cgrulesengd
350
+
351
+ # remove the openshift root cgroup
352
+ delete_cgroup
353
+
354
+ if [ $RETVAL -eq 0 ]
355
+ then
356
+ echo -n "[ OK ]"
357
+ else
358
+ GROUP_RETVAL=$(($GROUP_RETVAL+1))
359
+ echo -n "[ FAILED ]"
360
+ fi
361
+
362
+ [ $GROUP_RETVAL -eq 0 ] && touch ${lockfile}
363
+ echo -n $"Openshift cgroups uninitialized"
364
+ echo
365
+ return $GROUP_RETVAL
366
+ }
367
+
368
+ restartall() {
369
+ stopall
370
+ startall
371
+ }
372
+
373
+ status() {
374
+ echo "Checking Openshift Services: "
375
+
376
+ # don't start if not configured for openshift
377
+ if [ ! -d /cgroup/all ]
378
+ then
379
+ echo "Openshift cgroups not configured: /cgconfig/all does not exist"
380
+ return 1
381
+ fi
382
+
383
+ lscgroup | grep -e ":${OPENSHIFT_CGROUP_ROOT}\$" >/dev/null 2>&1
384
+ if [ $? -ne 0 ]
385
+ then
386
+ echo "Openshift cgroups uninitialized"
387
+ echo
388
+ return 1
389
+ else
390
+ echo "Openshift cgroups initialized"
391
+ fi
392
+
393
+ if [ -z "$1" ]
394
+ then
395
+ USERLIST=`openshift_users`
396
+ else
397
+ USERLIST=$1
398
+ fi
399
+
400
+ # check that the /openshift cgroup exists
401
+
402
+ # This won't scale forever, but works fine in the '100 or so' range
403
+ # would be easy to convert to a 'in `find...`' jj
404
+ for USERNAME in $USERLIST
405
+ do
406
+ # check that /openshift/<username> exists
407
+ SUBSYSTEMS=`cgroup_user_subsystems`
408
+ if ( cgroup_rule_exists $USERNAME )
409
+ then
410
+ RETVAL=0
411
+ BOUND="BOUND"
412
+ else
413
+ RETVAL=1
414
+ BOUND="UNBOUND"
415
+ fi
416
+
417
+ echo -n "${USERNAME}: $BOUND " `echo $SUBSYSTEMS | tr ' ' ,`
418
+ # check that cgrule exists
419
+
420
+ if [ $RETVAL -eq 0 ]
421
+ then
422
+ echo -n "[ OK ]"
423
+ else
424
+ GROUP_RETVAL=$(($GROUP_RETVAL+1))
425
+ echo -n "[ FAILED ]"
426
+ fi
427
+ echo
428
+ done
429
+ return $GROUP_RETVAL
430
+ }
431
+
432
+ case "$1" in
433
+ startall)
434
+ startall
435
+ ;;
436
+
437
+ stopall)
438
+ stopall
439
+ ;;
440
+
441
+ restartall)
442
+ restartall
443
+ ;;
444
+
445
+ condrestartall)
446
+ [ -f "$lockfile" ] && restartall
447
+ ;;
448
+
449
+ status)
450
+ status $2
451
+ ;;
452
+
453
+ startuser)
454
+ if (service cgconfig status >/dev/null)
455
+ then
456
+ startuser $2
457
+ #service cgred reload
458
+ pkill -USR2 cgrulesengd
459
+ else
460
+ RETVAL=1
461
+ echo "cgconfig service not running"
462
+ fi
463
+ ;;
464
+
465
+ stopuser)
466
+ if (service cgconfig status >/dev/null)
467
+ then
468
+ stopuser $2
469
+ #service cgred reload
470
+ pkill -USR2 cgrulesengd
471
+ else
472
+ RETVAL=1
473
+ echo "cgconfig service not running"
474
+ fi
475
+ ;;
476
+
477
+ *)
478
+ echo $"Usage: $0 {start|stop|status|restart|condrestart|startuser <username>|stopuser <username>}"
479
+ exit 1
480
+ esac
481
+
482
+ exit $RETVAL