-1

Everthing on Java.

Environment: RedHat Linux 12.3

NOTE:  1. Old model: There was NO A.java
                     "script.sh" starts/stops B.java as process
       2. New model: There IS A.java
                     "script.sh" never uses A
                     "script.sh" starts B.java as process.
                     "myGraceful.sh" stops process Gracefully 
                     "script.sh" is NEVER used for stopping
               

Server(B.java in server.jar):

  • Java Process triggered as: ./script.sh {start|stop}

  • Its a legacy class existing for 10 yrs or more

  • has RemoteB Interface

  • has

              graceFul(){ ..handles all DB ,user states,connection...etc
                           ..works perfectly from Admin
                           ..invoked as RMI from JSP 
                           ..never invoked by script till now
                         }
              initServer(){...}
              getUsers(){...}
    

Requirement & My Effort:

Everyone knows how the code RMI Looks or .sh to invoke java. Hence I dont think pasting a proprietary code should be expected here.

Graceful needs to be done from shell script on same Server node. On Server everything runniing by Spring. I will die if I try to Inject a Bean as there is going to be 100x1000 dependencies coming in queue. Hence I created

RMI Client(com/common/task/A.java in same server.jar):

  1. A can be triggered by: ./myGraceful.sh stop (eg. java -cp... com.A 2>&1)
  2. in same server.jar - hence inevitaby loaded (note not running) on same Server node.
  3. having p s v main(String args[])
  4. Forks Thread ..thread calls RMI shutdown on B ...and thread expected to die on own.

Problem:

Server shutting down perfectly. Then If I isssue following command AGAIN and AGAIN:

          ./script.sh start

Server starts up. But within a minute it stops automatically. I dont have any clue what and which is stopping the Server. I Observed

Prior to any of my new modifications:


  "./script.sh stop"               [used to work flawlessly calling kill -9 $pid ]
  "ps - aefwww | grep java"         used to show:

 pid ppid.. /usr/java/jdk/bin/java ........java -D....  -Djava.timeout=..  -D....
 pid ppid.. .../abc/ ....java...
 pid ppid.. .../xyz/ .................java...

But now


"./myGraceful.sh stop" triggers modified server.jar(which now has A.java):

  "ps - aefwww | grep java"  shows:
 pid ppid.. .../abc/ ....java...
 pid ppid.. .../xyz/ .................java...

Here goes some code:

myGraceful.sh:
----------------
    #!/bin/bash
    CLASSPATH=$COMMON_CLASS_PATH:$LIB_INHOUSE/server.jar
    rmiIp=x.y.zz.www [hidden]
    rmiPort=xxxx [hidden]
    peerId=1
    period=5
    
    function kill_server(){
        echo -n "Shutting down Server ($pid): "
            echo "executing Arnab" 
            echo "arg0 : $0 pid : $pid"     
            java -Djava.rmi.server.hostname=localhost \
                 com.common.task.GracefulRunner $rmiIp $rmiPort $peerId $period  2>&1
            echo Done
    }
    case "$1" in
    start)
            get_pids "CustomBootstrap" $2
            if [ "$pid" != "" ] ; then
                get_processname "CustomBootstrap" $2
                if [ "$server" != "" ] ; then
                    echo "Server already running. pid = $pid"
                    exit 1
                fi
                if [ "$ctserver" != "" ] ; then         
                echo "Shutting down CT Server($pid): "
                    kill -SIGQUIT $pid
                    kill -9 $pid
                    echo Done
                fi  
            fi          
        $0  run $2 1>&2 &
        sleep 2
        $0  status $2
        # $0 err
        ;;
    stop)
        $0 kill $2
        ;;
    kill)
        get_pids "CustomBootstrap" $2
        if [ "$pid" != "" ] ; then
            kill_server
            echo "Server  ended at `date`" 
        else
            get_pids "Launcher" $2
            if [ "$pid" != "" ] ; then
                kill_server
            else
               echo "Server is not running !"           
            fi
        fi
        ;;
   esac

A.java

 public class A {

   class GracefulStopperThread implements Runnable{
        private String serverRMIIp = null;
        private int serverRmiPort =0;
        private String serverPeerId =null;
        private int shutDownPeriod =0;
        
         public GracefulStopperThread(String rmiIp,String rmiPort,String peerId,String period){ 
             serverRMIIp = rmiIp;
             serverRmiPort = Integer.parseInt(rmiPort);
             serverPeerId = peerId;
             shutDownPeriod =Integer.parseInt(period);    
             
         }
        
         public void run() {
            System.out.println("***************************************** GracefulStopper is running *******************************************");
                System.out.println("serverPeerId :="+serverPeerId+" , shutDownPeriod :="+shutDownPeriod);
            try {
                  
                
                IRemoteServer serverRef = null;
                String rmiUrl = getURL(serverRMIIp,serverRmiPort,serverPeerId);
                System.out.println("THE RMI URL : "+rmiUrl);
            
                serverRef = (IRemoteServer) Naming.lookup(rmiUrl );
                com.server.ds.IRemoteServer  pcServerRef = (com.server.ds.IRemoteServer) serverRef;
                pcServerRef.graceful(SHUTDOWN_TYPE_SERVER_NOTSYSTEM,"Gracefully Shutting down withing 10 mins", shutDownPeriod);
                System.out.println("GracefulStopperThread completed ");
                } catch (Exception e) {
                    e.printStackTrace();
                }
         }

        private String getURL(String rmiIp,int rmiPort,String peerId) {
             return new StringBuffer(32).append("rmi://").append(serverRMIIp).append(':').append(serverRmiPort)
                        .append('/').append(serverPeerId).toString();
        }
         
 }
 
 
  public static void main(String args[]) throws InterruptedException {
               A agent = new A();         
               Runnable stopper = agent.new GracefulStopperThread(args[0],args[1],args[2],args[3]);
               Thread t = new Thread(stopper);
               t.start();
               t.join();
               System.out.println("MainThread completed ");
   }
}
 
Arnab Dutta
  • 168
  • 11
  • 1
    You can't seriously expect to get an answer to this question without posting some code. – user207421 May 03 '16 at 22:13
  • @EJP which code should I paste here ? I added some code though. Although, Enlarging the picture shows the entire required code needed to give me insight on the issue – Arnab Dutta May 04 '16 at 07:31
  • @EJP as the solution is not going to help anyone...and it was irrelevant to any server or client code or RMI - so should I delete this question ? – Arnab Dutta Jul 23 '16 at 19:38
  • @bohemian As the solution is not related to any of the server or client or RMI codes above (which was the whole popint of discussion) - so shall I delete this question or what ? – Arnab Dutta Jul 23 '16 at 19:41
  • Yes you should delete it. And it is rather late to be adding the code now, seven years after it was requested, – user207421 May 10 '23 at 04:52

1 Answers1

0

From catalina and tomcat logs it became clear - there was a wrong missing JMX entry in the jmx config file which has nothing to do with all above. This caused Tomcat to stop after 85 % of its start. Hence it actually never started. Question can be closed and marked solved.

Arnab Dutta
  • 168
  • 11