瀏覽代碼

Merge branch '10.3.x'

Shinsuke Sugaya 8 年之前
父節點
當前提交
b42fe99ff1

二進制
src/main/assemblies/files/fess-service-mgr.exe


+ 1 - 1
src/main/assemblies/files/fess.in.bat

@@ -84,7 +84,7 @@ set APP_NAME=fess
 set ES_HOME=%FESS_HOME%/es
 
 set FESS_CLASSPATH=%FESS_HOME%\lib\classes
-set FESS_JAVA_OPTS=%FESS_JAVA_OPTS% -Dfess
+set FESS_JAVA_OPTS=-Dfess %FESS_JAVA_OPTS%
 set FESS_JAVA_OPTS=%FESS_JAVA_OPTS% -Des-foreground=yes
 set FESS_JAVA_OPTS=%FESS_JAVA_OPTS% -Dfess.home="%FESS_HOME%"
 set FESS_JAVA_OPTS=%FESS_JAVA_OPTS% -Dfess.es.dir="%ES_HOME%"

+ 45 - 17
src/main/assemblies/files/service.bat

@@ -1,7 +1,7 @@
 @echo off
-SETLOCAL
+SETLOCAL enabledelayedexpansion
 
-TITLE Fess Service 10.0.0-SNAPSHOT
+TITLE Fess Service
 
 if NOT DEFINED JAVA_HOME goto err
 
@@ -13,7 +13,15 @@ if not exist "%JAVA_HOME%\bin\java.exe" (
 echo JAVA_HOME points to an invalid Java installation (no java.exe found in "%JAVA_HOME%"^). Exiting...
 goto:eof
 )
-"%JAVA_HOME%\bin\java" -version 2>&1 | "%windir%\System32\find" "64-Bit" >nul:
+
+"%JAVA_HOME%\bin\java" -Xmx50M -version > nul 2>&1
+
+if errorlevel 1 (
+	echo Warning: Could not start JVM to detect version, defaulting to x86:
+	goto x86
+)
+
+"%JAVA_HOME%\bin\java" -Xmx50M -version 2>&1 | "%windir%\System32\find" "64-Bit" >nul:
 
 if errorlevel 1 goto x86
 set EXECUTABLE=%FESS_HOME%\bin\fess-service-x64.exe
@@ -31,8 +39,6 @@ if EXIST "%EXECUTABLE%" goto okExe
 echo fess-service-(x86|x64).exe was not found...
 
 :okExe
-set FESS_VERSION=10.0.0-SNAPSHOT
-
 if "%LOG_DIR%" == "" set LOG_DIR=%FESS_HOME%\logs
 
 if "x%1x" == "xx" goto displayUsage
@@ -75,6 +81,16 @@ goto:eof
 echo The service '%SERVICE_ID%' has been stopped
 goto:eof
 
+:doManagment
+set EXECUTABLE_MGR=%FESS_HOME%\bin\fess-service-mgr.exe
+"%EXECUTABLE_MGR%" //ES//%SERVICE_ID%
+if not errorlevel 1 goto managed
+echo Failed starting service manager for '%SERVICE_ID%'
+goto:eof
+:managed
+echo Successfully started service manager for '%SERVICE_ID%'.
+goto:eof
+
 :doRemove
 rem Remove the service
 "%EXECUTABLE%" //DS//%SERVICE_ID% %LOG_OPTS%
@@ -90,21 +106,24 @@ echo Installing service      :  "%SERVICE_ID%"
 echo Using JAVA_HOME (%ARCH%):  "%JAVA_HOME%"
 
 rem Check JVM server dll first
-set JVM_DLL=%JAVA_HOME%\jre\bin\server\jvm.dll
-if exist "%JVM_DLL%" goto foundJVM
+if exist "%JAVA_HOME%"\jre\bin\server\jvm.dll (
+	set JVM_DLL=\jre\bin\server\jvm.dll
+	goto foundJVM
+)
 
 rem Check 'server' JRE (JRE installed on Windows Server)
-set JVM_DLL=%JAVA_HOME%\bin\server\jvm.dll
-if exist "%JVM_DLL%" goto foundJVM
+if exist "%JAVA_HOME%"\bin\server\jvm.dll (
+	set JVM_DLL=\bin\server\jvm.dll
+	goto foundJVM
+)
 
 rem Fallback to 'client' JRE
-set JVM_DLL=%JAVA_HOME%\bin\client\jvm.dll
-
-if exist "%JVM_DLL%" (
-echo Warning: JAVA_HOME points to a JRE and not JDK installation; a client (not a server^) JVM will be used...
+if exist "%JAVA_HOME%"\bin\client\jvm.dll (
+	set JVM_DLL=\bin\client\jvm.dll
+	echo Warning: JAVA_HOME points to a JRE and not JDK installation; a client (not a server^) JVM will be used...
 ) else (
-echo JAVA_HOME points to an invalid Java installation (no jvm.dll found in "%JAVA_HOME%"^). Existing...
-goto:eof
+	echo JAVA_HOME points to an invalid Java installation (no jvm.dll found in "%JAVA_HOME%"^). Exiting...
+	goto:eof
 )
 
 :foundJVM
@@ -130,12 +149,21 @@ set FESS_PARAMS=-Dfess;-Dfess.home="%FESS_HOME%";-Dfess.es.dir="%ES_HOME%";-Dfes
 set JVM_OPTS=%JAVA_OPTS: =;%
 
 if not "%FESS_JAVA_OPTS%" == "" set JVM_FESS_JAVA_OPTS=%FESS_JAVA_OPTS: =#%
-if not "%FESS_JAVA_OPTS%" == "" set JVM_OPTS=%JVM_OPTS%;%JVM_FESS_JAVA_OPTS%
+if not "%FESS_JAVA_OPTS%" == "" set JVM_OPTS=%JVM_OPTS%;%JVM_FESS_JAVA_OPTS%;
 
 if "%FESS_START_TYPE%" == "" set FESS_START_TYPE=manual
 if "%FESS_STOP_TIMEOUT%" == "" set FESS_STOP_TIMEOUT=0
 
-"%EXECUTABLE%" //IS//%SERVICE_ID% --Startup %FESS_START_TYPE% --StopTimeout %FESS_STOP_TIMEOUT% --StartClass org.codelibs.fess.FessBoot --StopClass org.codelibs.fess.FessBoot --StartMethod main --StopMethod shutdown --Classpath "%FESS_CLASSPATH%" --JvmSs %JVM_SS% --JvmMs %JVM_XMS% --JvmMx %JVM_XMX% --JvmOptions %JVM_OPTS% ++JvmOptions %FESS_PARAMS% %LOG_OPTS% --PidFile "%SERVICE_ID%.pid" --DisplayName "Fess %FESS_VERSION% (%SERVICE_ID%)" --Description "Fess %FESS_VERSION% Windows Service - https://github.com/codelibs/fess" --Jvm "%JVM_DLL%" --StartMode jvm --StopMode jvm --StartPath "%FESS_HOME%"
+if "%SERVICE_DISPLAY_NAME%" == "" set SERVICE_DISPLAY_NAME=Fess (%SERVICE_ID%)
+if "%SERVICE_DESCRIPTION%" == "" set SERVICE_DESCRIPTION=Fess Service - https://github.com/codelibs/fess
+
+if not "%SERVICE_USERNAME%" == "" (
+	if not "%SERVICE_PASSWORD%" == "" (
+		set SERVICE_PARAMS=%SERVICE_PARAMS% --ServiceUser "%SERVICE_USERNAME%" --ServicePassword "%SERVICE_PASSWORD%"
+	)
+)
+
+ "%EXECUTABLE%" //IS//%SERVICE_ID% --Startup %FESS_START_TYPE% --StopTimeout %FESS_STOP_TIMEOUT% --StartClass org.codelibs.fess.FessBoot --StopClass org.codelibs.fess.FessBoot --StartMethod main --StopMethod shutdown --Classpath "%FESS_CLASSPATH%" --JvmSs %JVM_SS% --JvmMs %JVM_XMS% --JvmMx %JVM_XMX% --JvmOptions %JVM_OPTS% ++JvmOptions %FESS_PARAMS% %LOG_OPTS% --PidFile "%SERVICE_ID%.pid" --DisplayName "%SERVICE_DISPLAY_NAME%" --Description "%SERVICE_DESCRIPTION%" --Jvm "%%JAVA_HOME%%%JVM_DLL%" --StartMode jvm --StopMode jvm --StartPath "%FESS_HOME%" %SERVICE_PARAMS% ++StartParams start
 
 if not errorlevel 1 goto installed
 echo Failed installing '%SERVICE_ID%' service

+ 22 - 13
src/main/java/org/codelibs/fess/helper/ProcessHelper.java

@@ -58,7 +58,7 @@ public class ProcessHelper {
         JobProcess jobProcess;
         try {
             jobProcess = new JobProcess(pb.start());
-            destroyProcess(runningProcessMap.putIfAbsent(sessionId, jobProcess));
+            destroyProcess(sessionId, runningProcessMap.putIfAbsent(sessionId, jobProcess));
             return jobProcess;
         } catch (final IOException e) {
             throw new FessSystemException("Crawler Process terminated.", e);
@@ -67,14 +67,14 @@ public class ProcessHelper {
 
     public boolean destroyProcess(final String sessionId) {
         final JobProcess jobProcess = runningProcessMap.remove(sessionId);
-        return destroyProcess(jobProcess);
+        return destroyProcess(sessionId, jobProcess);
     }
 
     public boolean isProcessRunning() {
         return !runningProcessMap.isEmpty();
     }
 
-    protected boolean destroyProcess(final JobProcess jobProcess) {
+    protected boolean destroyProcess(final String sessionId, final JobProcess jobProcess) {
         if (jobProcess != null) {
             final InputStreamThread ist = jobProcess.getInputStreamThread();
             try {
@@ -83,26 +83,35 @@ public class ProcessHelper {
                 logger.warn("Could not interrupt a thread of an input stream.", e);
             }
 
-            final CountDownLatch latch = new CountDownLatch(1);
+            final CountDownLatch latch = new CountDownLatch(3);
             final Process process = jobProcess.getProcess();
-            new Thread((Runnable) () -> {
+            new Thread(() -> {
                 try {
                     IOUtils.closeQuietly(process.getInputStream());
-                } catch (final Exception e1) {
-                    logger.warn("Could not close a process input stream.", e1);
+                } catch (final Exception e) {
+                    logger.warn("Could not close a process input stream.", e);
+                } finally {
+                    latch.countDown();
                 }
+            }, "ProcessCloser-input-" + sessionId).start();
+            new Thread(() -> {
                 try {
                     IOUtils.closeQuietly(process.getErrorStream());
-                } catch (final Exception e2) {
-                    logger.warn("Could not close a process error stream.", e2);
+                } catch (final Exception e) {
+                    logger.warn("Could not close a process error stream.", e);
+                } finally {
+                    latch.countDown();
                 }
+            }, "ProcessCloser-error-" + sessionId).start();
+            new Thread(() -> {
                 try {
                     IOUtils.closeQuietly(process.getOutputStream());
-                } catch (final Exception e3) {
-                    logger.warn("Could not close a process output stream.", e3);
+                } catch (final Exception e) {
+                    logger.warn("Could not close a process output stream.", e);
+                } finally {
+                    latch.countDown();
                 }
-                latch.countDown();
-            }, "ProcessCloser").start();
+            }, "ProcessCloser-output-" + sessionId).start();
 
             try {
                 latch.await(10, TimeUnit.SECONDS);

+ 50 - 24
src/main/java/org/codelibs/fess/thumbnail/impl/WebDriverGenerator.java

@@ -39,6 +39,7 @@ import org.openqa.selenium.phantomjs.PhantomJSDriver;
 import org.openqa.selenium.phantomjs.PhantomJSDriverService;
 import org.openqa.selenium.phantomjs.PhantomJSDriverService.Builder;
 import org.openqa.selenium.remote.DesiredCapabilities;
+import org.openqa.selenium.remote.UnreachableBrowserException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -62,32 +63,40 @@ public class WebDriverGenerator extends BaseThumbnailGenerator {
 
     protected String imageFormatName = "png";
 
+    protected long unreachableCheckInterval = 10 * 60 * 1000L;
+
+    protected long previousCheckTime = 0;
+
     @PostConstruct
     public void init() {
         final FessConfig fessConfig = ComponentUtil.getFessConfig();
         if (fessConfig.isThumbnailHtmlPhantomjsEnabled() && super.isAvailable()) {
-            try {
-                if (webDriver == null) {
-                    if (webDriverCapabilities == null) {
-                        webDriver = new PhantomJSDriver();
-                    } else {
-                        if (webDriverCapabilities instanceof DesiredCapabilities) {
-                            final DesiredCapabilities capabilities = (DesiredCapabilities) webDriverCapabilities;
-                            webDriverCapabilities.asMap().entrySet().stream()
-                                    .filter(e -> e.getValue() instanceof String && filePathMap.containsKey(e.getValue().toString()))
-                                    .forEach(e -> capabilities.setCapability(e.getKey(), filePathMap.get(e.getValue().toString())));
-                        }
-                        webDriver = new PhantomJSDriver(createDriverService(webDriverCapabilities), webDriverCapabilities);
-                    }
-                }
-                webDriver.manage().window().setSize(new Dimension(windowWidth, windowHeight));
-            } catch (final Exception e) {
-                if (logger.isDebugEnabled()) {
-                    logger.debug("WebDriver is not available for generating thumbnails.", e);
+            startWebDriver();
+        }
+    }
+
+    protected void startWebDriver() {
+        try {
+            if (webDriver == null) {
+                if (webDriverCapabilities == null) {
+                    webDriver = new PhantomJSDriver();
                 } else {
-                    logger.info("WebDriver is not available for generating thumbnails.");
+                    if (webDriverCapabilities instanceof DesiredCapabilities) {
+                        final DesiredCapabilities capabilities = (DesiredCapabilities) webDriverCapabilities;
+                        webDriverCapabilities.asMap().entrySet().stream()
+                                .filter(e -> e.getValue() instanceof String && filePathMap.containsKey(e.getValue().toString()))
+                                .forEach(e -> capabilities.setCapability(e.getKey(), filePathMap.get(e.getValue().toString())));
+                    }
+                    webDriver = new PhantomJSDriver(createDriverService(webDriverCapabilities), webDriverCapabilities);
                 }
             }
+            webDriver.manage().window().setSize(new Dimension(windowWidth, windowHeight));
+        } catch (final Exception e) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("WebDriver is not available for generating thumbnails.", e);
+            } else {
+                logger.info("WebDriver is not available for generating thumbnails.");
+            }
         }
     }
 
@@ -96,6 +105,7 @@ public class WebDriverGenerator extends BaseThumbnailGenerator {
         if (webDriver != null) {
             synchronized (this) {
                 webDriver.quit();
+                webDriver = null;
             }
         }
     }
@@ -124,15 +134,27 @@ public class WebDriverGenerator extends BaseThumbnailGenerator {
 
         if (webDriver instanceof TakesScreenshot) {
             synchronized (this) {
-                webDriver.get(url);
-                final File thumbnail = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
-                convert(thumbnail, outputFile);
-                return true;
+                try {
+                    webDriver.get(url);
+                    final File thumbnail = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
+                    convert(thumbnail, outputFile);
+                    return true;
+                } catch (UnreachableBrowserException e) {
+                    if (logger.isDebugEnabled()) {
+                        logger.debug("WebDriver is not available.", e);
+                    }
+                    final long now = ComponentUtil.getSystemHelper().getCurrentTimeAsLong();
+                    if (now - previousCheckTime > unreachableCheckInterval) {
+                        destroy();
+                        startWebDriver();
+                        previousCheckTime = now;
+                    }
+                }
             }
         } else {
             logger.warn("WebDriver is not instance of TakesScreenshot: " + webDriver);
-            return false;
         }
+        return false;
     }
 
     @Override
@@ -242,4 +264,8 @@ public class WebDriverGenerator extends BaseThumbnailGenerator {
     public void setThumbnailHeight(final int thumbnailHeight) {
         this.thumbnailHeight = thumbnailHeight;
     }
+
+    public void setUnreachableCheckInterval(long unreachableCheckInterval) {
+        this.unreachableCheckInterval = unreachableCheckInterval;
+    }
 }