NSSM - not starts service after 1 execution with error - Non-Sucking Service Manager - nssm

I have multiple services in nssm (windows server 2019) but there is one which doesn't run.
I have set it up exactly as other one that runs successfully.
In the log of the application I get error for the application script but this in my opinion should not stops the nssm to continue run it on the next run, isn't correct?
Status of the service is SERVICE_RUNNING
If I stop and start then executes only once according to Event View and exits with code 0 , I guess this is error or?
parameters of the service are:
<path to nssm>\nssm.exe install Service1 <path to service>.exe
<path to nssm>\nssm.exe set Service1 AppDirectory <path to service>
<path to nssm>\nssm.exe set Service1 AppExit Default Restart
<path to nssm>\nssm.exe set Service1 AppRestartDelay 360000
<path to nssm>\nssm.exe set Service1 AppStdout <path to log file, its same if that matters>
<path to nssm>\nssm.exe set Service1 AppStderr <path to log file, its same if that matters>
<path to nssm>\nssm.exe set Service1 AppTimestampLog 1
<path to nssm>\nssm.exe set Service1 DisplayName Service1
<path to nssm>\nssm.exe set Service1 ObjectName user
<path to nssm>\nssm.exe set Service1 Start SERVICE_AUTO_START
<path to nssm>\nssm.exe set Service1 Type SERVICE_WIN32_OWN_PROCESS
Thanks in advance

Related

Run several indexes as a service using fscrawler

I have successfully created an index job using fscrawler and made it run as a service in windows as shown in the documentation:
set JAVA_HOME=c:\Program Files\Java\jdk15.0.1
set FS_JAVA_OPTS=-Xmx2g -Xms2g
/Elastic/fscrawler/bin/fscrawler.bat --config_dir C:\Documents\Elasctic\fscrawler job1 >>
/Elastic/logs/fscrawler.log 2>&1
However, I have several jobs (like 10 of them) which I would like to run concurrently. I have tried adding the start command as below but it gives me errors:
set JAVA_HOME=c:\Program Files\Java\jdk15.0.1
set FS_JAVA_OPTS=-Xmx2g -Xms2g
start "" /Elastic/fscrawler/bin/fscrawler.bat --config_dir C:\Documents\Elasctic\fscrawler job1 >>
/Elastic/logs/fscrawler.log 2>&1
start "" /Elastic/fscrawler/bin/fscrawler.bat --config_dir C:\Documents\Elasctic\fscrawler job2 >>
/Elastic/logs/fscrawler.log 2>&1
How do I add several index jobs to the batch file so that they all run simultaneously?

Solr Windows Service won't stop

I have Solr set up on my server and running as a service, everything runs beautifully until I come to try and stop the service, it just hangs. I have tried amending the arguments and spent forever trying to see if anyone has got the same problem. unfortunately my google fu has failed me.
Service is set up as per the below using the Commons Daemon Service Runner.
#echo off
set JAVA_HOME=D:\application\Java
set SERVICE_NAME=SolrService
set SERVICE_HOME=D:\application\Solr
set PR_INSTALL=%SERVICE_HOME%\server\SolrService.exe
#REM Service Log Configuration
set PR_LOGPREFIX=%SERVICE_NAME%
set PR_LOGPATH=%SERVICE_HOME%\logs
set PR_STDOUTPUT=auto
set PR_STDERROR=auto
set PR_LOGLEVEL=Debug
set PR_STARTUP=auto
set PR_STARTMODE=exe
set PR_STARTIMAGE=%SERVICE_HOME%\bin\solr.cmd
set PR_STARTPARAMS=start
#REM Shutdown Configuration
set PR_STOPMODE=exe
set PR_STOPIMAGE=%SERVICE_HOME%\bin\solr.cmd
set DSTOP.PORT=8983
set PR_STOPPARAMS="stop -p 8983 -k solrrocks"
%PR_INSTALL% //IS/%SERVICE_NAME% ^
--Description="Solr-5.2.1 Search Tool for Application" ^
--DisplayName="%SERVICE_NAME%" ^
--Install="%PR_INSTALL%" ^
--Startup="%PR_STARTUP%" ^
--LogPath="%PR_LOGPATH%" ^
--LogPrefix="%PR_LOGPREFIX%" ^
--LogLevel="%PR_LOGLEVEL%" ^
--StdOutput="%PR_STDOUTPUT%" ^
--StdError="%PR_STDERROR%" ^
--StartMode="%PR_STARTMODE%" ^
--StartImage="%PR_STARTIMAGE%" ^
--StartParams="%PR_STARTPARAMS%" ^
--StopMode="%PR_STOPMODE%" ^
--StopImage="%PR_STOPIMAGE%" ^
--StopParams="%PR_STOPPARAMS%"
if not errorlevel 1 goto installed
echo Failed to install "%SERVICE_NAME%" service. Refer to log in %PR_LOGPATH%
exit /B 1
:installed
echo The Service "%SERVICE_NAME%" has been installed
exit /B 0
Used NSSM to resolve the issue and manage the windows service
https://nssm.cc/
Made a batch file that contains the following information (run from the same location as your NSSM.exe)
nssm install D:\Search\bin\solr.cmd
nssm set AppDirectory D:\search\bin
nssm set AppParameters "start -f -p 8983
nssm set Description "Solr Search Engine Windows Service"
That will create a windows service that should start and stop correctly

Running batch file from scheduled task on windows server 2012 won't write to disc

I wrote a short batch file for restarting two services every night and write some lines to a txt-file in the same folder. According to the history of the scheduled task the task ran succesfully, but the txt-file is not created.
At first I thought this was beacause of permissions, but when I escalated the permissions of the user running the task to max on both the batch file and the folder, the result stayed the same.
If I run the batch-file manually it does what it's supposed to do.
What am I missing here?
Source:
#echo off
set now=%date:~6,4%%date:~3,2%%date:~0,2%
#echo. >>servicerestartlog.txt
#echo.%now% >>servicerestartlog.txt
net stop "IntegratorService"
IF ERRORLEVEL 0 #echo STOP INTEGRATOR SUCCESS>>servicerestartlog.txt
IF NOT ERRORLEVEL 0 #echo STOP INTEGRATOR FAILED>>servicerestartlog.txt
net stop "SchedulerService"
IF ERRORLEVEL 0 #echo STOP SCHEDULER SUCCESS>>servicerestartlog.txt
IF NOT ERRORLEVEL 0 #echo STOP SCHEDULER FAILED>>servicerestartlog.txt
net start "IntegratorService"
IF ERRORLEVEL 0 #echo START INTEGRATOR SUCCESS>>servicerestartlog.txt
IF NOT ERRORLEVEL 0 #echo START INTEGRATOR FAILED>>servicerestartlog.txt
net start "SchedulerService"
IF ERRORLEVEL 0 #echo START SCHEDULER SUCCESS>>servicerestartlog.txt
IF NOT ERRORLEVEL 0 #echo START SCHEDULER FAILED>>servicerestartlog.txt
exit
Solution that worked for me:
In addition to the path to the script I wanted to run I had to add the folder the script was supposed to start in. This can be set in the Start in (optional) - textbox under edit action. Seems it's not so optional after all...

Vmware commands executing batch file

net use x: "\\vmware-host\Shared Folders\ShareME">>logfile.txt 2>&1
ping -n 11 127.0.0.1 > nul
x:
cd "Firefox18"
call autorun.bat>>logfile.txt
cd ../
exit
When I execute the above batch file by double clicking, logfile.txt is generated. But when I use vmrun -T ws -gu <Username> -gp <Password> runProgramInGuest <Vm-Path> <path of Batch File to execute> The scripts runs fine, only the logfile.txt is not generated.
This happens only in windows 7. It works fine for Windows XP.
The problem solved I just needed >>"C:\Users\Ebryx 2\Desktop\logfile.txt" 2>&1
The quotation mark for the path seemed to work for windows 7.

Issue with numbering script

I'm trying to create one of my first ever DOS script (more used to bash).
I'm trying to create a script that would rename my pics using a sequential number and the year as a prefix. I created this script :
#ECHO OFF
setlocal EnableDelayedExpansion
echo.
SET /P Year=Please enter Year (YYYY) :
SET /P Start=Starting Number :
dir
set /A i=%Start%
for %%f in (*.JPG) do call :renameit "%%f"
goto done
:renameit
echo %1 %i%
set str=%i%
set str=0000!str:.=!
set str=!str:~-4!
ren %1 PICT_%Year%_%str%.JPG
set /A i+=1
:done
Issue is that it sometimes works fine, sometimes goes through one additional look renaming back a file that was already renamed. Here are 2 examples (as you can see, I added a DIR and ECHO in the script above for troubleshooting) :
RUN 1 (CORRECT) :
Directory of C:\TEST
07/01/2013 10:55 <DIR> .
07/01/2013 10:55 <DIR> ..
04/08/2011 14:28 16.823 PICT_2012_0005.JPG
04/08/2011 14:28 16.823 PICT_2012_0006.JPG
04/08/2011 14:28 16.823 PICT_2012_0007.JPG
07/01/2013 10:56 368 script.cmd
4 File(s) 50.837 bytes
2 Dir(s) 30.342.901.760 bytes free
"PICT_2012_0005.JPG" 5
"PICT_2012_0006.JPG" 6
"PICT_2012_0007.JPG" 7
RUN 2 (FAILED) :
Directory of C:\TEST
07/01/2013 10:56 <DIR> .
07/01/2013 10:56 <DIR> ..
04/08/2011 14:28 16.823 PICT_2011_0005.JPG
04/08/2011 14:28 16.823 PICT_2011_0006.JPG
04/08/2011 14:28 16.823 PICT_2011_0007.JPG
07/01/2013 10:56 368 script.cmd
4 File(s) 50.837 bytes
2 Dir(s) 30.342.901.760 bytes free
"PICT_2011_0005.JPG" 5
"PICT_2011_0006.JPG" 6
"PICT_2011_0007.JPG" 7
"PICT_2012_0005.JPG" 8
Any idea what I'm doing wrong ?
Thanks
Expanded Comment into a full answer.
It is a known feature/issue/undefined behavior of the for command. When looping through a directory of files and making modification to those files, the for loop does not keep a static list of files in the folder. Instead it just checks for the next file until nothing is returned from the file system. However, when modifying files in the loop, the file system sees the modification as an additional file and it gets sent again to the for loop. This will cause an unknown number (based upon the race condition of the for loop and file system) of files to be reprocessed.
See this forum for an in depth discussion about it.
http://www.dostips.com/forum/viewtopic.php?f=3&t=4138&sid=463cb91964f497c478afcca79c33384a
You can alternatively use this for statement: for /F "delims=" %%F in ('dir /B *.jpg') do call :renameit "%%~fF"
The dir command will generate a static list of the files in the directory at its run time preventing the recursion of files.

Resources