Class: Unicorn::HttpServer::Worker
- Inherits:
-
Struct
- Object
- Struct
- Unicorn::HttpServer::Worker
- Defined in:
- lib/unicorn.rb
Overview
This class and its members can be considered a stable interface and will not change in a backwards-incompatible fashion between releases of Unicorn. You may need to access it in the before_fork/after_fork hooks. See the Unicorn::Configurator RDoc for examples.
Instance Attribute Summary collapse
-
#nr ⇒ Object
Returns the value of attribute nr.
-
#switched ⇒ Object
Returns the value of attribute switched.
-
#tmp ⇒ Object
Returns the value of attribute tmp.
Instance Method Summary collapse
-
#==(other_nr) ⇒ Object
worker objects may be compared to just plain numbers.
-
#user(user, group = nil) ⇒ Object
Changes the worker process to the specified
userandgroupThis is only intended to be called from within the worker process from theafter_forkhook.
Instance Attribute Details
#nr ⇒ Object
Returns the value of attribute nr
166 167 168 |
# File 'lib/unicorn.rb', line 166 def nr @nr end |
#switched ⇒ Object
Returns the value of attribute switched
166 167 168 |
# File 'lib/unicorn.rb', line 166 def switched @switched end |
#tmp ⇒ Object
Returns the value of attribute tmp
166 167 168 |
# File 'lib/unicorn.rb', line 166 def tmp @tmp end |
Instance Method Details
#==(other_nr) ⇒ Object
worker objects may be compared to just plain numbers
169 170 171 |
# File 'lib/unicorn.rb', line 169 def ==(other_nr) self.nr == other_nr end |
#user(user, group = nil) ⇒ Object
Changes the worker process to the specified user and group This is only intended to be called from within the worker process from the after_fork hook. This should be called in the after_fork hook after any priviledged functions need to be run (e.g. to set per-worker CPU affinity, niceness, etc)
Any and all errors raised within this method will be propagated directly back to the caller (usually the after_fork hook. These errors commonly include ArgumentError for specifying an invalid user/group and Errno::EPERM for insufficient priviledges
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/unicorn.rb', line 183 def user(user, group = nil) # we do not protect the caller, checking Process.euid == 0 is # insufficient because modern systems have fine-grained # capabilities. Let the caller handle any and all errors. uid = Etc.getpwnam(user).uid gid = Etc.getgrnam(group).gid if group Unicorn::Util.chown_logs(uid, gid) tmp.chown(uid, gid) if gid && Process.egid != gid Process.initgroups(user, gid) Process::GID.change_privilege(gid) end Process.euid != uid and Process::UID.change_privilege(uid) self.switched = true end |