Services can now be "Non Runnable".

master
Philippe PITTOLI 2019-11-08 01:08:57 +01:00
parent 10cd792373
commit e0e81d8581
5 changed files with 21 additions and 2 deletions

View File

@ -1,4 +1,4 @@
command: echo "coucou" command: none
consumes: www consumes: www
requires-domain: true requires-domain: true

View File

@ -193,6 +193,11 @@ commands.push "start", "Starts a service." do
service.dependency_tree.flatten.reverse.each do |service| service.dependency_tree.flatten.reverse.each do |service|
next if service.running? PID_DIRECTORY next if service.running? PID_DIRECTORY
if service.non_runnable
STDOUT << "#{service.to_s}: non runnable\n"
next
end
puts "starting #{service.to_s}" puts "starting #{service.to_s}"
service.start PID_DIRECTORY, LOG_DIRECTORY service.start PID_DIRECTORY, LOG_DIRECTORY
end end

View File

@ -176,6 +176,9 @@ class Service
def port_definitions def port_definitions
@reference.port_definitions @reference.port_definitions
end end
def non_runnable
@reference.non_runnable
end
def root def root
@root || "#{@environment.root}/#{name}" @root || "#{@environment.root}/#{name}"
@ -306,6 +309,11 @@ class Service
# - Should we wait for the process to die? # - Should we wait for the process to die?
# - Shouldnt we remove the pid file? # - Shouldnt we remove the pid file?
def stop(pid_dir : String) def stop(pid_dir : String)
if non_runnable
STDOUT << ("%-20s " % "#{full_id}:").colorize(:white).to_s
STDOUT << "non runnable"
return
end
_pid = pid pid_dir _pid = pid pid_dir
if _pid if _pid
@ -344,9 +352,11 @@ class Service
Running Running
Dead Dead
Stopped Stopped
NonRunnable
end end
def status(pid_dir) def status(pid_dir)
return Status::NonRunnable if non_runnable
_pid = pid pid_dir _pid = pid pid_dir
if _pid if _pid

View File

@ -62,6 +62,7 @@ class ServiceDefinition
getter pre_start_hooks : Array(Hook) getter pre_start_hooks : Array(Hook)
getter provides : Array(Provides) getter provides : Array(Provides)
getter port_definitions : Array(PortDefinition) getter port_definitions : Array(PortDefinition)
getter non_runnable : Bool
getter requires_domain = false getter requires_domain = false
@ -69,6 +70,7 @@ class ServiceDefinition
sections = specs.sections sections = specs.sections
specs = specs.assignments specs = specs.assignments
@command = specs["command"].as_s @command = specs["command"].as_s
@non_runnable = (@command == "none")
@stop_command = specs["stop-command"]?.try &.as_s @stop_command = specs["stop-command"]?.try &.as_s
@directory = specs["directory"]?.try &.as_s @directory = specs["directory"]?.try &.as_s
@user = specs["user"]?.try &.as_s @user = specs["user"]?.try &.as_s

View File

@ -40,12 +40,14 @@ else
if verbose if verbose
STDOUT << ("%-20s " % "#{service.full_id}:").colorize(:white).to_s STDOUT << ("%-20s " % "#{service.full_id}:").colorize(:white).to_s
status_string = "%-10s" % service.status PID_DIRECTORY status_string = "%-15s" % service.status PID_DIRECTORY
status_string = case service.status PID_DIRECTORY status_string = case service.status PID_DIRECTORY
when Service::Status::Dead when Service::Status::Dead
status_string.colorize(:red).bright status_string.colorize(:red).bright
when Service::Status::Running when Service::Status::Running
status_string.colorize(:green).bright status_string.colorize(:green).bright
when Service::Status::NonRunnable
status_string.colorize(:cyan)
when Service::Status::Stopped when Service::Status::Stopped
status_string.colorize :yellow status_string.colorize :yellow
else else