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

Unix sockets #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
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