Skip to content

Instantly share code, notes, and snippets.

@adrianpike
Created October 17, 2010 18:48
Show Gist options
  • Save adrianpike/631126 to your computer and use it in GitHub Desktop.
Save adrianpike/631126 to your computer and use it in GitHub Desktop.
begin
uid, gid = Process.euid, Process.egid
user, group = 'apps', 'apps'
target_uid = Etc.getpwnam(user).uid
target_gid = Etc.getgrnam(group).gid
worker.tmp.chown(target_uid, target_gid)
if uid != target_uid || gid != target_gid
Process.initgroups(user, target_gid)
Process::GID.change_privilege(target_gid)
Process::UID.change_privilege(target_uid)
end
rescue => e
if RAILS_ENV == 'development'
STDERR.puts "couldn't change user, oh well"
else
raise e
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment