Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --no-wait argument #593

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def services_args
flag "--sudo-service-user=", description: "When run as root on macOS, run the service(s) as this user."
switch "--all", description: "Run <subcommand> on all services."
switch "--json", description: "Output as JSON."
switch "--no-wait", description: "Don't wait for `stop` to finish stopping the service."
named_args max: 2
end
end
Expand Down Expand Up @@ -124,7 +125,7 @@ def services
when *::Service::Commands::Start::TRIGGERS
::Service::Commands::Start.run(targets, args.file, verbose: args.verbose?)
when *::Service::Commands::Stop::TRIGGERS
::Service::Commands::Stop.run(targets, verbose: args.verbose?)
::Service::Commands::Stop.run(targets, verbose: args.verbose?, no_wait: args.no_wait?)
when *::Service::Commands::Kill::TRIGGERS
::Service::Commands::Kill.run(targets, verbose: args.verbose?)
else
Expand Down
6 changes: 3 additions & 3 deletions lib/service/commands/restart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ def run(targets, custom_plist, verbose:)
# group not-started services with started ones for restart
started << service
end
ServicesCli.stop([service]) if service.loaded?
ServicesCli.stop([service], verbose: verbose) if service.loaded?
end

ServicesCli.run(ran) if ran.present?
ServicesCli.start(started) if started.present?
ServicesCli.run(ran, verbose: verbose) if ran.present?
ServicesCli.start(started, verbose: verbose) if started.present?
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/service/commands/stop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ module Stop

TRIGGERS = %w[stop unload terminate term t u].freeze

def run(targets, verbose:)
def run(targets, verbose:, no_wait:)
ServicesCli.check(targets) &&
ServicesCli.stop(targets, verbose: verbose)
ServicesCli.stop(targets, verbose: verbose, no_wait: no_wait)
end
end
end
Expand Down
19 changes: 14 additions & 5 deletions lib/service/services_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def start(targets, service_file = nil, verbose: false)
end

# Stop a service and unload it.
def stop(targets, verbose: false)
def stop(targets, verbose: false, no_wait: false)
targets.each do |service|
unless service.loaded?
rm service.dest if service.dest.exist? # get rid of installed service file anyway, dude
Expand All @@ -142,14 +142,23 @@ def stop(targets, verbose: false)
next
end

puts "Stopping `#{service.name}`... (might take a while)"
systemctl_args = System.systemctl_args
if no_wait
systemctl_args << "--no-block"
Comment on lines +145 to +147
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like the systemctl_args variable is actually used anywhere in this method outside of lines 145 and 147. I assume it's supposed to be used on line 154 as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apainintheneck Whoops, opened PR in #596

puts "Stopping `#{service.name}`..."
else
puts "Stopping `#{service.name}`... (might take a while)"
end

if System.systemctl?
quiet_system(*System.systemctl_args, "disable", "--now", service.service_name)
elsif System.launchctl?
quiet_system System.launchctl, "bootout", "#{System.domain_target}/#{service.service_name}"
while $CHILD_STATUS.to_i == 9216 || service.loaded?
sleep(1)
quiet_system System.launchctl, "bootout", "#{System.domain_target}/#{service.service_name}"
unless no_wait
while $CHILD_STATUS.to_i == 9216 || service.loaded?
sleep(1)
quiet_system System.launchctl, "bootout", "#{System.domain_target}/#{service.service_name}"
end
end
quiet_system System.launchctl, "stop", "#{System.domain_target}/#{service.service_name}" if service.pid?
end
Expand Down