diff --git a/lib/poise_application_ruby/resources/puma.rb b/lib/poise_application_ruby/resources/puma.rb index 3f574c3..7d8536a 100644 --- a/lib/poise_application_ruby/resources/puma.rb +++ b/lib/poise_application_ruby/resources/puma.rb @@ -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`. @@ -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 diff --git a/lib/poise_application_ruby/resources/thin.rb b/lib/poise_application_ruby/resources/thin.rb index 1124790..7ec798a 100644 --- a/lib/poise_application_ruby/resources/thin.rb +++ b/lib/poise_application_ruby/resources/thin.rb @@ -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 @@ -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 diff --git a/lib/poise_application_ruby/resources/unicorn.rb b/lib/poise_application_ruby/resources/unicorn.rb index 0728b51..294a26e 100644 --- a/lib/poise_application_ruby/resources/unicorn.rb +++ b/lib/poise_application_ruby/resources/unicorn.rb @@ -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`. @@ -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