Bug 909341

Summary: [as7] Shutting down the agent also shuts down the as7 started by running the start operation
Product: [Other] RHQ Project Reporter: Jirka Kremser <jkremser>
Component: Operations, PluginsAssignee: Nobody <nobody>
Status: NEW --- QA Contact:
Severity: high Docs Contact:
Priority: unspecified    
Version: 4.5CC: hrupp
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Jirka Kremser 2013-02-08 15:28:21 UTC
Description of problem:
If as7 is started using the start operation and the agent is shut down, the as7 is killed as well In other words, it doesn't survive the lifecycle of the agent if it was started by the agent. Even though the "Start Script Prefix" property in connection settings of as7 is correctly set to "/usr/bin/nohup" value. 


Version-Release number of selected component (if applicable):
RHQ 4.6.0-SNAPSHOT

How reproducible:
always

Steps to Reproduce:
1. import the as7 to the inventory
2. shut it down and up or restart it using the scheduled operation
3. kill the agent
  
Actual results:
the as7 is down


Expected results:
the as7 is up

Additional info:
Setting the env. variable LAUNCH_JBOSS_IN_BACKGROUND="true" in the standalone.sh (the default provided launch script for as7) also doesn't help.

Comment 1 Jirka Kremser 2013-02-11 12:41:55 UTC
Replicated also for as6 (eap 5.1.2). This is happening because of following lines in the launch script (doesn't matter if it is standalone.sh or run.sh):

      trap "kill -HUP  $JBOSS_PID" HUP
      trap "kill -TERM $JBOSS_PID" INT
      trap "kill -QUIT $JBOSS_PID" QUIT
      trap "kill -PIPE $JBOSS_PID" PIPE
      trap "kill -TERM $JBOSS_PID" TERM

i.e. script register itself for listening on the signals mentioned above and re-sends (relays) the signal to the actual jboss process. If these commands are commented out, the life cycle of AS will survive the life cycle of the agent.

A quick fix may try to find those traps commands in the launch script and comment them out.

Comment 2 Jirka Kremser 2013-02-18 14:21:28 UTC
Adding following code to AgentMain.start() method solves the issue:

   SignalHandler signalHandler = new SignalHandler() {
       public void handle(Signal signal) {
           LOG.warn("Catching interrupt signal, shutting down all the threads."
           m_shutdownHook.run();
       }
   };
   Signal.handle(new Signal("INT"), signalHandler);


Unfortunately, the classes SignalHandler and Signal are coming from sun.misc package and we can't depend on them. The code make use of native methods so it can't be copy&pasted to our code base.