"--config-url", "http://consul-server:8500/v1/kv/veshv-config?raw=true",
"--kafka-bootstrap-servers", "message-router-kafka:9092",
"--key-store-password", "onaponap",
- "--trust-store-password", "onaponap"]
+ "--trust-store-password", "onaponap",
+ "--first-request-delay", "2",
+ "--log-level", "DEBUG"]
environment:
JAVA_OPTS: "-Dio.netty.leakDetection.level=paranoid"
healthcheck:
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")
logger.withError { log("Failed to start a server", ex) }
ExitFailure(1)
},
- { logger.info { "Gentle shutdown" } }
+ { logger.info { "Finished" } }
)
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()
-
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}
logger.trace(context, it)
Mono.just<T>(t)
})
- }
\ No newline at end of file
+ }
package org.onap.dcae.collectors.veshv.utils
import arrow.effects.IO
+import org.onap.dcae.collectors.veshv.utils.logging.Logger
import reactor.netty.DisposableServer
+import java.time.Duration
/**
* @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
*/
class NettyServerHandle(private val ctx: DisposableServer) : ServerHandle(ctx.host(), ctx.port()) {
override fun shutdown() = IO {
- ctx.disposeNow()
+ logger.info { "Graceful shutdown" }
+ ctx.disposeNow(SHUTDOWN_TIMEOUT)
+ logger.info { "Server disposed" }
}
override fun await() = IO<Unit> {
ctx.channel().closeFuture().sync()
}
+
+ companion object {
+ val logger = Logger(NettyServerHandle::class)
+ private val SHUTDOWN_TIMEOUT = Duration.ofSeconds(10)
+ }
}
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * dcaegen2-collectors-veshv
+ * ================================================================================
+ * Copyright (C) 2019 NOKIA
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.dcae.collectors.veshv.utils
+
+import arrow.effects.IO
+
+/**
+ * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
+ * @since January 2019
+ */
+
+fun registerShutdownHook(job: () -> Unit) {
+ Runtime.getRuntime().addShutdownHook(object : Thread() {
+ override fun run() {
+ job()
+ }
+ })
+}
+
+fun registerShutdownHook(job: IO<Unit>) = IO {
+ registerShutdownHook {
+ job.unsafeRunSync()
+ }
+}