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
48
src/main.cr
48
src/main.cr
|
@ -143,6 +143,9 @@ class Service
|
||||||
getter environment : Environment
|
getter environment : Environment
|
||||||
getter providers = ProvidersList.new
|
getter providers = ProvidersList.new
|
||||||
|
|
||||||
|
class Exception < ::Exception
|
||||||
|
end
|
||||||
|
|
||||||
class ProvidersList < Hash(String, String)
|
class ProvidersList < Hash(String, String)
|
||||||
def []?(name)
|
def []?(name)
|
||||||
super(name).try { |x| Service.get_by_id x}
|
super(name).try { |x| Service.get_by_id x}
|
||||||
|
@ -405,19 +408,44 @@ begin
|
||||||
elsif args[0] == "del"
|
elsif args[0] == "del"
|
||||||
Service.new(args[1], args[2]?).remove RC_DIRECTORY
|
Service.new(args[1], args[2]?).remove RC_DIRECTORY
|
||||||
elsif args[0] == "start"
|
elsif args[0] == "start"
|
||||||
#service = Service.new(args[1], args[2]?)
|
services = args[1..args.size].map do |arg|
|
||||||
service = Service.get_by_id(args[1]).not_nil!
|
service = Service.get_by_id(arg)
|
||||||
service.dependency_tree.flatten.reverse.each do |service|
|
|
||||||
if service.status(PID_DIRECTORY) == Service::Status::Running
|
unless service
|
||||||
next
|
raise Service::Exception.new "Service '#{arg}' does not exist."
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "starting #{service.to_s}"
|
service
|
||||||
service.start PID_DIRECTORY, LOG_DIRECTORY
|
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
|
end
|
||||||
elsif args[0] == "stop"
|
elsif args[0] == "stop"
|
||||||
# FIXME: Build revdep tree and stop services started as dependencies?
|
services = args[1..args.size].map do |arg|
|
||||||
Service.new(args[1], args[2]?).stop PID_DIRECTORY
|
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"
|
elsif args[0] == "status"
|
||||||
puts Service.new(args[1], args[2]?).status PID_DIRECTORY
|
puts Service.new(args[1], args[2]?).status PID_DIRECTORY
|
||||||
elsif args[0] == "show"
|
elsif args[0] == "show"
|
||||||
|
@ -451,7 +479,7 @@ begin
|
||||||
STDERR << parser << "\n"
|
STDERR << parser << "\n"
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
rescue e
|
rescue e : Service::Exception
|
||||||
STDERR << e.message << "\n"
|
STDERR << e.message << "\n"
|
||||||
exit 2
|
exit 2
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue