1

I'm trying to get Tika JAXRS running as a Windows Service using Apache Commons Daemon.

I've got tika-server-1.7.jar from http://tika.apache.org/download.html

I've downloaded v1.0.15 of the Windows binaries for Apache Commons Daemon from http://commons.apache.org/proper/commons-daemon/binaries.html

I can get Tika started as a service, but I can't determine what to use for a stop method.

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

This starts, and works as I'd hope, but when trying to stop the service it doesn't respond. Obviously org.apache.tika.server.TikaServerCli.main(string[] args) isn't a suitable stop method, but I'm lost for alternatives.

I'd also welcome any alternative methods for getting Tika running as a Windows Service, or otherwise auto-starting outside of an interactive session.

Snixtor
  • 4,239
  • 2
  • 31
  • 54
  • What happens if you just define a service which runs `java.exe` with an argument `-jar tika-server.jar`, does that work? – Gagravarr Mar 04 '15 at 10:10
  • Same story, service runs fine, but can't get it to stop, just times out trying. Used the following service registration command: `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"` – Snixtor Mar 04 '15 at 23:53

3 Answers3

0

It would appear this is a known issue of Apache Commons Daemon 1.0.15. https://issues.apache.org/jira/browse/DAEMON-298

I swapped in version 1.0.14, downloaded from Apache archives http://archive.apache.org/dist/commons/daemon/binaries/windows/ and the service now does shut down.

The original java StartMode produces an error on shutdown but does shutdown. The exe StartMode though, works without issue.

Snixtor
  • 4,239
  • 2
  • 31
  • 54
  • Having said that, I'm still not getting consistent results. 1.0.14 worked fine with exe StartMode on my Win8.1 PC, but on a WinServer2008R2 PC it shuts down, but also throws an error. – Snixtor Mar 05 '15 at 00:59
0

I ran into this about a year ago and found a solution. Running Apache Commons Daemon in JVM mode will allow you to specify the StartClass and the StartMethod, which works fine because you can just point it to static void Main(...){}

However, stop doesn't work because there's no stop method to call.

So, I built from source, and added a stop method. I've created a PR in the tika project for this. Babble's downvoted solution is basically the same thing, but I'd really like to see it available in the base jar file. https://github.com/apache/tika/pull/324

https://www.michaelwda.com/post/tika_windows_service a few additional details and screenshots here.

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 
Michael Davis
  • 21
  • 1
  • 3
-2

I've created a MSI which does this all for you: https://github.com/wbicode/TikaService-Installer (or you can install the setup yourself: https://github.com/wbicode/TikaService)

You'll have to create a separate class which implements its own start/stop-class (tika-server-X.X.jar is in it's classpath).

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);
  }
}

And it's installed with this script (the tika-server-X.X.jar lies inside the lib folder):

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" ^
Babble
  • 1
  • 2
  • 3