container: make liveness probe independent of webserver
Currently liveness and readiness was treated the same. However, their behaviour at shutdown is meant to be different. When a service is not read no new connections are made to it, and when a service is not live it can be cleaned up. By considering our service live if and only if it listens to HTTP requests we don't have the opportunity to clean up after we stop listening to new requests. Leave readiness probes as they are, and instead use a file in the filesystem to indicate when the service is live. It is created before composer is spawned and deleted once composer exits.
This commit is contained in:
parent
15c2044b3c
commit
d3cd3197c0
2 changed files with 11 additions and 5 deletions
|
|
@ -9,6 +9,7 @@ a container.
|
|||
import argparse
|
||||
import contextlib
|
||||
import os
|
||||
import pathlib
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
|
|
@ -301,6 +302,10 @@ class Cli(contextlib.AbstractContextManager):
|
|||
res = 0
|
||||
sockets = self._prepare_sockets()
|
||||
|
||||
liveness = pathlib.Path('/run/live')
|
||||
|
||||
liveness.touch()
|
||||
|
||||
try:
|
||||
if self.args.builtin_worker:
|
||||
proc_worker = self._spawn_worker()
|
||||
|
|
@ -324,7 +329,6 @@ class Cli(contextlib.AbstractContextManager):
|
|||
proc_dnf_json.terminate()
|
||||
proc_dnf_json.wait()
|
||||
|
||||
return res
|
||||
except KeyboardInterrupt:
|
||||
if proc_worker:
|
||||
proc_worker.terminate()
|
||||
|
|
@ -343,6 +347,8 @@ class Cli(contextlib.AbstractContextManager):
|
|||
if proc_composer:
|
||||
proc_composer.kill()
|
||||
raise
|
||||
finally:
|
||||
liveness.unlink()
|
||||
|
||||
return res
|
||||
|
||||
|
|
|
|||
|
|
@ -41,10 +41,10 @@ objects:
|
|||
name: composer
|
||||
livenessProbe:
|
||||
failureThreshold: 3
|
||||
httpGet:
|
||||
path: ${LIVENESS_URI}
|
||||
port: ${{COMPOSER_API_PORT}}
|
||||
scheme: HTTP
|
||||
exec:
|
||||
command:
|
||||
- cat
|
||||
- /tmp/live
|
||||
periodSeconds: 10
|
||||
successThreshold: 1
|
||||
timeoutSeconds: 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue