Skip to content

Commit 543977c

Browse files
authored
fix: Catch TERM/HUP/INT and cleanup. (#1249)
1 parent f50e065 commit 543977c

File tree

1 file changed

+28
-0
lines changed
  • jicofo/src/main/java/org/jitsi/jicofo

1 file changed

+28
-0
lines changed

jicofo/src/main/java/org/jitsi/jicofo/Main.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323
import org.jitsi.metaconfig.*;
2424
import org.jitsi.utils.*;
2525
import org.jitsi.utils.logging2.*;
26+
import sun.misc.*;
2627

28+
import java.util.*;
2729
import java.util.concurrent.*;
30+
import java.util.concurrent.atomic.*;
2831

2932

3033
/**
@@ -83,6 +86,29 @@ public static void main(String[] args)
8386
return;
8487
}
8588

89+
AtomicInteger exitStatus = new AtomicInteger();
90+
91+
/* Catch signals and cause them to trigger a clean shutdown. */
92+
for (String signalName : List.of("TERM", "HUP", "INT"))
93+
{
94+
try
95+
{
96+
Signal.handle(new Signal(signalName), signal ->
97+
{
98+
// Matches java.lang.Terminator
99+
exitStatus.set(signal.getNumber() + 128);
100+
logger.info("Caught signal " + signal + ", shutting down.");
101+
102+
shutdownLatch.countDown();
103+
});
104+
}
105+
catch (IllegalArgumentException e)
106+
{
107+
/* Unknown signal on this platform, or not allowed to register this signal; that's fine. */
108+
logger.warn("Unable to register signal " + signalName, e);
109+
}
110+
}
111+
86112

87113
try
88114
{
@@ -97,6 +123,8 @@ public static void main(String[] args)
97123
jicofoServices.shutdown();
98124
TaskPools.shutdown();
99125
JicofoServices.setJicofoServicesSingleton(null);
126+
logger.info("Jicofo has been stopped, exiting with exit code " + exitStatus.get());
127+
System.exit(exitStatus.get());
100128
}
101129

102130
private static void setupMetaconfigLogger()

0 commit comments

Comments
 (0)