Skip to content

Commit

Permalink
Catch TERM, HUP, and INT signals, and do a clean shutdown. (#2265)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanLennox authored Dec 20, 2024
1 parent c7ef8e6 commit 8780d43
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion jvb/src/main/kotlin/org/jitsi/videobridge/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import org.jitsi.videobridge.version.JvbVersionService
import org.jitsi.videobridge.websocket.ColibriWebSocketService
import org.jitsi.videobridge.xmpp.XmppConnection
import org.jitsi.videobridge.xmpp.config.XmppClientConnectionConfig
import sun.misc.Signal
import java.time.Clock
import kotlin.concurrent.thread
import kotlin.system.exitProcess
Expand Down Expand Up @@ -163,6 +164,23 @@ fun main() {
null
}

var exitStatus = 0

/* Catch signals and cause them to trigger a clean shutdown. */
listOf("TERM", "HUP", "INT").forEach { signalName ->
try {
Signal.handle(Signal(signalName)) { signal ->
exitStatus = signal.number + 128 // Matches java.lang.Terminator
logger.info("Caught signal $signal, shutting down.")

shutdownService.beginShutdown()
}
} catch (e: IllegalArgumentException) {
/* Unknown signal on this platform, or not allowed to register this signal; that's fine. */
logger.warn("Unable to register signal '$signalName'", e)
}
}

// Block here until the bridge shuts down
shutdownService.waitForShutdown()

Expand All @@ -186,7 +204,7 @@ fun main() {
TaskPools.CPU_POOL.shutdownNow()
TaskPools.IO_POOL.shutdownNow()

exitProcess(0)
exitProcess(exitStatus)
}

private fun setupMetaconfigLogger() {
Expand Down

0 comments on commit 8780d43

Please sign in to comment.