Class: OpenShift::UnixUserObserver

Inherits:
Object
  • Object
show all
Includes:
Object::Singleton, OpenShift::Utils::ShellExec
Defined in:
lib/openshift-origin-node/plugins/unix_user_observer.rb

Instance Method Summary collapse

Methods included from OpenShift::Utils::ShellExec

run_as, shellCmd, #shellCmd

Instance Method Details

#after_add_ssh_key(user, key) ⇒ Object



72
73
74
75
76
# File 'lib/openshift-origin-node/plugins/unix_user_observer.rb', line 72

def after_add_ssh_key(user,key)
  ssh_dir = File.join(user.homedir, ".ssh")
  cmd = "restorecon -R #{ssh_dir}"
  shellCmd(cmd)
end

#after_initialize_homedir(user) ⇒ Object



32
33
34
35
36
# File 'lib/openshift-origin-node/plugins/unix_user_observer.rb', line 32

def after_initialize_homedir(user)
  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 : ''}"
  out,err,rc = shellCmd(cmd)
  raise OpenShift::UserCreationException.new("Unable to setup pam/fs limits for #{user.name}: stdout -- #{out} stderr -- #{err}") unless rc == 0
end

#after_initialize_openshift_port_proxy(user) ⇒ Object



56
57
# File 'lib/openshift-origin-node/plugins/unix_user_observer.rb', line 56

def after_initialize_openshift_port_proxy(user)
end

#after_remove_ssh_key(user, key) ⇒ Object



81
82
# File 'lib/openshift-origin-node/plugins/unix_user_observer.rb', line 81

def after_remove_ssh_key(user,key)
end

#after_unix_user_create(user) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/openshift-origin-node/plugins/unix_user_observer.rb', line 21

def after_unix_user_create(user)
  out,err,rc = shellCmd("service cgconfig status > /dev/null 2>&1")
  if rc == 0
    out,err,rc = shellCmd("/usr/bin/oo-admin-ctl-cgroups startuser #{user.name} > /dev/null")
    raise OpenShift::UserCreationException.new("Unable to setup cgroups for #{user.name}: stdout -- #{out} stderr --#{err}}") unless rc == 0
  end
end

#after_unix_user_destroy(user) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/openshift-origin-node/plugins/unix_user_observer.rb', line 59

def after_unix_user_destroy(user)
  out,err,rc = shellCmd("service cgconfig status > /dev/null")
  shellCmd("/usr/bin/oo-admin-ctl-cgroups thawuser #{user.name} > /dev/null") if rc == 0
  shellCmd("/usr/bin/oo-admin-ctl-cgroups stopuser #{user.name} > /dev/null") if rc == 0

  cmd = "/bin/sh #{File.join("/usr/libexec/openshift/lib", "teardown_pam_fs_limits.sh")} #{user.name}"
  out,err,rc = shellCmd(cmd)
  raise OpenShift::UserCreationException.new("Unable to teardown pam/fs/nproc limits for #{user.name}") unless rc == 0
end

#before_add_ssh_key(user, key) ⇒ Object



69
70
# File 'lib/openshift-origin-node/plugins/unix_user_observer.rb', line 69

def before_add_ssh_key(user,key)
end

#before_initialize_homedir(user) ⇒ Object



29
30
# File 'lib/openshift-origin-node/plugins/unix_user_observer.rb', line 29

def before_initialize_homedir(user)
end

#before_initialize_openshift_port_proxy(user) ⇒ Object



53
54
# File 'lib/openshift-origin-node/plugins/unix_user_observer.rb', line 53

def before_initialize_openshift_port_proxy(user)
end

#before_remove_ssh_key(user, key) ⇒ Object



78
79
# File 'lib/openshift-origin-node/plugins/unix_user_observer.rb', line 78

def before_remove_ssh_key(user,key)
end

#before_unix_user_create(user) ⇒ Object



18
19
# File 'lib/openshift-origin-node/plugins/unix_user_observer.rb', line 18

def before_unix_user_create(user)
end

#before_unix_user_destroy(user) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/openshift-origin-node/plugins/unix_user_observer.rb', line 39

def before_unix_user_destroy(user)
  cmd = "/bin/sh #{File.join('/usr/libexec/openshift/lib', "setup_pam_fs_limits.sh")} #{user.name} 0 0 0"
  out,err,rc = shellCmd(cmd)
  raise OpenShift::UserCreationException.new("Unable to setup pam/fs/nproc limits for #{user.name}") unless rc == 0

  out,err,rc = shellCmd("service cgconfig status > /dev/null")
  if rc == 0
    shellCmd("/usr/bin/oo-admin-ctl-cgroups freezeuser #{user.name} > /dev/null") if rc == 0
  end

  last_access_dir = OpenShift::Config.instance.get("LAST_ACCESS_DIR")
  shellCmd("rm -f #{last_access_dir}/#{user.name} > /dev/null")
end

#update(*args) ⇒ Object



12
13
14
15
16
# File 'lib/openshift-origin-node/plugins/unix_user_observer.rb', line 12

def update(*args)
  method = args.first
  args = args.drop(1)
  send(method, *args)
end