2019-06-09 18:08:59 +02:00
|
|
|
|
|
|
|
require "./service/service.cr"
|
|
|
|
|
|
|
|
require "./config.cr"
|
|
|
|
|
|
|
|
ServiceDefinition.load SERVICES_DIRECTORY
|
|
|
|
Environment.load ENVIRONMENTS_DIRECTORY
|
|
|
|
Service.load RC_DIRECTORY
|
|
|
|
|
2019-06-10 14:32:30 +02:00
|
|
|
LibC.setuid 0
|
|
|
|
LibC.setgid 0
|
|
|
|
|
2019-10-29 13:08:58 +01:00
|
|
|
verbose = ENV["SERVICE_VERBOSE"]?.try &.==("true")
|
|
|
|
|
2019-10-24 12:55:30 +02:00
|
|
|
list_status = false
|
2019-10-23 19:38:08 +02:00
|
|
|
services = ARGV
|
|
|
|
if services.size == 0
|
2019-10-24 12:55:30 +02:00
|
|
|
list_status = true
|
2019-10-23 19:38:08 +02:00
|
|
|
services = Service.all
|
|
|
|
else
|
|
|
|
services = services.map do |id|
|
|
|
|
Service.get_by_id id
|
|
|
|
end
|
2019-06-09 18:08:59 +02:00
|
|
|
end
|
|
|
|
|
2019-10-24 12:55:30 +02:00
|
|
|
if services.size == 1 && ! list_status
|
2019-10-23 19:38:08 +02:00
|
|
|
services[0]?.try do |service|
|
|
|
|
puts service.status PID_DIRECTORY
|
|
|
|
exit 0
|
|
|
|
end
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
service_not_found = false
|
|
|
|
|
|
|
|
services.each do |service|
|
|
|
|
if service.nil?
|
|
|
|
service_not_found = true
|
|
|
|
else
|
2019-10-29 13:08:58 +01:00
|
|
|
if verbose
|
|
|
|
STDOUT << ("%-20s " % "#{service.full_id}:").colorize(:white).to_s
|
|
|
|
|
2019-11-08 01:08:57 +01:00
|
|
|
status_string = "%-15s" % service.status PID_DIRECTORY
|
2019-10-29 13:08:58 +01:00
|
|
|
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
|
2019-11-08 01:08:57 +01:00
|
|
|
when Service::Status::NonRunnable
|
|
|
|
status_string.colorize(:cyan)
|
2019-10-29 13:08:58 +01:00
|
|
|
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
|
2019-10-23 19:38:08 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
exit 1 if service_not_found
|
|
|
|
end
|
2019-06-09 18:08:59 +02:00
|
|
|
|