4 Replies Latest reply on May 8, 2015 11:23 AM by afewcis

    JBoss 7.2.0 doesn't rotate log file when run as service

    afewcis

      I am running JBoss 7.2.0 on Windows Server 2008; I have the same issue on my Windows 7 development workstation. I have set up JBoss 7.2.0  to run as a service using the instructions at Jboss 7.1.1 as Windows service (with minor changes in the service name, and that my log file is server.log instead of standalone.log). When I start JBoss using standalone.bat, it renames server.log with a date and creates a new log file, just as it should. But if I run it as a service, the file does not get renamed, and JBoss eventually overwrites server.log (after generating a Java I/O error due to the fact that the file is initially in use). service.bat appears to be properly referencing and invoking standalone.bat, and all of the configurations specified therein (standalone.xml, logging.properties). The service starts up and runs fine otherwise, it just doesn't rotate the log file. I have checked Windows permissions on server.log and all folders on its path, and SYSTEM has full permissions.

       

      I have no idea what else to try. My service.bat is below. TIA for any suggestions.

       

      service.bat

      ---------------------------------------------------------------------------------------------------------------

       

      @echo off
      REM JBoss, the OpenSource webOS
      REM
      REM Distributable under LGPL license.
      REM See terms of license at gnu.org.
      REM
      REM -------------------------------------------------------------------------
      REM JBoss Service Script for Windows
      REM -------------------------------------------------------------------------


      @if not "%ECHO%" == "" echo %ECHO%
      @if "%OS%" == "Windows_NT" setlocal
      set DIRNAME=%CD%

      REM
      REM VERSION, VERSION_MAJOR and VERSION_MINOR are populated
      REM during the build with ant filter.
      REM
      set SVCNAME=JBAS72SVC
      set SVCDISP=JBoss Application Server 7.2.0
      set SVCDESC=JBoss Application Server 7.2.0 GA/Platform: Windows x64
      set NOPAUSE=Y

      REM Suppress killing service on logoff event
      REM set JAVA_OPTS=-Xrs

      REM Figure out the running mode

      if /I "%1" == "install"   goto cmdInstall
      if /I "%1" == "uninstall" goto cmdUninstall
      if /I "%1" == "start"     goto cmdStart
      if /I "%1" == "stop"      goto cmdStop
      if /I "%1" == "restart"   goto cmdRestart
      if /I "%1" == "signal"    goto cmdSignal
      echo Usage: service install^|uninstall^|start^|stop^|restart^|signal
      goto cmdEnd

      REM jbosssvc retun values
      REM ERR_RET_USAGE           1
      REM ERR_RET_VERSION         2
      REM ERR_RET_INSTALL         3
      REM ERR_RET_REMOVE          4
      REM ERR_RET_PARAMS          5
      REM ERR_RET_MODE            6

      :errExplain
      if errorlevel 1 echo Invalid command line parameters
      if errorlevel 2 echo Failed installing %SVCDISP%
      if errorlevel 4 echo Failed removing %SVCDISP%
      if errorlevel 6 echo Unknown service mode for %SVCDISP%
      goto cmdEnd

      :cmdInstall
      jbosssvc.exe -imwdc %SVCNAME% "%DIRNAME%" "%SVCDISP%" "%SVCDESC%" service.bat
      if not errorlevel 0 goto errExplain
      echo Service %SVCDISP% installed
      goto cmdEnd

      :cmdUninstall
      jbosssvc.exe -u %SVCNAME%
      if not errorlevel 0 goto errExplain
      echo Service %SVCDISP% removed
      goto cmdEnd

      :cmdStart
      REM Executed on service start
      del .r.lock 2>&1 | findstr /C:"being used" > nul
      if not errorlevel 1 (
        echo Could not continue. Locking file already in use.
        goto cmdEnd
      )
      echo Y > .r.lock
      jbosssvc.exe -p 1 "Starting %SVCDISP%" > C:\jboss-7.2.0.Final\standalone\log\server.log
      call standalone.bat --server-config=standalone.xml < .r.lock >> C:\jboss-7.2.0.Final\standalone\log\server.log 2>&1
      jbosssvc.exe -p 1 "Shutdown %SVCDISP% service" >> C:\jboss-7.2.0.Final\standalone\log\server.log
      del .r.lock
      goto cmdEnd

      :cmdStop
      REM Executed on service stop
      echo Y > .s.lock
      jbosssvc.exe -p 1 "Shutting down %SVCDISP%" > C:\jboss-7.2.0.Final\standalone\log\shutdown.log
      call jboss-cli.bat --connect command=:shutdown >> C:\jboss-7.2.0.Final\standalone\log\shutdown.log 2>&1
      jbosssvc.exe -p 1 "Shutdown %SVCDISP% service" >> C:\jboss-7.2.0.Final\standalone\log\shutdown.log
      del .s.lock
      goto cmdEnd

      :cmdRestart
      REM Executed manually from command line
      REM Note: We can only stop and start
      echo Y > .s.lock
      jbosssvc.exe -p 1 "Shutting down %SVCDISP%" >> C:\jboss-7.2.0.Final\standalone\log\shutdown.log
      call jboss-cli.bat --connect command=:shutdown >> C:\jboss-7.2.0.Final\standalone\log\shutdown.log 2>&1
      del .s.lock
      :waitRun
      REM Delete lock file
      del .r.lock > nul 2>&1
      REM Wait one second if lock file exist
      jbosssvc.exe -s 1
      if exist ".r.lock" goto waitRun
      echo Y > .r.lock
      jbosssvc.exe -p 1 "Restarting %SVCDISP%" >> C:\jboss-7.2.0.Final\standalone\log\server.log
      call standalone.bat --server-config=standalone.xml < .r.lock >> C:\jboss-7.2.0.Final\standalone\log\server.log 2>&1
      jbosssvc.exe -p 1 "Shutdown %SVCDISP% service" >> C:\jboss-7.2.0.Final\standalone\log\server.log
      del .r.lock
      goto cmdEnd

      :cmdSignal
      REM Send signal to the service.
      REM Requires jbosssch.dll to be loaded in JVM
      @if not ""%2"" == """" goto execSignal
      echo Missing signal parameter.
      echo Usage: service signal [0...9]
      goto cmdEnd
      :execSignal
      jbosssvc.exe -k%2 %SVCNAME%
      goto cmdEnd

      :cmdEnd

        • 1. Re: JBoss 7.2.0 doesn't rotate log file when run as service
          jamezp

          You're piping stdout to the server.log which the server is also trying to write to. You need to either pipe to console.log (really any different file) or just remove the console-handler.

           

          --

          James R. Perkins

          • 2. Re: JBoss 7.2.0 doesn't rotate log file when run as service
            afewcis

            Thank you for your help. I tried changing server.log to a different file in the seven places where service.bat is writing to it, and also tried REMming it out, but it's still not creating the rolling log file. Windows scripts are really out of my area of expertise--maybe I missed something?

            • 3. Re: JBoss 7.2.0 doesn't rotate log file when run as service
              jamezp

              By default the file will rotate daily. This however only happens if something is being logged. You definitely don't want to redirect stdout and stderr to the server.log or any log file defined by the server. Most people usually redirect the output to console.log. You could also remove the console-handler from JBoss EAP which should write nothing to the console.log.

               

              --

              James R. Perkins

              • 4. Re: JBoss 7.2.0 doesn't rotate log file when run as service
                afewcis

                Removing the console-handler didn't solve the issue, but it turned out I still had a line referencing server.log. So I changed all those references in the startup command sequence to boot.log, and all in the shutdown sequences to shutdown.log, and this solved the problem. Thank you for pointing me in the right direction.