1

我正在尝试使用 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 服务运行或在交互式会话之外自动启动的替代方法。

4

3 回答 3

0

这似乎是 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/下载,现在服务确实关闭了。

原来的javaStartMode 在关机时会产生错误,但关机。不过,exeStartMode 可以毫无问题地工作。

于 2015-03-05T00:35:24.923 回答
0

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

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

所以,我从源代码构建,并添加了一个停止方法。为此,我在 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 
于 2020-07-11T01:32:23.700 回答
-2

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

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

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-XXjar 位于 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" ^
于 2019-04-01T12:42:33.593 回答