Skip to content

Commit

Permalink
Merge pull request #9108 from spacecowboy/3.2-exitcode
Browse files Browse the repository at this point in the history
Neo4j now exits with code 0 for SIGINT and SIGTERM
  • Loading branch information
spacecowboy committed Mar 30, 2017
2 parents c946d39 + 04804ce commit 819fcfc
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import java.util.logging.Logger;
import javax.annotation.Nonnull;

import sun.misc.Signal;
import sun.misc.SignalHandler;

import org.neo4j.graphdb.TransactionFailureException;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.helpers.collection.Pair;
Expand All @@ -49,6 +52,8 @@ public abstract class ServerBootstrapper implements Bootstrapper
public static final int OK = 0;
public static final int WEB_SERVER_STARTUP_ERROR_CODE = 1;
public static final int GRAPH_DATABASE_STARTUP_ERROR_CODE = 2;
private static final String SIGTERM = "TERM";
private static final String SIGINT = "INT";

private volatile NeoServer server;
private Thread shutdownHook;
Expand All @@ -74,6 +79,7 @@ public static int start( Bootstrapper boot, String... argv )
public final int start( File homeDir, Optional<File> configFile, Pair<String, String>... configOverrides )
{
addShutdownHook();
installSignalHandler();
try
{
Config config = createConfig( homeDir, configFile, configOverrides );
Expand Down Expand Up @@ -171,6 +177,15 @@ private Config createConfig( File homeDir, Optional<File> file, Pair<String, Str
configurationValidators() );
}

// Exit gracefully if possible
private void installSignalHandler()
{
// SIGTERM is invoked when system service is stopped
Signal.handle( new Signal( SIGTERM ), ( signal ) -> System.exit( 0 ) );
// SIGINT is invoked when user hits ctrl-c when running `neo4j console`
Signal.handle( new Signal( SIGINT ), ( signal ) -> System.exit( 0 ) );
}

private void addShutdownHook()
{
shutdownHook = new Thread()
Expand Down

0 comments on commit 819fcfc

Please sign in to comment.