From e0e81d85810af8acf2ef02e409de3cc37e3fed30 Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Fri, 8 Nov 2019 01:08:57 +0100 Subject: [PATCH] Services can now be "Non Runnable". --- services/www.spec | 2 +- src/service.cr | 5 +++++ src/service/service.cr | 10 ++++++++++ src/service/service_definition.cr | 2 ++ src/status.cr | 4 +++- 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/services/www.spec b/services/www.spec index d0a4ec1..d60fe9e 100644 --- a/services/www.spec +++ b/services/www.spec @@ -1,4 +1,4 @@ -command: echo "coucou" +command: none consumes: www requires-domain: true diff --git a/src/service.cr b/src/service.cr index 8922acb..d551f1f 100644 --- a/src/service.cr +++ b/src/service.cr @@ -193,6 +193,11 @@ commands.push "start", "Starts a service." do service.dependency_tree.flatten.reverse.each do |service| next if service.running? PID_DIRECTORY + if service.non_runnable + STDOUT << "#{service.to_s}: non runnable\n" + next + end + puts "starting #{service.to_s}" service.start PID_DIRECTORY, LOG_DIRECTORY end diff --git a/src/service/service.cr b/src/service/service.cr index 58e6a97..58e157a 100644 --- a/src/service/service.cr +++ b/src/service/service.cr @@ -176,6 +176,9 @@ class Service def port_definitions @reference.port_definitions end + def non_runnable + @reference.non_runnable + end def root @root || "#{@environment.root}/#{name}" @@ -306,6 +309,11 @@ class Service # - Should we wait for the process to die? # - Shouldn’t we remove the pid file? 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 if _pid @@ -344,9 +352,11 @@ class Service Running Dead Stopped + NonRunnable end def status(pid_dir) + return Status::NonRunnable if non_runnable _pid = pid pid_dir if _pid diff --git a/src/service/service_definition.cr b/src/service/service_definition.cr index 387dd2e..7cca6a7 100644 --- a/src/service/service_definition.cr +++ b/src/service/service_definition.cr @@ -62,6 +62,7 @@ class ServiceDefinition getter pre_start_hooks : Array(Hook) getter provides : Array(Provides) getter port_definitions : Array(PortDefinition) + getter non_runnable : Bool getter requires_domain = false @@ -69,6 +70,7 @@ class ServiceDefinition sections = specs.sections specs = specs.assignments @command = specs["command"].as_s + @non_runnable = (@command == "none") @stop_command = specs["stop-command"]?.try &.as_s @directory = specs["directory"]?.try &.as_s @user = specs["user"]?.try &.as_s diff --git a/src/status.cr b/src/status.cr index 4768dcc..89df686 100644 --- a/src/status.cr +++ b/src/status.cr @@ -40,12 +40,14 @@ else if verbose 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 when Service::Status::Dead status_string.colorize(:red).bright when Service::Status::Running status_string.colorize(:green).bright + when Service::Status::NonRunnable + status_string.colorize(:cyan) when Service::Status::Stopped status_string.colorize :yellow else