daemon/src/main/java/de/taimos/daemon/DaemonStarter.java
// I KNOW WHAT I AM DOING
I KNOW WHAT I AM DOING
I KNOW WHAT I AM DOING
private static void handleSignals() {
        if (DaemonStarter.isRunMode()) {
            try {
                Signal.handle(new Signal("HUP"), arg0 -> {
                    System.out.println("SIG INT");
                });
            } catch (IllegalArgumentException e) {
                System.err.println("Signal HUP not supported");
            }
            try {
                Signal.handle(new Signal("TERM"), arg0 -> {
                    System.out.println("SIG TERM");
                    DaemonStarter.stopService();
                });
            } catch (IllegalArgumentException e) {
                System.err.println("Signal TERM not supported");
            }
            try {
                Signal.handle(new Signal("INT"), arg0 -> {
                    System.out.println("SIG INT");
                    DaemonStarter.stopService();
                });
            } catch (IllegalArgumentException e) {
                System.err.println("Signal INT not supported");
            }
            try {
                Signal.handle(new Signal("USR2"), arg0 -> {
                    System.out.println("SIG USR2");
                    DaemonStarter.getLifecycleListener().signalUSR2();
                });
            } catch (IllegalArgumentException e) {
                System.err.println("Signal USR2 not supported");
            }
        }
    }
private static void handleSignals ( ) { if ( DaemonStarter . isRunMode ( ) ) { try { Signal . handle ( new Signal ( "HUP" ) , arg0 -> { System . out . println ( "SIG INT" ) ; } ) ; } catch ( IllegalArgumentException e ) { System . err . println ( "Signal HUP not supported" ) ; } try { Signal . handle ( new Signal ( "TERM" ) , arg0 -> { System . out . println ( "SIG TERM" ) ; DaemonStarter . stopService ( ) ; } ) ; } catch ( IllegalArgumentException e ) { System . err . println ( "Signal TERM not supported" ) ; } try { Signal . handle ( new Signal ( "INT" ) , arg0 -> { System . out . println ( "SIG INT" ) ; DaemonStarter . stopService ( ) ; } ) ; } catch ( IllegalArgumentException e ) { System . err . println ( "Signal INT not supported" ) ; } try { Signal . handle ( new Signal ( "USR2" ) , arg0 -> { System . out . println ( "SIG USR2" ) ; DaemonStarter . getLifecycleListener ( ) . signalUSR2 ( ) ; } ) ; } catch ( IllegalArgumentException e ) { System . err . println ( "Signal USR2 not supported" ) ; } } }
I KNOW WHAT I AM DOING
I KNOW WHAT I AM DOING
// handle SIGHUP to prevent process to get killed when exiting the tty // Nothing to do here // handle SIGTERM to notify the program to stop // handle SIGINT to notify the program to stop // handle SIGUSR2 to notify the life-cycle listener