Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Blocker 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
        Eric Yang added a comment -

        I just committed this, thanks Cheng.

        Show
        Eric Yang added a comment - I just committed this, thanks Cheng.
        Hide
        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
        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
        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
        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
        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
        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
        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
        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
        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
        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
        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
        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.

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development