简体   繁体   English

如何使用将暂停执行直到域启动的批处理文件在 Windows 中启动 Glassfish 服务?

[英]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:此时我正在使用下面的命令作为我的批处理脚本的一部分来引导 domain1:

asadmin start-domain domain1 asadmin 起始域 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.但是我最近将 domain1 作为服务安装,所以现在当我使用这个命令时,域是在我的用户进程下启动的,而不是作为服务启动。 So after I logout, the domain is gone.所以在我注销后,域就消失了。 I used:我用了:

net start domain1净启动域1

and

sc start domain1 sc 起始域 1

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.然而,一旦信号[或其他任何东西]被派往服务,这两个似乎都会返回,并且它们不会等到域1实际启动。 "asadmin start-domain" did return after it started the domain... “asadmin start-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?那么有没有办法使用批处理命令将 Glassfish 作为服务启动并等待它启动?

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.一些应用程序已经提供了自动创建 Windows 服务的可能性。 However every .exe can be configured this way.但是,每个 .exe 都可以通过这种方式进行配置。

GUI: http://www.sevenforums.com/tutorials/2495-services-start-disable.html图形用户界面: http : //www.sevenforums.com/tutorials/2495-services-start-disable.html
Console: https://support.microsoft.com/de-de/kb/137890控制台: 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登录前自动启动: 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)在记事本中输入以下代码并保存 [name].bat(对于 Windows)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM