【问题标题】:Config for Tika Windows Service with Apache Commons Daemon使用 Apache Commons Daemon 配置 Tika Windows 服务
【发布时间】:2015-03-04 06:12:34
【问题描述】:

我正在尝试使用 Apache Commons Daemon 让 Tika JAXRS 作为 Windows 服务运行。

我有来自http://tika.apache.org/download.html 的 tika-server-1.7.jar

我已经从http://commons.apache.org/proper/commons-daemon/binaries.html 下载了用于 Apache Commons Daemon 的 v1.0.15 版 Windows 二进制文件

我可以将 Tika 作为服务启动,但我无法确定停止方法使用什么。

prunsrv.exe //IS//tika-daemon
 --DisplayName "Tika Daemon" 
 --Classpath "C:\Tika Service\tika-server-1.7.jar"
 --StartClass "org.apache.tika.server.TikaServerCli"
 --StopClass "org.apache.tika.server.TikaServerCli"
 --StartMethod main
 --StopMethod main
 --Description "Tika Daemon Windows Service"
 --StartMode java
 --StopMode java

这会启动,并且按我希望的那样工作,但是在尝试停止服务时它没有响应。显然org.apache.tika.server.TikaServerCli.main(string[] args) 不是一个合适的停止方法,但我已经找不到替代方法了。

我也欢迎任何让 Tika 作为 Windows 服务运行的替代方法,或者以其他方式在交互式会话之外自动启动。

【问题讨论】:

  • 如果你只定义一个运行 java.exe 并带有参数 -jar tika-server.jar 的服务,会发生什么情况?
  • 同样的故事,服务运行良好,但无法停止,只是尝试超时。使用了以下服务注册命令:prunsrv.exe //IS//tika-daemon --DisplayName "Tika Daemon" --Description "Tika Daemon Windows Service" --StartMode exe --StartImage "C:\Program Files\Java\jdk1.8.0_31\jre\bin\java.exe" --StartPath "C:\Program Files\Java\jdk1.8.0_31\jre\bin" ++StartParams -jar;"C:\Tika Service\tika-server-1.7.jar"

标签: jetty apache-tika apache-commons-daemon


【解决方案1】:

这似乎是 Apache Commons Daemon 1.0.15 的一个已知问题。 https://issues.apache.org/jira/browse/DAEMON-298

我换了 1.0.14 版,从 Apache 档案库 http://archive.apache.org/dist/commons/daemon/binaries/windows/ 下载,现在服务确实关闭了。

原来的java StartMode 在关机时会产生错误,但确实关机了。不过,exe StartMode 可以正常工作。

【讨论】:

  • 话虽如此,我仍然没有得到一致的结果。 1.0.14 在我的 Win8.1 PC 上使用 exe StartMode 运行良好,但在 WinServer2008R2 PC 上它会关闭,但也会引发错误。
【解决方案2】:

大约一年前我遇到了这个问题并找到了解决方案。在 JVM 模式下运行 Apache Commons Daemon 将允许您指定 StartClass 和 StartMethod,这可以正常工作,因为您只需将其指向 static void Main(...){}

但是,stop 不起作用,因为没有可以调用的 stop 方法。

所以,我从源代码构建,并添加了一个停止方法。为此,我在 tika 项目中创建了一个 PR。 Babble 被否决的解决方案基本上是一样的,但我真的很想在基本 jar 文件中看到它。 https://github.com/apache/tika/pull/324

https://www.michaelwda.com/post/tika_windows_service 此处提供一些其他详细信息和屏幕截图。

C:\source\tika\commons-daemon-1.2.2-bin-windows\amd64\prunsrv.exe //IS//tika-daemon ^
--DisplayName "Tika Daemon"  ^
--Description "Tika Daemon Windows Service" ^
--Classpath C:\source\tika\tika-server.jar ^
--StartClass "org.apache.tika.server.TikaServerCli" ^
--StopClass "org.apache.tika.server.TikaServerCli" ^
--StartMethod main ^
--StopMethod stop ^
--StartMode jvm  ^
--StopMode jvm ^
--StdOutput auto ^
--StdError auto ^
--Jvm "C:\Program Files\Java\jdk1.8.0_211\jre\bin\server\jvm.dll" ^
++StartParams -spawnChild 

【讨论】:

    【解决方案3】:

    我已经为您创建了一个 MSI:https://github.com/wbicode/TikaService-Installer(或者您可以自己安装设置:https://github.com/wbicode/TikaService

    您必须创建一个单独的类来实现它自己的启动/停止类(tika-server-X.X.jar 在它的类路径中)。

    public class WinService {
    
      public static void start(String[] args) {
          Class<?> clazz = Class.forName("org.apache.tika.server.TikaServerCli");
          Method method = clazz.getMethod("main", String[].class);
          method.setAccessible(true);
    
          method.invoke(null, (Object)args.toArray(new String[0]));
      }
    
      public static void stop(String[] args) {
          System.out.println("stopping... TikaService");
          Runtime.getRuntime().exit(0);
      }
    }
    

    它是用这个脚本安装的(tika-server-X.X.jar 位于 lib 文件夹内):

    prunsrv.exe //IS//tika-daemon ^
        --DisplayName "Tika Daemon" ^
        --Classpath "%SERVICE_PATH%\TikaService.jar;%SERVICE_PATH%\lib\*" ^
        --StartMode java ^
        --StartClass "your.namespace.WinService" ^
        --StartMethod start ^
        --StopMode java ^
        --StopClass "your.namespace.WinService" ^
        --StopMethod stop ^
        --Description "Tika Daemon Windows Service" ^
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-29
      • 1970-01-01
      • 1970-01-01
      • 2012-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多