Search code examples
javawindowsserviceglassfish

How to start Glassfish service in Windows using batch file that will pause execution untill domain is started?


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?


Solution

  • 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
    )