`service status --verbose`

master
Luka Vandervelden 2019-10-29 13:08:58 +01:00
parent cd6fd4c81f
commit 7fdccfa1b2
2 changed files with 39 additions and 1 deletions

View File

@ -14,6 +14,7 @@ parser = uninitialized OptionParser
args = [] of String args = [] of String
force = false force = false
verbose = false
alias Command = Proc(Array(String), Nil) alias Command = Proc(Array(String), Nil)
alias CommandTuple = Tuple(String, String, Command) alias CommandTuple = Tuple(String, String, Command)
@ -215,6 +216,8 @@ commands.push "stop", "Stops a running service." do |args|
end end
commands.push "status", "Prints the status of services." do |args| commands.push "status", "Prints the status of services." do |args|
ENV["SERVICE_VERBOSE"] = verbose.to_s
child = Process.run "#{OWN_LIBEXEC_DIR}/status", args, child = Process.run "#{OWN_LIBEXEC_DIR}/status", args,
output: Process::Redirect::Inherit, output: Process::Redirect::Inherit,
error: Process::Redirect::Inherit error: Process::Redirect::Inherit
@ -309,6 +312,9 @@ parser = OptionParser.parse do |cli|
cli.on "-f", "--force", "Ignores warnings and executes dangerous operations." do cli.on "-f", "--force", "Ignores warnings and executes dangerous operations." do
force = true force = true
end end
cli.on "-v", "--verbose", "Prints more data when doing things." do
verbose = true
end
cli.unknown_args do |x| cli.unknown_args do |x|
args = x args = x

View File

@ -10,6 +10,8 @@ Service.load RC_DIRECTORY
LibC.setuid 0 LibC.setuid 0
LibC.setgid 0 LibC.setgid 0
verbose = ENV["SERVICE_VERBOSE"]?.try &.==("true")
list_status = false list_status = false
services = ARGV services = ARGV
if services.size == 0 if services.size == 0
@ -35,7 +37,37 @@ else
if service.nil? if service.nil?
service_not_found = true service_not_found = true
else else
puts "#{service.full_id}: #{service.status PID_DIRECTORY}" if verbose
STDOUT << ("%-20s " % "#{service.full_id}:").colorize(:white).to_s
status_string = "%-10s" % service.status PID_DIRECTORY
status_string = case service.status PID_DIRECTORY
when Service::Status::Dead
status_string.colorize(:red).bright
when Service::Status::Running
status_string.colorize(:green).bright
when Service::Status::Stopped
status_string.colorize :yellow
else
status_string.colorize # ¯\_(ツ)_/¯
end
STDOUT << status_string.to_s
STDOUT << (
service.ports.map do |name, number|
"#{name}:#{number.colorize(:magenta).to_s}"
end +
service.providers.map do |token, id|
"-#{token.colorize(:yellow)}:" + id.colorize(:cyan).to_s
end +
service.provides.map do |token|
"+#{token.token.colorize(:green).to_s}"
end
).join " "
STDOUT << "\n"
else
puts "#{service.full_id}: #{service.status PID_DIRECTORY}"
end
end end
end end