@@ -179,6 +179,7 @@ def self.run(*args, global: false, file: nil, subcommand: "", services: false)
179
179
params (
180
180
entries : T ::Array [ Homebrew ::Bundle ::Dsl ::Entry ] ,
181
181
_block : T . proc . params (
182
+ entry : Homebrew ::Bundle ::Dsl ::Entry ,
182
183
info : T ::Hash [ String , T . anything ] ,
183
184
service_file : Pathname ,
184
185
conflicting_services : T ::Array [ T ::Hash [ String , T . anything ] ] ,
@@ -195,6 +196,8 @@ def self.run(*args, global: false, file: nil, subcommand: "", services: false)
195
196
[ entry , formula ]
196
197
end . to_h
197
198
199
+ return if entries_formulae . empty?
200
+
198
201
conflicts = entries_formulae . to_h do |entry , formula |
199
202
[
200
203
entry ,
@@ -245,15 +248,20 @@ def self.run(*args, global: false, file: nil, subcommand: "", services: false)
245
248
246
249
raise "Failed to get service info for #{ entry . name } " if info . nil?
247
250
248
- yield info , service_file , conflicting_services
251
+ yield entry , info , service_file , conflicting_services
249
252
end
250
253
end
251
254
252
255
sig { params ( entries : T ::Array [ Homebrew ::Bundle ::Dsl ::Entry ] , _block : T . nilable ( T . proc . void ) ) . void }
253
256
private_class_method def self . run_services ( entries , &_block )
257
+ entries_to_stop = [ ]
254
258
services_to_restart = [ ]
255
259
256
- map_service_info ( entries ) do |info , service_file , conflicting_services |
260
+ map_service_info ( entries ) do |entry , info , service_file , conflicting_services |
261
+ # Don't restart if already running this version
262
+ loaded_file = Pathname . new ( info [ "loaded_file" ] . to_s )
263
+ next if info [ "running" ] && loaded_file &.file? && loaded_file &.realpath == service_file . realpath
264
+
257
265
if info [ "running" ] && !Bundle ::BrewServices . stop ( info [ "name" ] , keep : true )
258
266
opoo "Failed to stop #{ info [ "name" ] } service"
259
267
end
@@ -269,6 +277,8 @@ def self.run(*args, global: false, file: nil, subcommand: "", services: false)
269
277
unless Bundle ::BrewServices . run ( info [ "name" ] , file : service_file )
270
278
opoo "Failed to start #{ info [ "name" ] } service"
271
279
end
280
+
281
+ entries_to_stop << entry
272
282
end
273
283
274
284
return unless block_given?
@@ -277,7 +287,7 @@ def self.run(*args, global: false, file: nil, subcommand: "", services: false)
277
287
yield
278
288
ensure
279
289
# Do a full re-evaluation of services instead state has changed
280
- stop_services ( entries )
290
+ stop_services ( entries_to_stop )
281
291
282
292
services_to_restart . each do |service |
283
293
next if Bundle ::BrewServices . run ( service )
@@ -289,7 +299,7 @@ def self.run(*args, global: false, file: nil, subcommand: "", services: false)
289
299
290
300
sig { params ( entries : T ::Array [ Homebrew ::Bundle ::Dsl ::Entry ] ) . void }
291
301
private_class_method def self . stop_services ( entries )
292
- map_service_info ( entries ) do |info , _ , _ |
302
+ map_service_info ( entries ) do |_ , info , _ , _ |
293
303
next unless info [ "loaded" ]
294
304
295
305
# Try avoid services not started by `brew bundle services`
0 commit comments