Details

    • Type: Bug
    • Status: Resolved
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      Some processes like Collectors, demuxManager, etc have to be able to exit if they have to.
      In that case, watchdog will not restart them since the shutdown hook will have done the cleanup.

      pFile = new PidFile("Agent");
      Runtime.getRuntime().addShutdownHook(pFile);

      pFile = new PidFile("Collector");
      Runtime.getRuntime().addShutdownHook(pFile);

        Activity

        Hide
        eyang Eric Yang added a comment -

        If the program is cleanly exited, it should have pFile.clean() in the main function of the program. The rest of the time, it should do nothing. There shouldn't be any addShutdownHook for pFile in our code.

        Show
        eyang Eric Yang added a comment - If the program is cleanly exited, it should have pFile.clean() in the main function of the program. The rest of the time, it should do nothing. There shouldn't be any addShutdownHook for pFile in our code.
        Hide
        jboulon Jerome Boulon added a comment -

        If there's no addShutdownHook todo the cleanup, how do you do the cleanup when you want to stop the agent or the collector?
        We're sending a kill -TERM ...

        Show
        jboulon Jerome Boulon added a comment - If there's no addShutdownHook todo the cleanup, how do you do the cleanup when you want to stop the agent or the collector? We're sending a kill -TERM ...
        Hide
        eyang Eric Yang added a comment -

        You should have a shutdown function added to the shutdown hook, but only for SIGHUP and SIGTERM should have pFile.clean(); called.

        Show
        eyang Eric Yang added a comment - You should have a shutdown function added to the shutdown hook, but only for SIGHUP and SIGTERM should have pFile.clean(); called.
        Hide
        eyang Eric Yang added a comment -

        Use SignalHandler would do the job, example:

        public class **** implements sun.misc.SignalHandler {
        private boolean Running = true;
        private static Logger myLogger;

        public SignalHandler() {
        try
        {
        this.setupHandler();
        }
        catch (SignalHandlerException e)
        {
        myLogger.info ( e.toString() );
        }
        }

        private void setupHandler() throws SignalHandlerException {
        this.handleSignal("INT");
        this.handleSignal("TERM");
        //this.handleSignal("HUP");
        }

        Show
        eyang Eric Yang added a comment - Use SignalHandler would do the job, example: public class **** implements sun.misc.SignalHandler { private boolean Running = true; private static Logger myLogger; public SignalHandler() { try { this.setupHandler(); } catch (SignalHandlerException e) { myLogger.info ( e.toString() ); } } private void setupHandler() throws SignalHandlerException { this.handleSignal("INT"); this.handleSignal("TERM"); //this.handleSignal("HUP"); }
        Hide
        jboulon Jerome Boulon added a comment -

        Instead of going with an unpublished API, it will be simpler and cleaner to add a public static shutdown method that will remove the shutdownHook for pidFile.

        Show
        jboulon Jerome Boulon added a comment - Instead of going with an unpublished API, it will be simpler and cleaner to add a public static shutdown method that will remove the shutdownHook for pidFile.
        Hide
        zhangyongjiang Cheng added a comment -

        Use a new singleton class DaemonWatcher to wrapper PidFile class. It has a method bailout. When this method is called, shutdownhook will be removed and then call system.exit.

        Show
        zhangyongjiang Cheng added a comment - Use a new singleton class DaemonWatcher to wrapper PidFile class. It has a method bailout. When this method is called, shutdownhook will be removed and then call system.exit.
        Hide
        eyang Eric Yang added a comment -

        I just committed this, thanks Cheng.

        Show
        eyang Eric Yang added a comment - I just committed this, thanks Cheng.

          People

          • Assignee:
            zhangyongjiang Cheng
            Reporter:
            jboulon Jerome Boulon
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development