Grooming related to side-effects directories.
parent
f858a9aa11
commit
3e8a1d2ab2
25
src/main.cr
25
src/main.cr
|
@ -1,6 +1,13 @@
|
|||
require "option_parser"
|
||||
require "yaml"
|
||||
|
||||
# Those are set to local to make testing easier.
|
||||
PID_DIRECTORY = "./pid"
|
||||
RC_DIRECTORY = "./rc"
|
||||
LOG_DIRECTORY = "./log"
|
||||
SERVICES_DIRECTORY = "./services"
|
||||
ENVIRONMENTS_DIRECTORY = "./environments"
|
||||
|
||||
# TODO:
|
||||
# - Be more declarative about the definition of commands.
|
||||
|
||||
|
@ -386,33 +393,33 @@ if command.nil?
|
|||
exit 1
|
||||
end
|
||||
|
||||
ServiceDefinition.load "services"
|
||||
Environment.load "environments"
|
||||
Service.load "rc"
|
||||
ServiceDefinition.load SERVICES_DIRECTORY
|
||||
Environment.load ENVIRONMENTS_DIRECTORY
|
||||
Service.load RC_DIRECTORY
|
||||
|
||||
begin
|
||||
if args[0] == "help"
|
||||
puts parser
|
||||
elsif args[0] == "add"
|
||||
Service.new(args[1], args[2]?).write "rc"
|
||||
Service.new(args[1], args[2]?).write RC_DIRECTORY
|
||||
elsif args[0] == "del"
|
||||
Service.new(args[1], args[2]?).remove "rc"
|
||||
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") == Service::Status::Running
|
||||
if service.status(PID_DIRECTORY) == Service::Status::Running
|
||||
next
|
||||
end
|
||||
|
||||
puts "starting #{service.to_s}"
|
||||
service.start "pid", "log"
|
||||
service.start PID_DIRECTORY, LOG_DIRECTORY
|
||||
end
|
||||
elsif args[0] == "stop"
|
||||
# FIXME: Build revdep tree and stop services started as dependencies?
|
||||
Service.new(args[1], args[2]?).stop "pid"
|
||||
Service.new(args[1], args[2]?).stop PID_DIRECTORY
|
||||
elsif args[0] == "status"
|
||||
puts Service.new(args[1], args[2]?).status "pid"
|
||||
puts Service.new(args[1], args[2]?).status PID_DIRECTORY
|
||||
elsif args[0] == "show"
|
||||
service = Service.all.find do |service|
|
||||
unless service.name == args[1]
|
||||
|
|
Loading…
Reference in New Issue