At this moment I am using command below as a part of my batch script to boot domain1:
asadmin start-domain domain1
however I have recently installed domain1 as a service so now when I use this command the domain is starting under my user process instead of booting as a service. So after I logout, the domain is gone. I used:
net start domain1
and
sc start domain1
However both of these seem to return as soon as signal[or whatever else] is dispatched toward service, and they do not wait untill domain1 is actually started. "asadmin start-domain" did return after it started the domain...
I have to wait as in my script I am undeploying/deploying new app shortly after domain start. So is there any way to start Glassfish as service using batch command and wait untill it is started?
Install:
sc create ServiveName binpath= <PATH_TO_SERVICE>.exe
net start ServiveName
PAUSE
Start:
net start ServiceName
PAUSE
Stop:
net stop ServiceName
PAUSE
Uninstall:
net stop ServiceName
sc delete ServiceName
PAUSE
One of the solutions I am using:
@echo off
SETLOCAL enableextensions enabledelayedexpansion
set GLASSFISH_HOME=c:\glassfish
set DOMAIN=domain1
net start %DOMAIN%
:loop
call timeout /t 1 /NOBREAK > NUL
echo Still waiting for domain to start
for /f "tokens=1,2 delims= " %%A IN ( '"%GLASSFISH_HOME%\bin\asadmin.bat" list-domains' ) DO IF "%%A"=="%DOMAIN%" SET GLASSFISH_RUNNING=%%B
if not "%GLASSFISH_RUNNING%"=="running" (
goto loop
)
I modified the above version a little bit for better understanding:
@echo off
SETLOCAL enableextensions enabledelayedexpansion
set GLASSFISH_HOME=D:\glassfish
set DOMAIN=domainName
set SERVICE_NAME="name of your service"
net start %SERVICE_NAME%
:loop
call timeout /t 1 /NOBREAK > NUL
echo Still waiting for domain to start
for /f "tokens=1,2 delims= " %%A IN ( '"%GLASSFISH_HOME%\bin\asadmin.bat" list-domains' ) DO IF "%%A"=="%DOMAIN%" SET GLASSFISH_RUNNING=%%B
if not "%GLASSFISH_RUNNING%"=="running" (
goto loop
)
Some applicatios already provide possiblities to automatically create Windows services. However every .exe can be configured this way.
GUI: http://www.sevenforums.com/tutorials/2495-services-start-disable.html
Console: https://support.microsoft.com/de-de/kb/137890
Automatic startup before logon: https://serverfault.com/questions/227862/run-a-program-without-user-being-logged-on
Type the following code in notepad and save [name].bat (for windows)
cd C:\\glassfish3\\glassfish3\\bin asadmin start-domain PAUSE
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.