diff options
author | 2019-01-08 12:43:25 +0000 | |
---|---|---|
committer | 2019-01-08 12:43:25 +0000 | |
commit | e1c68f37ec3ba3ee512b86846a134d2f278b6571 (patch) | |
tree | 38a009aa2495ed0208a870b7ca01e6b22432c485 /sources/hv-collector-main | |
parent | 5180f3f32a2cdd35206f728e0fd7dd6ad62b567a (diff) | |
parent | 0d3d921285f397239e739790bf62d1cb8768ca7b (diff) |
Merge "Handle sigterm signal"
Diffstat (limited to 'sources/hv-collector-main')
-rw-r--r-- | sources/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/main.kt | 10 | ||||
-rwxr-xr-x | sources/hv-collector-main/src/main/scripts/entry.sh | 17 |
2 files changed, 22 insertions, 5 deletions
diff --git a/sources/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/main.kt b/sources/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/main.kt index c29c5d16..16da3721 100644 --- a/sources/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/main.kt +++ b/sources/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/main.kt @@ -30,6 +30,7 @@ import org.onap.dcae.collectors.veshv.utils.arrow.ExitFailure import org.onap.dcae.collectors.veshv.utils.arrow.unsafeRunEitherSync import org.onap.dcae.collectors.veshv.utils.commandline.handleWrongArgumentErrorCurried import org.onap.dcae.collectors.veshv.utils.logging.Logger +import org.onap.dcae.collectors.veshv.utils.registerShutdownHook private const val VESHV_PACKAGE = "org.onap.dcae.collectors.veshv" private val logger = Logger("$VESHV_PACKAGE.main") @@ -44,7 +45,7 @@ fun main(args: Array<String>) = logger.withError { log("Failed to start a server", ex) } ExitFailure(1) }, - { logger.info { "Gentle shutdown" } } + { logger.info { "Finished" } } ) private fun startAndAwaitServers(config: ServerConfiguration) = @@ -52,7 +53,8 @@ private fun startAndAwaitServers(config: ServerConfiguration) = Logger.setLogLevel(VESHV_PACKAGE, config.logLevel) logger.info { "Using configuration: $config" } HealthCheckServer.start(config).bind() - VesServer.start(config).bind() - .await().bind() + VesServer.start(config).bind().run { + registerShutdownHook(shutdown()).bind() + await().bind() + } }.fix() - diff --git a/sources/hv-collector-main/src/main/scripts/entry.sh b/sources/hv-collector-main/src/main/scripts/entry.sh index 2e8cb0c5..a612e393 100755 --- a/sources/hv-collector-main/src/main/scripts/entry.sh +++ b/sources/hv-collector-main/src/main/scripts/entry.sh @@ -2,4 +2,19 @@ set -euo pipefail -java ${JAVA_OPTS:-''} -cp '*:' org.onap.dcae.collectors.veshv.main.MainKt $@ +pid=-1 + +function handle_sigterm() { + if [[ ${pid} -ge 0 ]]; then + echo "Caught SIGTERM signal. Redirecting to process with pid=${pid}" + kill -TERM "${pid}" + wait ${pid} + fi + exit 143 # 128 + 15 -- SIGTERM +} +trap "handle_sigterm" SIGTERM + +java ${JAVA_OPTS:-} -cp '*:' org.onap.dcae.collectors.veshv.main.MainKt $@ & +pid=$! +echo "Service started with pid=${pid}" +wait ${pid} |