def destroy
if @uid.nil? and (not File.directory?(@homedir.to_s))
return nil
end
raise UserDeletionException.new(
"ERROR: unable to destroy user account #{@uuid}"
) if @uid.nil? || @homedir.nil? || @uuid.nil?
uuid_lock_file = "/var/lock/oo-create.#{@uuid}"
File.open(uuid_lock_file, File::RDWR|File::CREAT, 0o0600) do | lock |
lock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
lock.flock(File::LOCK_EX)
kill_procs(@uid)
notify_observers(:before_unix_user_destroy)
kill_procs(@uid)
purge_sysvipc(uuid)
initialize_openshift_port_proxy
if @config.get("CREATE_APP_SYMLINKS").to_i == 1
Dir.foreach(File.dirname(@homedir)) do |dent|
unobfuscate = File.join(File.dirname(@homedir), dent)
if (File.symlink?(unobfuscate)) &&
(File.readlink(unobfuscate) == File.basename(@homedir))
File.unlink(unobfuscate)
end
end
end
basedir = @config.get("GEAR_BASE_DIR")
path = File.join(basedir, ".httpd.d", "#{uuid}_*")
FileUtils.rm_rf(Dir.glob(path))
dirs = list_home_dir(@homedir)
out,err,rc = shellCmd("userdel -f \"#{@uuid}\"")
raise UserDeletionException.new(
"ERROR: unable to destroy user account(#{rc}): #{@uuid} stdout: #{out} stderr:#{err}") unless rc == 0
FileUtils.rm_rf(@homedir)
if File.exists?(@homedir)
Syslog.alert "1st attempt to remove \'#{@homedir}\' from filesystem failed."
Syslog.alert "Dir(before) #{@uuid}/#{@uid} => #{dirs}"
Syslog.alert "Dir(after) #{@uuid}/#{@uid} => #{list_home_dir(@homedir)}"
end
notify_observers(:after_unix_user_destroy)
if File.exists?(@homedir)
sleep(5)
FileUtils.rm_rf(@homedir)
Syslog.alert "2nd attempt to remove \'#{@homedir}\' from filesystem failed." if File.exists?(@homedir)
end
lock.flock(File::LOCK_UN)
File.unlink(uuid_lock_file)
end
end