0

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?

Kaszaq
  • 997
  • 10
  • 16

4 Answers4

0

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
Ross Bush
  • 14,648
  • 2
  • 32
  • 55
  • Thanks, but thats not really what I need. I need to wait untill domain1 is started, not only the service. You see, the service is started before domain is started. After I start service it takes some time after domain is actually started. Unfortunetly using sc start or net start does not wait untill domain is started contrary to asadmin command. I am thinking about using a loop after sc start to check if domain is started. – Kaszaq Nov 02 '13 at 22:41
0

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
)
Kaszaq
  • 997
  • 10
  • 16
  • Yes this approach would work. Another approach would be to write some Java or Groovy to leverage the Glassfish REST management API to check on the domain status and deploy etc. – NBW Nov 04 '13 at 11:57
0

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

Community
  • 1
  • 1
Dr4gon
  • 421
  • 8
  • 17
0

Type the following code in notepad and save [name].bat (for windows)

cd C:\glassfish3\glassfish3\bin asadmin start-domain PAUSE