Solr Windows Service won't stop - solr

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

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?

Can't use nssm set command in batch script

When using this command in my batch script the set command is interpreted as the default windows batch "set an environment command":
#echo off
echo "Always run this script as Administrator. If you don't the service will be installed but not correctly configured!"
set serviceName=MyApp
set serviceLabel=MyApp
set serviceExe=MyApp.exe
set maindir=C:\\Users\\MyUser\\Desktop\\MyApp\\
set nssm=%maindir%\\lib\\nssm-2.24\\win64\\nssm.exe
%nssm% install %serviceName% "%maindir%\\%serviceExe%"
How do I prevent this?
An example, based upon my comment:
#Echo Off
Set "serviceName=MyApp"
Set "serviceExe=MyApp.exe"
Set "maindir=C:\\Users\\MyUser\\Desktop\\MyApp"
Set "nssm=%maindir%\\lib\\nssm-2.24\\win64\\nssm.exe"
"%nssm:\\=\%" install %serviceName% "%maindir%\\%serviceExe%"
Figured it out:
In my original script i had the nssm exe as a variable:
%nssm% set %serviceName% AppDirectory "%maindir%"
Somehow this confuses the script.
Just use an actual path to nssm.exe and it works:
.\nssm.exe set %serviceName% AppDirectory "%maindir%"

Batch script: goto was unexpected. using find xyz file.log && goto pass || goto fail

I have a very weird error from my batch script.
Although the code uses Android Debugging Bridge, I'm sure it's an error related to cmd as opposed to adb.
So, basically if anyone cares, the script just checks root access. Here's a sniplet of the code:
#echo off
adb kill-server
adb start-server
adb shell "su" >check.log 2>&1
adb kill-server
"%windir%\system32\find.exe" "#" check.log && goto pass || goto fail
:fail
echo No root access!
pause
:pass
echo Root access detected!
pause
The output for this is:
* daemon not running. starting it now on port XXXX *
* daemon started successfully *
* server not running *
---------- CHECK.LOG
goto was unexpected at this time
And the window closes automatically.
If I run it in a command window by manually typing the commands, this is what I get:
J:\tools>adb kill-server
J:\tools>adb start-server
* daemon not running. starting it now on port XXXX *
* daemon started successfully *
J:\tools>adb shell su >check.log 2>&1
J:\tools>"%windir%\system32\find.exe" "#" check.log && echo pass || echo fail
---------- CHECK.LOG
fail
Can anyone think of a solution? I tried to do it like this:
#echo off
adb kill-server
adb start-server
adb shell "su" >check.log 2>&1
adb kill-server
SET tr=0
"%windir%\system32\find.exe" "#" check.log >nul && SET tr=1 || SET tr=0
if "%tr%"=="1" goto pass
if "%tr%"=="0" goto fail
I still get the error for goto. :/
I'm puzzled, I have used other such statements before.
Thanks for reading through! :)
Oh, system32 is sometimes not present in path & as this is being made for others to use, I need to use %windir%\system32\
I ran your find line and it worked fine for me. Try using %errorlevel% as a workaround, which also works fine on my pc
find "#" check.log
if %errorlevel%==0 goto pass
if %errorlevel%==1 goto fail
Note: You don't need to specify the full path to find, as system32 is in the PATH variable.
Hope this helps!

dos batch script using psexec shows 'help' text every time it loops

Currently working on a script to ping every host on a /24 subnet, and then executes another script which runs psexec on those machines which are online. The ping sweep script is called ping.bat and the other script which actually runs psexec on the machines is called deploy_mir.bat. I can simply run deploy_mir.bat on a remote host and it will run no problem.
The problem im having is that every time mir.bat runs, which itself contains a loop, it will display the help info for psexec in the cmd window. As far as i can tell everything is working fine, aside from the annoying fact that everytime the loop inside of mir.bat runs my cmd window gets filled with the help info for psexec. I dont have #echo enabled, not that it would cause this anyway.
hoping for a quick fix, but if my code is needed to get an answer ill post it.
Posting the code anyway...
#echo on
setlocal EnableDelayedExpansion
set /p ipAddress="enter ip address: "
for /l %%i in (1,1,255) do (
ping -n 1 %ipAddress%.%%i | find "TTL" > nul
if !errorlevel! == 0 (
call deploy_mir.bat %ipAddress%.%%i
)
)
endlocal
deploy_mir.bat code
#ECHO OFF
echo "Mir Agent deployment to: %1"
rem net use T: \\%1\C$ /user:administrator "password"
net use T: \\%1\C$ /user:administrator "username"
copy /y conf.xml T:\WINDOWS\
copy /y setup_mir.bat T:\WINDOWS\
net use t: /delete
rem psexec \\%1 -i -u administrator -p "password" c:\windows\setup_mir.bat
psexec \\%1 -i -u administrator -p "username" c:\windows\setup_mir.bat
Desired cmd line result of running deploy_mir.bat
C:\DOCUME~1\socuser2\MIR>deploy_mir.bat 10.180.145.66
"Mir Agent deployment to: 10.180.145.66"
The command completed successfully.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
t: was deleted successfully.
PsExec v1.94 - Execute processes remotely
Copyright (C) 2001-2008 Mark Russinovich
Sysinternals - www.sysinternals.com
c:\windows\setup_mir.bat exited on 10.180.145.66 with error code 0.
C:\DOCUME~1\socuser2\MIR>
Just a suggestion. Not sure if it will solve your problem, but may provide some guidance:
My first step would be a small test by explicitly calling psexec on some test batch file in place of the line call deploy_mir.bat %ipAddress%.%%i. If no help message appears, since deploy_mir.bat works find on its own, try explicitly placing it's content in place of the same line call deploy_mir.bat %ipAddress%.%%i. If that works, then there is some issue in the said line we've been replacing. I believe dos / batch will open a sub shell from this line of code and run it's code in that scope. That may be causing the problem. Just guessing with the information provided.
Code Specific Notes:
#echo is enabled, but you say it is not in your question.
!errorlevel! == 0 should be !errorlevel! EQU 0
Some General Notes:
In general, I used to pass parameters to batch scripts in quotes, then strip the quotes with %~1 once inside the batch script. Similarly for if conditions, as !someVar! == a will throw and error if someVar is not set / empty, while "!someVar!" == "a" will gracefully not meet the criteria of the if condition.
I don't know why it works when called from outside the loop. But the psexec line in deploy_mir.bat should have cmd /c.
psexec \\%1 -i -u administrator -p "username" cmd /c c:\windows\setup_mir.bat

bat file to uninstall an installed application

I am using the following bat file to install my application on a user computer. However, the client want to be able uninstall the application if the application is installed, and then install the new version of the application.
However, I have 2 problems.
1) how can I detect if the application is installed or not?
2) If it is installed, how can I uninstall it?
The application is a C# 2005.
#ECHO OFF
:: Copy the configuration file
copy config.xml "%AppData%\DataLinks.xml"
:: Search for the CONFIG file, if this doesn't exit then the user doesn't have the .Net framework 2.0
SET FileName=%windir%\Microsoft.NET\Framework\v2.0.50727\CONFIG
IF EXIST %FileName% GOTO INSTALL_DIALER
ECHO.You currently do not have the Microsoft(c) .NET Framework 2.0 installed.
ECHO.This is required by the setup program for CAT Dialer
ECHO.
ECHO.The Microsoft(c) .NET Framework 2.0 will now be installed on you system.
ECHO.After completion setup will continue to install CAT Dialer on your system.
ECHO.
:: Install the .Net framework and then run setup to install the CAT Dialerr
PAUSE
ECHO Installing... this could take several minutes...Please wait....
START /WAIT NetFx20SP2_x86.exe
:: If the user cancels the installation of the framework exit batch file
IF errorlevel 1 GOTO EOF
Start CATSoftphone.exe
ECHO ON
EXIT
:: .Net framework has been skipped contine to install the dialer.
:INSTALL_DIALER
ECHO *** Skiped Dotnet Framework 2.0.50727 ***
ECHO Installing... Please wait...
START CATSoftphone.exe
ECHO ON
EXIT
Edit ==============================
<job id="ReInstall">
<script language="VBScript">
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
oExec = WshShell.Run("msiexec /uninstall {2E92DD55-37E9-4D6C-B55B-DAFD9DF583E2}" , 1 , true )
If oExec = 0 OR oExec = 1605 Then
oExec = WshShell.Run("InstallUninstallBat.msi")
End If
</script>
</job>
You might be better off using the popular (free) NSIS installer platform, rather than using batch scripts. It's possible to do all the same things you're doing with it and building an uninstaller is much easier.
Here at my company the same request is corresponded with a VB script which is something like:
<job id="ReInstallblabla">
<script language="VBScript">
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
oExec = WshShell.Run("msiexec /uninstall {3D96B234-EB0C-4AC3-89EC-E5CAB9AEC432}" , 1 , true )
If oExec = 0 OR oExec = 1605 Then
oExec = WshShell.Run("blabla_setup.msi")
End If
</script>
</job>
If you are able to create a deployment project for your application, it is going to have a ProductCode which you may pass as parameter to msiexec. Return value of 0 means uninstall is successfull, 1605 means no installation with the given ProductCode is found.
Hope it helps.

Resources