service/src/status.cr

45 lines
718 B
Crystal
Raw Normal View History

require "./service/service.cr"
require "./config.cr"
ServiceDefinition.load SERVICES_DIRECTORY
Environment.load ENVIRONMENTS_DIRECTORY
Service.load RC_DIRECTORY
LibC.setuid 0
LibC.setgid 0
2019-10-24 12:55:30 +02:00
list_status = false
services = ARGV
if services.size == 0
2019-10-24 12:55:30 +02:00
list_status = true
services = Service.all
else
services = services.map do |id|
Service.get_by_id id
end
end
2019-10-24 12:55:30 +02:00
if services.size == 1 && ! list_status
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
puts "#{service.full_id}: #{service.status PID_DIRECTORY}"
end
end
exit 1 if service_not_found
end