Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple groups support #102

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/god/process.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Process


attr_accessor :name, :uid, :gid, :log, :log_cmd, :err_log, :err_log_cmd, attr_accessor :name, :uid, :gid, :log, :log_cmd, :err_log, :err_log_cmd,
:start, :stop, :restart, :unix_socket, :chroot, :env, :dir, :start, :stop, :restart, :unix_socket, :chroot, :env, :dir,
:stop_timeout, :stop_signal, :umask :stop_timeout, :stop_signal, :umask, :gids


def initialize def initialize
self.log = '/dev/null' self.log = '/dev/null'
Expand Down Expand Up @@ -80,6 +80,18 @@ def valid?
end end
end end


# if multiple gids is provided
if self.gids
self.gids.each do |g|
begin
Etc.getgrnam(g)
rescue ArgumentError
valid = false
applog(self, :error, "GID for '#{g}' does not exist")
end
end
end

# dir must exist and be a directory if specified # dir must exist and be a directory if specified
if self.dir if self.dir
if !File.exist?(self.dir) if !File.exist?(self.dir)
Expand Down Expand Up @@ -289,10 +301,12 @@ def spawn(command)
File.umask self.umask if self.umask File.umask self.umask if self.umask
uid_num = Etc.getpwnam(self.uid).uid if self.uid uid_num = Etc.getpwnam(self.uid).uid if self.uid
gid_num = Etc.getgrnam(self.gid).gid if self.gid gid_num = Etc.getgrnam(self.gid).gid if self.gid
gids_num = (self.gids || []).map{|g| Etc.getgrnam(g).gid}


::Dir.chroot(self.chroot) if self.chroot ::Dir.chroot(self.chroot) if self.chroot
::Process.setsid ::Process.setsid
::Process.groups = [gid_num] if self.gid ::Process.groups = [gid_num] if self.gid
::Process.groups |= gids_num unless gids_num.empty?
::Process::Sys.setgid(gid_num) if self.gid ::Process::Sys.setgid(gid_num) if self.gid
::Process::Sys.setuid(uid_num) if self.uid ::Process::Sys.setuid(uid_num) if self.uid
self.dir ||= '/' self.dir ||= '/'
Expand Down
16 changes: 16 additions & 0 deletions test/test_process.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ def test_valid_should_return_false_if_gid_does_not_exists
assert !@p.valid? assert !@p.valid?
end end


def test_valid_should_return_true_if_gids_exists
@p.start = 'qux'
@p.log = '/tmp/foo.log'
@p.gids = %w{wheel root}

assert @p.valid?
end

def test_valid_should_return_false_if_gids_does_not_exists
@p.start = 'qux'
@p.log = '/tmp/foo.log'
@p.gids = %w{foobarbaz root}

assert !@p.valid?
end

def test_valid_should_return_true_if_dir_exists def test_valid_should_return_true_if_dir_exists
@p.start = 'qux' @p.start = 'qux'
@p.log = '/tmp/foo.log' @p.log = '/tmp/foo.log'
Expand Down