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
36
src/main.cr
36
src/main.cr
|
@ -143,6 +143,9 @@ 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,8 +408,17 @@ 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!
|
||||
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|
|
||||
service.dependency_tree.flatten.reverse.each do |service|
|
||||
if service.status(PID_DIRECTORY) == Service::Status::Running
|
||||
next
|
||||
|
@ -415,9 +427,25 @@ begin
|
|||
puts "starting #{service.to_s}"
|
||||
service.start PID_DIRECTORY, LOG_DIRECTORY
|
||||
end
|
||||
end
|
||||
elsif args[0] == "stop"
|
||||
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?
|
||||
Service.new(args[1], args[2]?).stop PID_DIRECTORY
|
||||
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