I am trying to automate my maven build and deployment process of the EAR in Jboss. I managed to write a bat file for the same which is given below.
ECHO OFF
RMDIR /S /Q .\deploy
call mvn clean install -D build=P,JB
call mvn clean install -D build=F,JB
#echo | call C:\Work\jboss-as-7.1.1.Final\bin\jboss-cli.bat --connect --controller=[my-machine-name]:9999 command=:shutdown
del /q C:\Work\jboss-as-7.1.1.Final\standalone\deployments\*.*
xcopy /s /y .\deploy\function\Jboss\*.ear C:\Work\jboss-as-7.1.1.Final\standalone\deployments
xcopy /s /y .\deploy\WorkFlowEngine\Jboss\*.ear C:\Work\jboss-as-7.1.1.Final\standalone\deployments
cd C:\Work\jboss-as-7.1.1.Final\bin
rmdir "C:\work\jboss-as-7.1.1.Final\standalone\data" /s /q
rmdir "C:\work\jboss-as-7.1.1.Final\standalone\log" /s /q
rmdir "C:\work\jboss-as-7.1.1.Final\standalone\tmp" /s /q
standalone.bat -bmanagement [my-machine-name] -b [my-machine-name] -c standalone-full-ha.xml
{code for check of deployment success/failure}
PAUSE
Here you can see that I am using the line
standalone.bat -bmanagement sbstjwsvm1509 -b sbstjwsvm1509 -c standalone-full-ha.xml
My requirement is that I want to check if the EAR was deployed successfully from my bat file.One way which I thought of is to check for .deplyed or .failed extension files in the Jboss deployment folder.I tried to write codes for the same but my code which is written below the above mentioned line is not getting executed.Is there any other means by which I can achieve this?Or what am I doing wrong in my bat file?Why is my code to check for deployment not getting executed?
Because the standalone.bat isn't executing in background and will be running the JBoss instance until you kill/stop it (ctrl+C signal or like you shutdown through jboss CLI). See this answer to get examples and details about you want to achive.
Since you are using maven, I suggest you to use jboss-as-maven-plugin.
Take a look the Usages, you will find commands to deploy/undeploy applications, resources, and to start/stop the server.
Then you could integrate the plugin execution to stop/clean in the maven clean phase and deploy/start on maven install phase using goals. See complex examples.
Thought of posting my solution here.
ECHO OFF
SET "JBOSS_DIR=C:\Work\jboss-as-7.1.1.Final"
SET "deployedAPP=MyApp.ear"
RMDIR /S /Q .\deploy
call mvn clean install -D build=P,JB
call mvn clean install -D build=F,JB
#echo | call %JBOSS_DIR%\bin\jboss-cli.bat --connect --controller=[mymachine_name]:9999 command=:shutdown
del /q %JBOSS_DIR%\standalone\deployments\*.*
xcopy /s /y .\deploy\function\Jboss\*.ear %JBOSS_DIR%\standalone\deployments
xcopy /s /y .\deploy\WorkFlowEngine\Jboss\*.ear %JBOSS_DIR%\standalone\deployments
cd %JBOSS_DIR%\bin
PING -n 61 -w 1 localhost >nul
START CMD /C CALL MyJboss.bat
SET count=0
:checkIfDeployed
if exist "%JBOSS_DIR%\standalone\deployments\%deployedAPP%.deployed" (
GOTO appDeployed
)
if exist "%JBOSS_DIR%\standalone\deployments\%deployedAPP%.failed" (
GOTO deployFailed
)
PING -n 6 -w 1 localhost >nul
GOTO checkIfDeployed
:appDeployed
PAUSE
EXIT
:deployFailed
SET /A count+=1
if %count% == 5 ( goto end )
#echo | call %JBOSS_DIR%\bin\jboss-cli.bat --connect --controller=[mymachine_name]:9999 command=:shutdown
PING -n 61 -w 1 localhost >nul
START CMD /C CALL MyJboss.bat
GOTO checkIfDeployed
:end
PAUSE
Used the line
START CMD /C CALL MyJboss.bat
to start JBoss in another cmd window.Now all my codes from below will get executed.
Related
I'm trying to execute a batch file but its console is not stopping for its output.
here's the code:
goto D:
cd postgresql-9.6.0-1-windows-x64-binaries
cd pgsql
cd bin
start pg_ctl start -D D:\pg_data\data
#echo on
echo server started
pause
I am assuming it is on the D: drive. use cd /d see cd /? for the reason why.
#echo off
cd /d "D:\postgresql-9.6.0-1-windows-x64-binaries\pgsql\bin"
start "" "pg_ctl" start -D "D:\pg_data\data"
echo server started
pause
change to start "" /wait if you want to wait for the service to start before you echo it has been started.
I am very new to .bat files. I am making a bat file to install all the programs we need at our company. One issue I am running into - I worked with Microsoft to create an msi file to install Office 365 however I would like this the line where it is installing Office 365 to wait till the install is finished before it moves onto the next line in the bat file. What should I be typing for that. Below is the first part of the bat file and you can see that the 2nd to last line is where I am installing office. This sometimes works and sometimes does not.
Any help please?
%windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f
"\\nas\install\IBM\Client Access\VR7_1\Windows\image64a\setup.exe" /s /v"/qn /norestart ADDLOCAL=afp,scs,req,inavbo,dt,dtexcel,odbc,emu"
msiexec /i "\\nas\install\ADOBE\Adobe STD X USE\Setup\AcroStan.msi" TRANSFORMS=AcroStan.mst /qb
msiexec /i "\\nas\install\MICROSOFT\Office 365 ProPlus\NewInstallMSI\OfficeProPlus64Bit.msi" /qb
Dism /online /enable-feature /featurename:NetFX3 /All /Source:"\\nas\install\MICROSOFT\Windows 10\Win10ENT\sources\sxs" /LimitAccess
I suppose start "" /wait is your best option here. I do not have all your commands, so you would need to test this:
start "" /wait "%windir%\System32\reg.exe" ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f
start "" /wait "\\nas\install\IBM\Client Access\VR7_1\Windows\image64a\setup.exe" /s /v"/qn /norestart ADDLOCAL=afp,scs,req,inavbo,dt,dtexcel,odbc,emu"
start "" /wait "msiexec" /i "\\nas\install\ADOBE\Adobe STD X USE\Setup\AcroStan.msi" TRANSFORMS=AcroStan.mst /qb
start "" /wait "msiexec" /i "\\nas\install\MICROSOFT\Office 365 ProPlus\NewInstallMSI\OfficeProPlus64Bit.msi" /qb
start "" /wait "Dism" /online /enable-feature /featurename:NetFX3 /All /Source:"\\nas\install\MICROSOFT\Windows 10\Win10ENT\sources\sxs" /LimitAccess
Cd /d "D:\Test"
START mvn clean install -DskipTests
xcopy /s "D:\Test\brsint-web\brsint-webapp\target\Test.war" "D:\apache-tomcat-7.0_1.2Latest (2)\webapps" /Y
Cd /d "D:\apache-tomcat-7.0_1.2Latest (2)\bin"
START startup.bat
I am trying to write a bat file which has series of actions I wanted to perform. I want to trigger 3rd line after 2nd line execution. 2nd line is a maven build which generates war file it takes time to complete. Mean while 3rd line i.e., copy command is getting executed before War file is generated. Please help me resolve.
Trying to maintain the structure you had as best as possible, I would suggest perhaps this:
CD /D "D:\Test"
(Call mvn clean install -DskipTests) || GoTo :EOF
XCopy "D:\Test\brsint-web\brsint-webapp\target\Test.war" "D:\apache-tomcat-7.0_1.2Latest (2)\webapps" /S /Y
CD "D:\apache-tomcat-7.0_1.2Latest (2)\bin"
Call "startup.bat"
If the mvn command is not successful the script will end at that point!
You can use the /Wait or /W flag after the Start Command. This will spawn the process and wait for a Return or Exit code before continuing.
e.g.
Cd /d "D:\Test"
START /wait mvn clean install -DskipTests
xcopy /s "D:\Test\brsint-web\brsint-webapp\target\Test.war" "D:\apache-tomcat-7.0_1.2Latest (2)\webapps" /Y
Cd /d "D:\apache-tomcat-7.0_1.2Latest (2)\bin"
START /wait startup.bat
I have been banging my head with this small script to search a delete a file from the remote host. However, I have been able to write to seperate scripts, both to delete and to find a file.
However, now I am trying to merge both and I am unable to use the for loop in the same line as the line which searches the file.
Psexec #IPlist.txt -u ad -p P#$$vv0rCL cmd /c (^WHERE /r D:\ %file%>res.txt
the above line helps to search the file, and below does the deletion part.
del /f /A:H /S /Q "D:\1\e.txt"
Now, since I want to delete all the files, found and stored in rex.txt, I need to run a for loop on this file.
Here is what I am trying to do
Psexec #IPlist.txt -u ad -p P#$$vv0rCL cmd /c (^WHERE /r D:\ %file%>res.txt ^& FOR /f "delims=" %%X IN (res.txt) DO ( del /f /A:H /S /Q "D:\1\e.txt")
but this gives error cmd exit with error code 1, and if I take for loop on next line, then the code doesn't work on remote pc.
Can some one guide please?
escape the ) in (res.txt) as ^)
I have a .bat that I've wrote to automate an install of a piece of software I have to install all the time at work. (I can't use powershell because a lot of the machines are XP still)
Near the end, the script is supposed to clean itself up and and logout, but I can't get it to log out for some reason.
taskkill /f /im explorer.exe>nul 2>&1
set _sd=%~dp0
cd /d c:\
del "%_sd%md5sum.exe"
...
del "%_sd%RUN-AS-ADMIN.bat"
wait 2
shutdown -f -l
There is no wait command in CMD. There is timeout for Win7+ but not for XP. To implement a kind of a timeout you'll have to use for example ping 127.0.0.1 -n 6 > nul. This will make your system "wait" for 5 seconds. You can modify the timeout by replacing 6 with any other value. If you want a timeout of X seconds, replace 6 with X+1.
EDIT: Made a stupid mistake making this, fixed it up.
Try this instead:
taskkill /f /im explorer.exe>nul 2>&1
set _sd=%~dp0
cd /d c:\
del "%_sd%md5sum.exe"
...
del "%_sd%RUN-AS-ADMIN.bat"
pause
shutdown -f -l
All I did was make it so that the wait is replaced with pause
I did some looking around, and I couldn't find any native commands that make the batch file delay and automatically continue, so this is the closest I can find. (Assuming the computer you're using this on is a Windows XP)
If you don't use a Windows XP for the batch file, use this instead:
taskkill /f /im explorer.exe>nul 2>&1
set _sd=%~dp0
cd /d c:\
del "%_sd%md5sum.exe"
...
del "%_sd%RUN-AS-ADMIN.bat"
timeout /t 2 >nul
shutdown -f -l
The timeout acts as a delay, however, it is unfortunately not a native command on Windows XP, but it is on Windows 7+ (Unsure about vista)
Hope this helps :)