1 Reply Latest reply on Jul 1, 2008 11:20 AM by peterj

    Problem: Restarting  Jboss service from batch file ,which is

    svsubramanyam007

      Hi ,

      I have servlet deployed in Jboss. In servlet am trying to call (batch)
      file.
      In batch file am trying to stop the server and trying to restart server.
      All other tasks am able to perform and able to stop the server
      but could not achieve to restart the server.
      Here the Jboss is running as service.

      Please throw some light where am wrong in my steps.

      My code in servlet....

      private synchronized void resetDB () throws ServletException
      {
      mLogger.info("Start cleaning the database");

      String cmd = "ResetDB.bat > %JBOSS_HOME%\\server\\default\\log\\reset.log";

      try
      {
      Runtime.getRuntime().exec(cmd);
      }
      catch(IOException e)
      {
      throw new ServletException("Failed to create the external process to execute command " + cmd, e);
      }
      }
      }

      My batch file contains...

      IF EXIST "C:\subbu\JBoss\JBoss-4.2.2.GA" SET STDSETUP="1"

      IF STDSETUP EQU "1" SET JBOSS_HOME=C:\subbu\JBoss\JBoss-4.2.2.GA
      IF STDSETUP NEQ "1" SET JBOSS_HOME=C:\Lang\JBoss\JBoss-4.2.2.GA

      IF STDSETUP EQU "1" SET POSTGRES_HOME=%programfiles%\PostgreSQL\8.3\
      IF STDSETUP NEQ "1" SET POSTGRES_HOME=C:\Lang\PostgreSQL\8.3\

      set PGPASSFILE=C:\subbu\CMS\pgpass.conf
      set JBOSS_SERVICE=JBAS42SVC
      set JBOSS_BIN="%JBOSS_HOME%\bin"
      set POSTGRES_BIN=%POSTGRES_HOME%\bin
      set SVCDISP=JBoss Application Server 4.2
      set SVCDESC=JBoss Application Server 4.2.1.GA/Platform: Windows i686
      set DIRNAME=%JBOSS_BIN%

      pushd %JBOSS_BIN%

      :SERVICE_CHECK
      ECHO Checking for %JBOSS_SERVICE%....
      SC QUERY "%JBOSS_SERVICE%" > %temp%\temp.txt
      FINDSTR /c:"%JBOSS_SERVICE%" %temp%\temp.txt
      IF %ERRORLEVEL% EQU 0 GOTO SERVICEEXIST
      IF %ERRORLEVEL% NEQ 0 GOTO STARTSERVICE

      :SERVICEEXIST
      ECHO checking for JBoss Service is Running or not.
      FINDSTR /c:"RUNNING" %temp%\temp.txt
      IF %ERRORLEVEL% EQU 0 GOTO SERVICERUNNING
      IF %ERRORLEVEL% NEQ 0 GOTO SERVICESTOPPED


      :SERVICERUNNING
      ECHO Service is Running - Stopping %JBOSS_SERVICE%......
      NET STOP "%JBOSS_SERVICE%"
      TASKKILL /F /FI "MODULES EQ JavaBLMLib.dll" /FI "MODULES EQ Wpcap.dll" /IM java.exe
      GOTO STARTSERVICE

      :SERVICESTOPPED
      ECHO %JBOSS_SERVICE% stopped.
      TASKKILL /F /FI "MODULES EQ JavaBLMLib.dll" /FI "MODULES EQ Wpcap.dll" /IM java.exe
      GOTO STARTSERVICE

      :STARTSERVICE
      pushd %POSTGRES_BIN%
      psql -d postgres -f %JBOSS_HOME%\bin\resetDB.ddl -U systemmgr
      popd
      ECHO Starting %JBOSS_SERVICE%
      net start %JBOSS_SERVICE%


      PLEASE help me in understanding in solving the problem.


        • 1. Re: Problem: Restarting  Jboss service from batch file ,whic
          peterj

          My guess would be that your batch job is a subprocess of the Java process (the one running JBosAS). When a process goes away (and you are asking JBossAS to stop), all subprocesses are also killed. Therefore while your batch file is waiting for JBossAS to stop, it is quietly dying.

          Try this. Run the cmd.exe instead, and pass it "start ResetDB.bat". The 'start' command will run the batch job in a completely separate process (that is, one that is not a child of the Java process).