I’m trying to run a Spring Boot application JAR file as a Windows service using procrun. I’ve installed the service and it was listed in Windows Services. When I’ve started the service, it stopped after few seconds, and in the Event Viewer log, the below error came
Service cannot be started. System.ComponentModel.Win32Exception: The directory name is invalid
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at winsw.Util.ProcessHelper.StartProcessAndCallbackForExit(Process processToStart, String executable, String arguments, Dictionary`2 envVars, String workingDirectory, Nullable`1 priority, ProcessCompletionCallback callback, Boolean redirectStdin, LogHandler logHandler, Boolean hideWindow)
at winsw.WrapperService.StartProcess(Process processToStart, String arguments, String executable, LogHandler logHandler, Boolean redirectStdin)
at winsw.WrapperService.OnStart(String[] args)
at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)
This is the .bat
file script I have used for installation of Service.
@echo off setlocal REM Set variables set SERVICE_NAME=E-invoice set DISPLAY_NAME="E-invoice Service" set DESCRIPTION="E-invoice API as a Windows Service" set SERVICE_JAR=e-invoice.jar REM I have also tried with Absolute path for classpath, still not worked set PRUNSRV=D:procrunprunsrv.exe set PRUNSRV_LOG=D:JARLogs%SERVICE_NAME%.log set PRUNSRV_ERR=D:JARLogs%SERVICE_NAME%-error.log set START_PATH=D:JAR REM Check if directories and files exist if not exist "%SERVICE_JAR%" ( echo Error in Service JAR path ) if not exist "%PRUNSRV%" ( echo Error in prunsrv path ) if not exist "%START_PATH%" ( echo Error in start path ) if not exist "D:JARLogs" ( echo Log path not found: D:JARLogs mkdir "D:JARLogs" if %errorlevel% neq 0 ( echo Failed to create log directory: C:spring-boot-applogs ) ) REM Install and configure the service with all parameters %PRUNSRV% //IS//%SERVICE_NAME% ^ --DisplayName="%DISPLAY_NAME%" ^ --Description="%DESCRIPTION%" ^ --Startup=auto ^ --Install="%PRUNSRV%" ^ --LogPath="D:JARLogs" ^ --LogLevel=Debug ^ --StdOutput="%PRUNSRV_LOG%" ^ --StdError="%PRUNSRV_ERR%" ^ --Jvm=auto ^ --Classpath="%SERVICE_JAR%" ^ --StartMode=Java ^ --StartClass=org.springframework.boot.loader.JarLauncher ^ --StartMethod=main ^ --StartParams=start ^ --StopMode=Java ^ --StopClass=org.springframework.boot.loader.JarLauncher ^ --StopMethod=main ^ --StopParams=stop ^ --LogLevel=Debug ^ --Startup=auto ^ --StartPath="%START_PATH%" REM Check if the service installation was successful if %errorlevel% neq 0 ( echo Service installation failed ) echo Service %SERVICE_NAME% installed and configured successfully. exit /b 0
Additionally, the logs are also not generated in the specified directory. After running the command(procrun_install_service.bat) in administrator CMD, the below response came
[2024-07-07 22:32:56] [warn] [10624] Failed to grant service user ‘NT AUTHORITYLocalService’ write permissions to log path ‘C:Windowssystem32LogFilesApache’ due to error ’19: The media is write protected.’
Service E-invoice installed and configured successfully.
I’m new to this process and every time I’m getting stuck at somewhere, so your timely help will be highly appreciated..
Thanks in Advance..
Sai from CDM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.