Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Commit

Permalink
support unix sockets in puma/unicorn/thin
Browse files Browse the repository at this point in the history
  • Loading branch information
James committed Feb 23, 2018
1 parent aa3cd87 commit ce62ba9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
17 changes: 16 additions & 1 deletion lib/poise_application_ruby/resources/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class Resource < Chef::Resource
# @!attribute port
# Port to bind to.
attribute(:port, kind_of: [String, Integer], default: 80)

# @!attribute socket
# Listen on a unix socket instead of a port
attribute(:socket, kind_of: [TrueClass, FalseClass], default: false)
end

# Provider for `application_puma`.
Expand All @@ -75,10 +79,21 @@ def configru_path
end
end

# Path to the socket file.
#
# @return [String]
def socket_path
@socket_path ||= "unix:///var/run/#{::File.basename(new_resource.path)}.sock"
end

# Set service resource options.
def service_options(resource)
super
resource.ruby_command("puma --port #{new_resource.port} #{configru_path}")
unless new_resource.socket
resource.ruby_command("puma --port #{new_resource.port} #{configru_path}")
else
resource.ruby_command("puma -b #{socket_path} #{configru_path}")
end
end
end
end
Expand Down
17 changes: 16 additions & 1 deletion lib/poise_application_ruby/resources/thin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class Resource < Chef::Resource

attribute(:port, kind_of: [String, Integer], default: 80)
attribute(:config_path, kind_of: String)

# @!attribute socket
# Listen on a unix socket instead of a port
attribute(:socket, kind_of: [TrueClass, FalseClass], default: false)
end

class Provider < Chef::Provider
Expand All @@ -51,10 +55,21 @@ def configru_path
end
end

# Path to the socket file.
#
# @return [String]
def socket_path
@socket_path ||= "unix:///var/run/#{::File.basename(new_resource.path)}.sock"
end

# (see PoiseApplication::ServiceMixin#service_options)
def service_options(resource)
super
cmd = "thin --rackup #{configru_path} --port #{new_resource.port}"
unless new_resource.socket
cmd = "thin --rackup #{configru_path} --port #{new_resource.port}"
else
cmd = "thin --rackup #{configru_path} --socket #{socket_path}"
end
cmd << " --config #{::File.expand_path(new_resource.config_path, new_resource.path)}" if new_resource.config_path
resource.ruby_command(cmd)
end
Expand Down
17 changes: 16 additions & 1 deletion lib/poise_application_ruby/resources/unicorn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class Resource < Chef::Resource
# @!attribute port
# Port to bind to.
attribute(:port, kind_of: [String, Integer], default: 80)

# @!attribute socket
# Listen on a unix socket instead of a port
attribute(:socket, kind_of: [TrueClass, FalseClass], default: false)
end

# Provider for `application_unicorn`.
Expand All @@ -76,10 +80,21 @@ def configru_path
end
end

# Path to the socket file.
#
# @return [String]
def socket_path
@socket_path ||= "unix:///var/run/#{::File.basename(new_resource.path)}.sock"
end

# Set service resource options.
def service_options(resource)
super
resource.ruby_command("unicorn --port #{new_resource.port} #{configru_path}")
unless new_resource.socket
resource.ruby_command("unicorn --port #{new_resource.port} #{configru_path}")
else
resource.ruby_command("unicorn -l #{socket_path} #{configru_path}")
end
end
end
end
Expand Down

0 comments on commit ce62ba9

Please sign in to comment.