Stop service if it is present on system (it may be spinning) (#95737)

Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
master
leunga1000 2022-02-24 14:52:11 +00:00 committed by GitHub
parent 689aebf452
commit 155ba9c303
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 5 deletions

View File

@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true
require "cli/parser"
@ -66,8 +67,10 @@ module Homebrew
# Following instructions from:
# https://www.postgresql.org/docs/10/static/pgupgrade.html
ohai "Upgrading #{name} data from #{pg_version_data} to #{pg_version_installed}..."
if /#{name}\s+started/.match?(Utils.popen_read("brew", "services", "list"))
services_json_output = Utils.popen_read("brew", "services", "info", "--all", "--json")
services_json = JSON.parse(services_json_output, object_class: OpenStruct)
loaded_service_names = services_json.select(&:loaded).map(&:name)
if loaded_service_names.include?(name)
system "brew", "services", "stop", name
service_stopped = true
elsif quiet_system "#{bin}/pg_ctl", "-D", datadir, "status"
@ -76,9 +79,7 @@ module Homebrew
end
# Shut down old server if it is up via brew services
if /#{old_pg_name}\s+started/.match?(Utils.popen_read("brew", "services", "list"))
system "brew", "services", "stop", old_pg_name
end
system "brew", "services", "stop", old_pg_name if loaded_service_names.include?(old_pg_name)
# get 'lc_collate' from old DB"
unless quiet_system "#{old_bin}/pg_ctl", "-w", "-D", datadir, "status"