`service status --verbose`
parent
cd6fd4c81f
commit
7fdccfa1b2
|
@ -14,6 +14,7 @@ parser = uninitialized OptionParser
|
|||
args = [] of String
|
||||
|
||||
force = false
|
||||
verbose = false
|
||||
|
||||
alias Command = Proc(Array(String), Nil)
|
||||
alias CommandTuple = Tuple(String, String, Command)
|
||||
|
@ -215,6 +216,8 @@ commands.push "stop", "Stops a running service." do |args|
|
|||
end
|
||||
|
||||
commands.push "status", "Prints the status of services." do |args|
|
||||
ENV["SERVICE_VERBOSE"] = verbose.to_s
|
||||
|
||||
child = Process.run "#{OWN_LIBEXEC_DIR}/status", args,
|
||||
output: 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
|
||||
force = true
|
||||
end
|
||||
cli.on "-v", "--verbose", "Prints more data when doing things." do
|
||||
verbose = true
|
||||
end
|
||||
|
||||
cli.unknown_args do |x|
|
||||
args = x
|
||||
|
|
|
@ -10,6 +10,8 @@ Service.load RC_DIRECTORY
|
|||
LibC.setuid 0
|
||||
LibC.setgid 0
|
||||
|
||||
verbose = ENV["SERVICE_VERBOSE"]?.try &.==("true")
|
||||
|
||||
list_status = false
|
||||
services = ARGV
|
||||
if services.size == 0
|
||||
|
@ -34,10 +36,40 @@ else
|
|||
services.each do |service|
|
||||
if service.nil?
|
||||
service_not_found = true
|
||||
else
|
||||
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
|
||||
|
||||
exit 1 if service_not_found
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue