我正在使用Apache Commons Procrun(prunsrv.exe,重命名为testService.exe)将.jar安装为Windows服务。它会成功安装该服务,并显示在Windows Service Manager中。
当我尝试启动服务时,它失败。这是带有相关错误的commons-daemon日志:
[2019-01-14 09:52:52] [info] [12988] Commons Daemon procrun (1.1.0.0 64-bit) started
[2019-01-14 09:52:52] [info] [12988] Starting service 'testService' ...
[2019-01-14 09:52:52] [warn] [12988] Failed to obtain service description
[2019-01-14 09:52:56] [error] [12988] apxServiceControl(): dwState(4) != dwCurrentState(1); dwWin32ExitCode = 1066, dwWaitHint = 0, dwServiceSpecificExitCode = 1
[2019-01-14 09:52:56] [error] [12988] apxServiceControl(): returning FALSE
[2019-01-14 09:52:56] [error] [12988] Failed to start service 'testService'
[2019-01-14 09:52:56] [info] [12988] Start service finished, returning 0
[2019-01-14 09:52:56] [error] [12988] Commons Daemon procrun failed with exit value: 5 (Failed to start service)
这是我编写的用于安装/启动服务的脚本:
@echo off
SET SERVICE_NAME=testService
IF "%1%" == "start" GOTO START
IF "%1%" == "stop" GOTO STOP
IF "%1%" == "delete" GOTO DELETE
IF "%1%" NEQ "install" GOTO:EOF
SET PR_INSTALL="%~dp0testService.exe"
SET PR_CLASSPATH=testService.jar
SET PR_JVM=%JAVA_HOME%\jre\bin\server\jvm.dll
SET PR_STARTUP=auto
SET PR_STARTMODE=jvm
SET PR_STARTCLASS=com.testService
SET PR_STARTPARAM=start
SET PR_STOPMODE=jvm
SET PR_STOPCLASS=com.testService
SET PR_STOPPARAM=stop
%SERVICE_NAME%.exe install %SERVICE_NAME%
GOTO:EOF
:START
%SERVICE_NAME%.exe start %SERVICE_NAME%
GOTO:EOF
:STOP
%SERVICE_NAME%.exe stop %SERVICE_NAME%
GOTO:EOF
:DELETE
%SERVICE_NAME%.exe delete %SERVICE_NAME%
任何想法都表明该错误意味着什么?我似乎找不到任何相关信息,这真让我发疯。
答案 0 :(得分:0)
问题出在%SERVICE_NAME%.exe install %SERVICE_NAME%
电话上
我将它们替换为testService.exe install %SERVICE_NAME%
,并且服务按预期启动。