Skip to content
Open
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
4 changes: 4 additions & 0 deletions bin/god
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ begin
options[:pid] = x
end

opts.on("-SDIR", "--socket_path DIR", "Where to write the socket file") do |x|
options[:socket_dir] = x
end

opts.on("-lFILE", "--log FILE", "Where to write the log file") do |x|
options[:log] = x
end
Expand Down
5 changes: 3 additions & 2 deletions lib/god.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ class << self
:terminate_timeout,
:socket_user,
:socket_group,
:socket_perms
:socket_perms,
:socket_dir

# internal
attr_accessor :inited,
Expand Down Expand Up @@ -443,7 +444,7 @@ def self.uncontact(contact)
end

def self.watches_by_name(name)
case name
case name
when "", nil then self.watches.values.dup
else Array(self.watches[name] || self.groups[name]).dup
end
Expand Down
4 changes: 4 additions & 0 deletions lib/god/cli/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def default_run
God.port = @options[:port]
end

if @options[:socket_dir]
God.socket_dir = @options[:socket_dir]
end

if @options[:events]
God::EventHandler.load
end
Expand Down
5 changes: 3 additions & 2 deletions lib/god/socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class Socket
#
# Returns String (file location)
def self.socket_file(port)
"/tmp/god.#{port}.sock"
dir = File.absolute_path(God.socket_dir || "/tmp")
"#{dir}/god.#{port}.sock"
end

# The address of the socket for a given port
Expand Down Expand Up @@ -93,7 +94,7 @@ def start
end
end

if File.exists?(self.socket_file)
if File.exist?(self.socket_file)
if @user
user_method = @user.is_a?(Integer) ? :getpwuid : :getpwnam
uid = Etc.send(user_method, @user).uid
Expand Down
8 changes: 7 additions & 1 deletion test/test_socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_should_start_a_drb_server
end

def test_should_use_supplied_port_and_host
DRb.expects(:start_service).with { |uri, object| uri == "drbunix:///tmp/god.9999.sock" && object.is_a?(God::Socket) }
DRb.expects(:start_service).with { |uri, object| uri == "drbunix://#{God::Socket.socket_file(9999)}" && object.is_a?(God::Socket) }
server = God::Socket.new(9999)
end

Expand All @@ -31,4 +31,10 @@ def test_ping_should_return_true
server = God::Socket.new
assert server.ping
end

def test_should_use_socket_dir_param
God.socket_dir = File.absolute_path(".")
socket_file = God::Socket.socket_file(9999)
assert_equal "#{File.absolute_path(".")}/god.9999.sock", socket_file
end
end