UI update.
- `start` and `stop` now take service ids in parameter and can take multiple of them. - Errors are displayed properly (instead of “index out of bounds” or “nil assertion failed”) when invalid ids are provided on the CLI for `start` and `stop`.master
parent
3e8a1d2ab2
commit
dddf285046
50
src/main.cr
50
src/main.cr
|
@ -142,7 +142,10 @@ end
|
|||
class Service
|
||||
getter environment : Environment
|
||||
getter providers = ProvidersList.new
|
||||
|
||||
|
||||
class Exception < ::Exception
|
||||
end
|
||||
|
||||
class ProvidersList < Hash(String, String)
|
||||
def []?(name)
|
||||
super(name).try { |x| Service.get_by_id x}
|
||||
|
@ -405,19 +408,44 @@ begin
|
|||
elsif args[0] == "del"
|
||||
Service.new(args[1], args[2]?).remove RC_DIRECTORY
|
||||
elsif args[0] == "start"
|
||||
#service = Service.new(args[1], args[2]?)
|
||||
service = Service.get_by_id(args[1]).not_nil!
|
||||
service.dependency_tree.flatten.reverse.each do |service|
|
||||
if service.status(PID_DIRECTORY) == Service::Status::Running
|
||||
next
|
||||
services = args[1..args.size].map do |arg|
|
||||
service = Service.get_by_id(arg)
|
||||
|
||||
unless service
|
||||
raise Service::Exception.new "Service '#{arg}' does not exist."
|
||||
end
|
||||
|
||||
puts "starting #{service.to_s}"
|
||||
service.start PID_DIRECTORY, LOG_DIRECTORY
|
||||
service
|
||||
end
|
||||
|
||||
services.each do |service|
|
||||
service.dependency_tree.flatten.reverse.each do |service|
|
||||
if service.status(PID_DIRECTORY) == Service::Status::Running
|
||||
next
|
||||
end
|
||||
|
||||
puts "starting #{service.to_s}"
|
||||
service.start PID_DIRECTORY, LOG_DIRECTORY
|
||||
end
|
||||
end
|
||||
elsif args[0] == "stop"
|
||||
# FIXME: Build revdep tree and stop services started as dependencies?
|
||||
Service.new(args[1], args[2]?).stop PID_DIRECTORY
|
||||
services = args[1..args.size].map do |arg|
|
||||
service = Service.get_by_id(arg)
|
||||
|
||||
unless service
|
||||
raise Service::Exception.new "Service '#{arg}' does not exist."
|
||||
end
|
||||
|
||||
service
|
||||
end
|
||||
|
||||
services.each do |service|
|
||||
# FIXME: Build revdep tree and stop services started as dependencies?
|
||||
if service.status(PID_DIRECTORY) == Service::Status::Running
|
||||
puts "stopping #{service.to_s}"
|
||||
service.stop PID_DIRECTORY
|
||||
end
|
||||
end
|
||||
elsif args[0] == "status"
|
||||
puts Service.new(args[1], args[2]?).status PID_DIRECTORY
|
||||
elsif args[0] == "show"
|
||||
|
@ -451,7 +479,7 @@ begin
|
|||
STDERR << parser << "\n"
|
||||
exit 1
|
||||
end
|
||||
rescue e
|
||||
rescue e : Service::Exception
|
||||
STDERR << e.message << "\n"
|
||||
exit 2
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue