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