Method: Eye::System.spawn_options

Defined in:
lib/eye/system.rb

.spawn_options(config = {}) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/eye/system.rb', line 112

def spawn_options(config = {})
  options = {
    pgroup: true,
    chdir: config[:working_dir] || '/'
  }

  options[:out]   = [config[:stdout], 'a'] if config[:stdout]
  options[:err]   = [config[:stderr], 'a'] if config[:stderr]
  options[:in]    = config[:stdin] if config[:stdin]
  options[:umask] = config[:umask] if config[:umask]
  options[:close_others] = false if config[:preserve_fds]
  options[:unsetenv_others] = true if config[:clear_env]

  if Eye::Local.root?
    options[:uid] = Etc.getpwnam(config[:uid]).uid if config[:uid]
    options[:gid] = Etc.getgrnam(config[:gid]).gid if config[:gid]
  end

  options
end