Method: God::Process#spawn

Defined in:
lib/god/process.rb

#spawn(command) ⇒ Object

Fork/exec the given command, returns immediately

+command+ is the String containing the shell command

Returns nothing



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/god/process.rb', line 274

def spawn(command)
  fork do
    uid_num = Etc.getpwnam(self.uid).uid if self.uid
    gid_num = Etc.getgrnam(self.gid).gid if self.gid

    ::Dir.chroot(self.chroot) if self.chroot
    ::Process.setsid
    ::Process.groups = [gid_num] if self.gid
    ::Process::Sys.setgid(gid_num) if self.gid
    ::Process::Sys.setuid(uid_num) if self.uid
    Dir.chdir "/"
    $0 = command
    STDIN.reopen "/dev/null"
    if self.log_cmd
      STDOUT.reopen IO.popen(self.log_cmd, "a") 
    else
      STDOUT.reopen file_in_chroot(self.log), "a"        
    end
    STDERR.reopen STDOUT
    
    # close any other file descriptors
    3.upto(256){|fd| IO::new(fd).close rescue nil}

    if self.env && self.env.is_a?(Hash)
      self.env.each do |(key, value)|
        ENV[key] = value
      end
    end

    exec command unless command.empty?
  end
end