readiness-check-command: implemented.
The 'postgresql' service is a good example of how this is used in practice.master
parent
c43eb7af42
commit
f2507e2dd0
|
@ -2,6 +2,7 @@ name: postgresql
|
||||||
user: postgres
|
user: postgres
|
||||||
command: postgres -D ${SERVICE_ROOT}/db -k /tmp/postgresql-${ENVIRONMENT}
|
command: postgres -D ${SERVICE_ROOT}/db -k /tmp/postgresql-${ENVIRONMENT}
|
||||||
#stop-command: kill -HUP ${PID}
|
#stop-command: kill -HUP ${PID}
|
||||||
|
readiness-check-command: pg_isready -p ${POSTGRESQL_PORT}
|
||||||
environment-variables:
|
environment-variables:
|
||||||
- PGROOT=${SERVICE_ROOT}
|
- PGROOT=${SERVICE_ROOT}
|
||||||
provides: postgresql
|
provides: postgresql
|
||||||
|
|
|
@ -179,6 +179,9 @@ class Service
|
||||||
def reload_command
|
def reload_command
|
||||||
@reference.reload_command
|
@reference.reload_command
|
||||||
end
|
end
|
||||||
|
def readiness_check_command
|
||||||
|
@reference.readiness_check_command
|
||||||
|
end
|
||||||
def provides
|
def provides
|
||||||
@reference.provides
|
@reference.provides
|
||||||
end
|
end
|
||||||
|
@ -233,6 +236,12 @@ class Service
|
||||||
|
|
||||||
env["SERVICE_TOKENS"] = @providers.to_a.map(&.[0]).join ':'
|
env["SERVICE_TOKENS"] = @providers.to_a.map(&.[0]).join ':'
|
||||||
|
|
||||||
|
@ports.each do |name, number|
|
||||||
|
name = name.upcase
|
||||||
|
|
||||||
|
env["PORT_#{name}"] = number.to_s
|
||||||
|
end
|
||||||
|
|
||||||
# FIXME: Parsing should probably be done… when parsing the file.
|
# FIXME: Parsing should probably be done… when parsing the file.
|
||||||
# FIXME: Parsing is probably a bit primitive. Maybe this isn’t the right way of defining this.
|
# FIXME: Parsing is probably a bit primitive. Maybe this isn’t the right way of defining this.
|
||||||
@reference.environment_variables.each do |string|
|
@reference.environment_variables.each do |string|
|
||||||
|
@ -341,6 +350,26 @@ class Service
|
||||||
end
|
end
|
||||||
|
|
||||||
self.save_pid context.pid_directory, process.pid
|
self.save_pid context.pid_directory, process.pid
|
||||||
|
|
||||||
|
# FIXME: At this point, let’s wait a few seconds for the service to be ready.
|
||||||
|
if command = readiness_check_command
|
||||||
|
context.info "Waiting for service to become ready…"
|
||||||
|
|
||||||
|
start_time = Time.local
|
||||||
|
now = Time.local
|
||||||
|
|
||||||
|
while (now - start_time).seconds < 5
|
||||||
|
r = Process.run "sh", ["-c", command]
|
||||||
|
|
||||||
|
if r.success?
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
sleep 0.05
|
||||||
|
|
||||||
|
now = Time.local
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
|
|
|
@ -74,6 +74,7 @@ class ServiceDefinition
|
||||||
getter command : String
|
getter command : String
|
||||||
getter stop_command : String?
|
getter stop_command : String?
|
||||||
getter reload_command : String?
|
getter reload_command : String?
|
||||||
|
getter readiness_check_command : String?
|
||||||
getter directory : String?
|
getter directory : String?
|
||||||
getter user : String?
|
getter user : String?
|
||||||
getter provides : String?
|
getter provides : String?
|
||||||
|
@ -93,6 +94,7 @@ class ServiceDefinition
|
||||||
@non_runnable = (@command == "none")
|
@non_runnable = (@command == "none")
|
||||||
@stop_command = specs["stop-command"]?.try &.as_s
|
@stop_command = specs["stop-command"]?.try &.as_s
|
||||||
@reload_command = specs["reload-command"]?.try &.as_s
|
@reload_command = specs["reload-command"]?.try &.as_s
|
||||||
|
@readiness_check_command = specs["readiness-check-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
|
||||||
@provides = specs["provides"]?.try &.as_a_or_s.map { |x| Provides.new x } || Array(Provides).new
|
@provides = specs["provides"]?.try &.as_a_or_s.map { |x| Provides.new x } || Array(Provides).new
|
||||||
|
|
Loading…
Reference in New Issue