diff --git a/Library/Homebrew/service.rb b/Library/Homebrew/service.rb
index 8eaeac13fc..3d1de39211 100644
--- a/Library/Homebrew/service.rb
+++ b/Library/Homebrew/service.rb
@@ -190,15 +190,15 @@ module Homebrew
SOCKET_STRING_REGEX = %r{([a-z]+)://([a-z0-9.]+):([0-9]+)}i.freeze
sig {
- params(value: T.nilable(T.any(String, T::Hash[String, String])))
- .returns(T.nilable(T::Hash[String, T::Hash[Symbol, String]]))
+ params(value: T.nilable(T.any(String, T::Hash[Symbol, String])))
+ .returns(T.nilable(T::Hash[Symbol, T::Hash[Symbol, String]]))
}
def sockets(value = nil)
return @sockets if value.nil?
@sockets = case value
when String
- { "Listeners" => value }
+ { listeners: value }
when Hash
value
end.transform_values do |socket_string|
@@ -580,8 +580,6 @@ module Homebrew
raise ArgumentError, "Unexpected run command: #{api_hash["run"]}"
end
- hash[:keep_alive] = api_hash["keep_alive"].transform_keys(&:to_sym) if api_hash.key?("keep_alive")
-
if api_hash.key?("environment_variables")
hash[:environment_variables] = api_hash["environment_variables"].to_h do |key, value|
[key.to_sym, replace_placeholders(value)]
@@ -600,12 +598,22 @@ module Homebrew
hash[key.to_sym] = replace_placeholders(value)
end
- %w[interval cron launch_only_once require_root restart_delay macos_legacy_timers sockets].each do |key|
+ %w[interval cron launch_only_once require_root restart_delay macos_legacy_timers].each do |key|
next if (value = api_hash[key]).nil?
hash[key.to_sym] = value
end
+ %w[sockets keep_alive].each do |key|
+ next unless (value = api_hash[key])
+
+ hash[key.to_sym] = if value.is_a?(Hash)
+ value.transform_keys(&:to_sym)
+ else
+ value
+ end
+ end
+
hash
end
diff --git a/Library/Homebrew/test/service_spec.rb b/Library/Homebrew/test/service_spec.rb
index 1045dfed1d..7f28005fb0 100644
--- a/Library/Homebrew/test/service_spec.rb
+++ b/Library/Homebrew/test/service_spec.rb
@@ -281,7 +281,7 @@ describe Homebrew::Service do
\t
\tSockets
\t
- \t\tListeners
+ \t\tlisteners
\t\t
\t\t\tSockFamily
\t\t\tIPv4v6
@@ -299,7 +299,7 @@ describe Homebrew::Service do
[
stub_formula_with_service_sockets("tcp://127.0.0.1:80"),
- stub_formula_with_service_sockets({ "Listeners" => "tcp://127.0.0.1:80" }),
+ stub_formula_with_service_sockets({ listeners: "tcp://127.0.0.1:80" }),
].each do |f|
plist = f.service.to_plist
expect(plist).to eq(plist_expect)
@@ -310,7 +310,7 @@ describe Homebrew::Service do
f = stub_formula do
service do
run [opt_bin/"beanstalkd", "test"]
- sockets "Socket" => "tcp://0.0.0.0:80", "SocketTLS" => "tcp://0.0.0.0:443"
+ sockets socket: "tcp://0.0.0.0:80", socket_tls: "tcp://0.0.0.0:443"
end
end
@@ -339,7 +339,7 @@ describe Homebrew::Service do
\t
\tSockets
\t
- \t\tSocket
+ \t\tsocket
\t\t
\t\t\tSockFamily
\t\t\tIPv4v6
@@ -350,7 +350,7 @@ describe Homebrew::Service do
\t\t\tSockServiceName
\t\t\t80
\t\t
- \t\tSocketTLS
+ \t\tsocket_tls
\t\t
\t\t\tSockFamily
\t\t\tIPv4v6
@@ -1049,7 +1049,7 @@ describe Homebrew::Service do
run_type: :immediate,
working_dir: "/$HOME",
cron: "0 0 * * 0",
- sockets: { "Listeners" => "tcp://0.0.0.0:80" },
+ sockets: { listeners: "tcp://0.0.0.0:80" },
}
end
diff --git a/docs/Formula-Cookbook.md b/docs/Formula-Cookbook.md
index 05ea59c9dd..5cd70c0336 100644
--- a/docs/Formula-Cookbook.md
+++ b/docs/Formula-Cookbook.md
@@ -1052,7 +1052,7 @@ The `sockets` method accepts a formatted socket definition as `://:<
Please note that sockets will be accessible on IPv4 and IPv6 addresses by default.
-If you only need one socket and you don't care about the name (the default is `Listeners`):
+If you only need one socket and you don't care about the name (the default is `listeners`):
```rb
service do
@@ -1066,7 +1066,7 @@ If you need multiple sockets and/or you want to specify the name:
```rb
service do
run [opt_bin/"beanstalkd", "test"]
- sockets "Socket" => "tcp://0.0.0.0:80", "SocketTLS" => "tcp://0.0.0.0:443"
+ sockets http: "tcp://0.0.0.0:80", https: "tcp://0.0.0.0:443"
end
```