@echo off ::################################################################################################################################## ::# ::# batchsrv.cmd ::# ::# Description : Manages the X3 batch server (starts, stops and checks) including any batch task for Sage products ::# using the X3 technology from v130 to v7. ::# ::# Last date : 18/05/2015 ::# ::# Version : WINDOWS - 1.11 ::# ::# Author : F.SUSSAN / SAGE Enterprise Market Europe ::# ::# Syntax : batchsrv [ | | | ] ... ::# ::# = status : Checks status of the batch server (default value) ::# stop : stops the batch server ::# start : starts the batch server ::# kill : kills only running tasks ::# killstop : kills running tasks and stops the batch server ::# restart : stops and starts the batch server ::# ::# = CON : redirects the standard output to the console (default option) ::# NUL : redirects nothing ::# FIL : redirects to a trace file (%TMPDIR%\batchsrv.log) ::# SIL : redirects to a trace file in silent mode ::# ::# = X3 folder existing for the Sage X3 Solution ::# ::# = X3 batch task running for the Sage X3 Solution ::# ::# Notes : - You can get Exit status returned from this script by using the errorlevel code. ::# - When you are running on Windows Server 2008, you must run this script "as administrator" by running ::# a scheduled task with two options: "Run whether user is logged on or not" and "highest privileges". ::# - In addition, it is recommended to run this script with the account which starts the Windows ::# service for the X3 solution. ::# - With a v7 Sage X3 product, if the folder directory is not located on the same relative path than runtime ::# you must set manually the ADXDOS variable. ::# ::# Examples : batchsrv ::# Checks the X3 batch server activity [SERVX3] for the Sage X3 Solution identified in settings. ::# batchsrv restart FIL ::# Restarts the X3 batch server ("killstop" + "start" options) for the Sage X3 Solution identified in settings ::# and generates a result trace file [%TMPDIR%\batchsrv.log]. ::# batchsrv killstop ::# Kills any batch task running in all existing folders and stops the batch server for the Sage X3 Solution identified in settings. ::# batchsrv kill DEMO ::# Kills any batch task running from the folder [DEMO] for the Sage X3 Solution identified in settings. ::# batchsrv kill DEMO ACCENTRY0 ::# Kills the accounting batch tasks [ACCENTRY0] from the folder [DEMO] for the Sage X3 Solution identified in settings. ::# ::# Exit status : = 0 : OK ::# = 1 : !! ERROR !! ::# = 2 : ** WARN ** ::# ::# Copyright © 2011-2015 by Sage Group - All Rights Reserved. ::# ::################################################################################################################################## ::# ::# Modifications history ::# -------------------------------------------------------------------------------------------------------------------------------- ::# ! Date ! Version ! Author ! Description ::# !------------+---------+--------------+----------------------------------------------------------------------------------------- ::# ! Date ! Version ! Author ! Description ::# !------------+---------+--------------+----------------------------------------------------------------------------------------- ::# ! 14/02/2011 ! 1.02 ! F.SUSSAN ! Status based of the existence of processes ::# !------------+---------+--------------+----------------------------------------------------------------------------------------- ::# ! 17/02/2011 ! 1.03 ! F.SUSSAN ! Correction if env file patch is incorrect ::# ! ! ! ! Correction wait loop for batch server startup ::# ! ! ! ! Option -o for psadx is no more active in V6 ::# ! ! ! ! Redirect standard OUTPUT : con, nul or fictrace ::# !------------+---------+--------------+----------------------------------------------------------------------------------------- ::# ! 14/03/2011 ! 1.04 ! A.PELTIER ! Correction for the ABEL case %DOSS_REF% replaced ::# ! ! ! ! by %BATCH_FOLDER% as a variable to initialize ::# !------------+---------+--------------+----------------------------------------------------------------------------------------- ::# ! 01/04/2011 ! 1.05 ! F.SUSSAN ! Change to initialize the %BATCH_FOLDER% ::# ! ! ! ! New option to use : restart ::# !------------+---------+--------------+----------------------------------------------------------------------------------------- ::# ! 17/07/2012 ! 1.06 ! F.SUSSAN ! Compatibility ensured from the V130 to V6 version. ::# !------------+---------+--------------+----------------------------------------------------------------------------------------- ::# ! 24/09/2012 ! 1.07 ! F.SUSSAN ! Change of the name of the X3 batch server ::# ! ! ! ! directory called "SERVPAIE" in RHV6. ::# !------------+---------+--------------+----------------------------------------------------------------------------------------- ::# ! 18/05/2013 ! 1.08 ! F.SUSSAN ! Correction for the "restart" option. ::# ! ! ! ! New variable to initialize : OUTPUT=CON, NUL or FIC. ::# !------------+---------+--------------+----------------------------------------------------------------------------------------- ::# ! 29/05/2013 ! 1.09 ! F.SUSSAN ! - The program can be now executed without need to fix the variables ::# ! ! ! ! which can also be initialized by passing arguments to program. ::# ! ! ! ! - Correction when the port number of the Batch server X3 did not match ::# ! ! ! ! that of the X3 solution (Ex:-20). ::# ! ! ! ! - Displays only the list of existing X3 folders and containing no ::# ! ! ! ! extra character in the directory name associated (.,-). ::# ! ! ! ! - Displays an additional message when the time-out is expired. ::# ! ! ! ! - Displays the accounting task if existing and running for each folder. ::# !------------+---------+--------------+----------------------------------------------------------------------------------------- ::# ! 17/11/2014 ! 1.09a ! B.LETEMPLIER ! - A few comment errors corrected ::# ! ! ! ! - Some issues with call :Banner solved ::# ! ! ! ! - Add a 'SIL' option that creates log file but does not display anything ::# !------------+---------+--------------+----------------------------------------------------------------------------------------- ::# ! 19/12/2014 ! 1.10 ! F.SUSSAN ! - New compatibility ensured in V7 version : the file "adxvolumes", ::# ! ! ! ! located under the runtime directory, is no longer exists. ::# ! ! ! ! - Calls new functions for a better readability of the program. ::# ! ! ! ! - Supports any batch task running on folders by the X3 batch server. ::# ! ! ! ! - Lists all running batch tasks for each folder based on the presence ::# ! ! ! ! of a run file in the FIL directory of the folder. ::# ! ! ! ! - If multiple instances of a same batch task are running with a different ::# ! ! ! ! parameter (e.g. INTERFACE with AJM for GEODE), the task name is ::# ! ! ! ! identified as follows: : (e.g. INTERFACE:ITL_AJM). ::# ! ! ! ! - The argument "-y CRYPT:" may be included in the X3 Batch server command. ::# ! ! ! ! - The "restart" option is used without stopping running X3 batch tasks. ::# !------------+---------+--------------+----------------------------------------------------------------------------------------- ::# ! 12/02/2015 ! 1.10a ! F.SUSSAN ! A few minor correction. ::# !------------+---------+--------------+----------------------------------------------------------------------------------------- ::# ! 28/08/2015 ! 1.11 ! F.SUSSAN ! - New compatibility ensured in Update 8 version : the directory for the X3 batch server ::# ! ! ! ! is now located under the directory for x3 folders (e.g. "dossiers\SERVX3"). ::# ! ! ! ! - Adds /V option to display the version number, the last modified date of the program, ::# ! ! ! ! and the list of variables modified & functions defined. ::# ! ! ! ! - Gets the extension of the program in the variable "extname". ::# -------------------------------------------------------------------------------------------------------------------------------- ::################################################################################################################################## setlocal enabledelayedexpansion ::#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!# ::#!!!! OPTIONAL VARIABLES THAT CAN BE USED DEPENDING !!!!# ::#!!!! ON THE CONTEXT OTHERWISE DETECTED BY DEFAULT !!!!# ::#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!# :: Directory where SOLUTION runtime is stored (By default detected in a a relative path where the program is stored under "\runtime\ebin") set ADXDIR= :: Directory where X3 FOLDERS are stored (By default detected depending on the version runtime) set ADXDOS= :: Action used for the X3 batch server management (By default = "STATUS") set ACTION= :: Redirection for the standard output (By default CON=Console else NUL=None, FIL=File trace, SIL=File trace without message) set OUTPUT= :: X3 folder by default for actions on X3 batch tasks (By default all X3 folders existing if null value, else enter the X3 folder name) set X3FOLDER= :: X3 task by default for actions (By default all X3 batch tasks running if null value, else enter an X3 task name) set X3TASK= ::#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!# ::#!!!! END OF IMPLEMENTATION-DEPENDANT VARIABLES !!!!# ::#!!!! DO NOT MAKE ANY CHANGE BELOW THIS PART !!!!# ::#!!!! OR DO IT AT YOUR OWN RISK !!! !!!!# ::#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!# ::#!!!! IF YOU FIND ANY BUG OR POSSIBLE ENHANCEMENT !!!!# ::#!!!! PLEASE REPORT YOUR VENDOR / DISTRIBUTOR. !!!!# ::#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!# :: Initializes variables used in the program call :Init_variables :: Displays the banner program if (%1)==(/?) (call :Banner) else (call :Banner %*) :: Gets options passed in the command line if (%1)==(/?) goto :Usage if (%1)==(/V) goto :Version if not (%5)==() goto :Usage :option if not (%1)==() for /D %%i in (START STOP KILL KILLSTOP RESTART STATUS) do if /I (%1)==(%%i) (set ACTION=%%i) & shift if not (%1)==() for /D %%i in (CON NUL FIL FIC SIL) do if /I (%1)==(%%i) (set OUTPUT=%%i) & shift if not (%1)==() for /D %%i in (ACCENTRY01 INTERFACE) do if /I (%1)==(%%i) (set X3TASK=%%i) & shift if defined ACTION if defined OUTPUT if not (%1)==() if not defined X3FOLDER (set X3FOLDER=%1) & shift if defined ACTION if defined OUTPUT if defined X3FOLDER if not (%1)==() if not defined X3TASK (set X3TASK=%1) & shift if defined ACTION if defined OUTPUT if defined X3TASK if defined X3FOLDER shift if not (%1)==() goto option :: Checks options used in the command line call :Check_options || goto :Usage :: Checks the value for variables that are defined call :Check_variables || goto End :: Initializes files used in the program call :Init_files if (%OUTPUT%)==(FIL) echo The trace file "%file_log%" is being generated... if /I %ACTION%==START call :Start_srvbatch if /I %ACTION%==STOP call :Stop_srvbatch if /I %ACTION%==KILL call :Stop_allbatch if /I %ACTION%==KILLSTOP call :Stop_allbatch if /I %ACTION%==KILLSTOP call :Stop_srvbatch if /I %ACTION%==RESTART call :Restart_srvbatch if /I %ACTION%==STATUS call :Stat_srvbatch :: Checks the result of the SQL script execution call :Status :: End of the program goto End :Init_variables ::#************************************************************# ::# Initializes variables used in the program ::# :: Standard variables set platform=Microsoft Windows Server 2003/2008/2012 set copyright=Copyright {C} 2011-2015 set author=Sage Group for /F "delims=" %%i in ('hostname') do set hostname=%%i for /F "delims=" %%i in ("%~nx0") do set progname=%%~ni for /F "delims=" %%i in ("%~nx0") do set extname=%%~xi set dirname=%~dp0 set dirname=%dirname:~,-1% for /f "tokens=5 delims=- " %%i in ('findstr /C:"# Version" %dirname%\%progname%%extname% ^| findstr /v findstr ') do set version=%%i set file_log= :: Specific variables set TIMEOUT=60 set SILENT=0 if not defined ACTION set ACTION=STATUS if not defined OUTPUT set OUTPUT=CON if not defined ADXDIR if exist %dirname%\..\bin\env.bat (set ADXDIR=%dirname%\..) && (set ADXDIR=!ADXDIR:~,-8!) if not defined ADXDOS if exist "%ADXDIR%"\adxvolumes for /F "tokens=1,2,3 delims=: " %%i in ('type %ADXDIR%\adxvolumes ^| find /I "A:" ') do set ADXDOS=%%j:%%k if not defined ADXDOS if exist %dirname%\..\..\dossiers (set ADXDOS=%dirname%\..\..) && (set ADXDOS=!ADXDOS:~,-19!\dossiers) if exist %ADXDIR%\SERVX3 set BATCH_FOLDER=SERVX3 if exist %ADXDIR%\SERVGX set BATCH_FOLDER=SERVGX if exist %ADXDIR%\SERVABEL set BATCH_FOLDER=SERVABEL if exist %ADXDIR%\SERVPAIE set BATCH_FOLDER=SERVPAIE if exist %ADXDIR%\SERVPAYE set BATCH_FOLDER=SERVPAYE if exist %ADXDOS%\SERVX3 set BATCH_FOLDER=SERVX3 if exist %ADXDOS%\SERVGX set BATCH_FOLDER=SERVGX if exist %ADXDOS%\SERVABEL set BATCH_FOLDER=SERVABEL if exist %ADXDOS%\SERVPAIE set BATCH_FOLDER=SERVPAIE if exist %ADXDOS%\SERVPAYE set BATCH_FOLDER=SERVPAYE if exist %ADXDIR%\SERV* for /f %%i in ('dir /B %ADXDIR%\SERV*') do set type_prd=%%i if exist %ADXDOS%\SERV* for /f %%i in ('dir /B %ADXDOS%\SERV*') do set type_prd=%%i if defined type_prd set type_prd=%type_prd:~4% if exist %ADXDIR%\bin\env.bat call %ADXDIR%\bin\env.bat ::echo ACTION=%ACTION% OUTPUT=%OUTPUT% X3FOLDER=%X3FOLDER% X3TASK=%X3TASK% ADXDIR=%ADXDIR% ADXDOS=%ADXDOS% BATCH_FOLDER=%BATCH_FOLDER% goto:EOF ::# ::# End of Init_variables ::#************************************************************# :Check_options ::#************************************************************# ::# Checks options used in the command line ::# set RET=1 if defined ACTION if /I not (%ACTION%)==(STATUS) if /I not (%ACTION%)==(STOP) if /I not (%ACTION%)==(START) if /I not (%ACTION%)==(KILL) if /I not (%ACTION%)==(KILLSTOP) if /I not (%ACTION%)==(RESTART) ( call :Display ERROR: Invalid value [%ACTION%] for the variable "ACTION" [must be "STATUS", "STOP", "START", "KILL", "KILLSTOP" or "RESTART"] call :Display exit /B %RET% ) else ( call :Upper ACTION ) :: Only for backward compatibility if "%OUTPUT%"=="FIC" (set OUTPUT=FIL) if defined OUTPUT if /I not (%OUTPUT%)==(CON) if /I not (%OUTPUT%)==(NUL) if /I not (%OUTPUT%)==(FIL) if /I not (%OUTPUT%)==(SIL) ( call :Display ERROR: Invalid value [%OUTPUT%] for the variable "OUTPUT" [must be "CON", "NUL", "FIL" or "SIL"] !! call :Display exit /B %RET% ) else ( call :Upper OUTPUT ) set RET=0 goto:EOF ::# ::# End of Check_options ::#************************************************************# :Check_variables ::#************************************************************# ::# Checks the value for variables that are defined ::# set RET=1 if not exist %ADXDIR%\bin\env.bat ( call :Display ERROR: The ADXDIR environment variable is not defined correctly and cannot be auto-detected !! call :Display This environment variable is needed to run this program. call :Display call :Display Actual value: "%ADXDIR%" call :Display exit /B %RET% ) if not exist %ADXDOS%\FOLDERS.xml ( call :Display ERROR: The ADXDOS environment variable or argument passed to the program is not defined correctly !! call :Display This environment variable is needed to run this program. call :Display call :Display Actual value: "%ADXDOS%" call :Display exit /B %RET% ) if defined OUTPUT if not (%OUTPUT%)==(CON) if not (%OUTPUT%)==(NUL) if not (%OUTPUT%)==(FIL) if not (%OUTPUT%)==(SIL) ( call :Display ERROR: The OUTPUT environment variable is not defined correctly in the script !! call :Display This environment variable is needed to run this program. call :Display call :Display Actual value: [%OUTPUT%] call :Display call :Display Possible values: [CON] ^(Console^) call :Display [NUL] ^(None^) call :Display [FIL] ^(File trace="%TMPDIR%\batchsrv.log" by default^) call :Display [SIL] Same as [FIL] but absolutely nothing sent to CON call :Display ) if defined X3FOLDER ( call :Check_x3folder !X3FOLDER! if "!RET2!"=="1" ( call :Display ERROR: Invalid value [!X3FOLDER!] used for variable "ACTION", "OUTPUT", "X3FOLDER" or running "X3TASK" !! call :Display goto :Usage ) ) if defined X3FOLDER set X3FOLDER_BAK=%X3FOLDER% if defined X3TASK set X3TASK_BAK=%X3TASK% set RET=0 goto:EOF ::# ::# End of Check_variables ::#************************************************************# :Init_files ::#************************************************************# ::# Initializes files used in the program ::# for /D %%i in (SIL FIL) do if /I (%OUTPUT%)==(%%i) (set file_log=%TMPDIR%\%progname%.log) :: Renames the old file trace if existing if exist "%file_log%" move /Y %file_log% %file_log%.old >NUL 2>&1 :: Displays the banner at the beginning of the file trace call :Banner>NUL ) goto:EOF ::# ::# End of Init_files ::#************************************************************# :Stop_srvbatch ::#************************************************************# ::# Stops the X3 batch server ::# call :Display STOPPING THE BATCH SERVER [%BATCH_FOLDER%] FOR THE %type_prd% SOLUTION [%AE_SERVICE_NAME%]... set SILENT=1 call :Stat_srvbatch set SILENT=0 if not (%RET%)==(0) ( call :Display OK set MSG=BATCH SERVER WAS NOT RUNNING set RET=2 goto:EOF ) else ( if exist %ADXDIR%\%BATCH_FOLDER% (echo >%ADXDIR%\%BATCH_FOLDER%\FIL\stop) :: Compatibility ensured from the V8 version if exist %ADXDOS%\%BATCH_FOLDER% (echo >%ADXDOS%\%BATCH_FOLDER%\FIL\stop) set CPT=%TIMEOUT% call :waitstopsrv) goto:EOF ::# ::# End of Stop_srvbatch ::#************************************************************# :waitstopsrv ::#************************************************************# ::# Loop for Waiting shutdown of the batch server ::# call :Display waiting [%CPT%]... call :Sleep 2 set SILENT=1 call :Stat_srvbatch set SILENT=0 if "%RET%"=="2" ( call :Display OK set MSG=BATCH SERVER STOPPED. set RET=0 goto:EOF ) else ( if "!CPT!"=="0" ( call :Display KO set MSG=BATCH SERVER DID NOT STOP PROPERLY set ERR=PLEASE, MAKE SURE THAT THE SCRIPT IS EXECUTED AS AN ADMINISTRATOR AND THE DATABASE IS OPENED. set RET=1 goto:EOF ) ) set /A CPT=%CPT%-1 goto waitstopsrv ::# ::# End of waitstopsrv ::#************************************************************# :Start_srvbatch ::#************************************************************# ::# Starts the X3 batch server ::# call :Display STARTING THE BATCH SERVER [%BATCH_FOLDER%] FOR THE %type_prd% SOLUTION [%AE_SERVICE_NAME%]... set SILENT=1 call :Stat_srvbatch set SILENT=0 if (%RET%)==(0) ( call :Display OK set MSG=BATCH SERVER IS ALREADY RUNNING [PID=%PID:~-5%] set RET=2 goto:EOF ) :: Adds the CRYPT argument in the command to fix the bug no KB54798 for a workflow problem. :: The argument "-y CRYPT:" is added in the command used to start the X3 Batch server :: where is the encrypted password of the service account that starts the Sage X3 solution, :: else that of the user account configured in the X3 connection box if the service is running as local system. :: It is possible only if the X3 batch server has been already started a first time from the application. if exist "%ADXDIR%\%BATCH_FOLDER%\tmp\serveur.bat" for /F "tokens=6,7 delims=: " %%i in ('type %ADXDIR%\%BATCH_FOLDER%\tmp\serveur.bat') do if "%%i"=="CRYPT" (set PWD=%%j) :: Compatibility ensured from the V8 version if exist "%ADXDOS%\%BATCH_FOLDER%\tmp\serveur.bat" for /F "tokens=6,7 delims=: " %%i in ('type %ADXDOS%\%BATCH_FOLDER%\tmp\serveur.bat') do if "%%i"=="CRYPT" (set PWD=%%j) if defined PWD ( start adonix -a -s %AE_SERVICE% -y CRYPT:!PWD! -l FRA %BATCH_FOLDER% ) else ( start adonix -a -s %AE_SERVICE% -l FRA %BATCH_FOLDER% ) set CPT=%TIMEOUT% call :waitstartsrv goto:EOF ::# ::# End of Start_srvbatch ::#************************************************************# :waitstartsrv ::#************************************************************# ::# Loop for waiting start of the batch server ::# call :Display waiting [%CPT%]... call :Sleep 2 set SILENT=1 call :Stat_srvbatch set SILENT=0 if "%RET%"=="0" ( call :Display OK set MSG=BATCH SERVER STARTED SUCCESSFULLY [PID=%PID:~-5%]. set RET=0 goto:EOF ) else ( if "!CPT!"=="0" ( call :Display KO set MSG=BATCH SERVER STARTUP FAILED set ERR=PLEASE, MAKE SURE THAT THE SCRIPT IS EXECUTED AS AN ADMINISTRATOR AND THE DATABASE IS OPENED. set RET=1 goto:EOF ) ) set /A CPT=%CPT%-1 goto waitstartsrv ::# ::# End of waitstartsrv ::#************************************************************# :Stat_srvbatch ::#************************************************************# ::# Checks the status of the x3 batch server ::# call :Display CHECKING THE BATCH SERVER ACTIVITY [%BATCH_FOLDER%] FOR THE %type_prd% SOLUTION [%AE_SERVICE_NAME%]... set PID= for /F "tokens=1,2 delims=:" %%i in ('psadx -fpx ^| find " %AE_SERVICE% " ^| find "BATCH" ^| find "%BATCH_FOLDER%" ') do set PID=%%i if "%PID%"=="" for /F "tokens=1,2 delims=:" %%i in ('psadx -fpx ^| find " p:p " ^| find "BATCH" ^| find "%BATCH_FOLDER%" ') do (set PID=%%j) if not "%PID%"=="" ( if exist %ADXDIR%\%BATCH_FOLDER%\FIL\stop ( set MSG=BATCH SERVER SHUTTING DOWN IN PROGRESS [PID=%PID:~-5%]... set RET=1 ) else ( :: Compatibility ensured from the V8 version if exist %ADXDOS%\%BATCH_FOLDER%\FIL\stop ( set MSG=BATCH SERVER SHUTTING DOWN IN PROGRESS [PID=%PID:~-5%]... set RET=1 ) else ( set MSG=BATCH SERVER IS ACTIVE [PID=%PID:~-5%]. set RET=0 ) ) ) else ( if exist %ADXDIR%\%BATCH_FOLDER%\FIL\run ( set MSG=BATCH SERVER IS DISABLED set RET=1 ) else ( :: Compatibility ensured from the V8 version if exist %ADXDOS%\%BATCH_FOLDER%\FIL\run ( set MSG=BATCH SERVER IS DISABLED set RET=1 ) else ( for /F "tokens=1,2,3 delims= " %%i in ('psadx -fp ^| find " %AE_SERVICE% " ^| find "BATCH" ^| find /V "%BATCH_FOLDER%" ') do (set FLD=%%k) if "!FLD!." == "." for /F "tokens=1,2,3 delims= " %%i in ('psadx -fp ^| find "BATCH" ^| find /V "%BATCH_FOLDER%" ') do (set FLD=%%k) if "!FLD!." == "." ( set MSG=BATCH SERVER IS NOT ACTIVE set RET=2 ) else ( set MSG=BATCH SERVER IS NOT ACTIVE, TASKS RUNNING [!FLD!] set RET=2 ) ) ) ) ) call :stat_allbatch goto:EOF ::# ::# End of Stat_srvbatch ::#************************************************************# :Stop_allbatch ::#************************************************************# ::# Stops all running batch tasks ::# if defined X3TASK ( if defined X3FOLDER ( set MSG=NO RUNNING TASK "%X3TASK%" WAS FOUND FROM THE "%X3FOLDER%" FOLDER ) else ( set MSG=NO RUNNING TASK [%X3TASK%] WAS FOUND ) ) else ( if defined X3FOLDER ( set MSG=NO RUNNING TASK WAS FOUND FROM THE "%X3FOLDER%" FOLDER ) else ( set MSG=NO RUNNING TASK WAS FOUND ) ) set RET=2 call :stat_allbatch set CPT=%TIMEOUT% set X3FOLDER=%X3FOLDER_BAK% set X3TASK=%X3TASK_BAK% call :Display if not defined X3FOLDER ( set X3FOLDER=.* if not defined X3TASK ( set X3TASK=* call :Display STOPPING ALL RUNNING BATCH TASKS FOR THE %type_prd% SOLUTION [%AE_SERVICE_NAME%]... ) else ( call :Display STOPPING THE BATCH TASK [%X3TASK%] FOR THE %type_prd% SOLUTION [%AE_SERVICE_NAME%]... ) ) else ( if not defined X3TASK ( set X3TASK=* call :Display STOPPING ALL RUNNING BATCH TASKS FROM THE FOLDER [%X3FOLDER%] FOR THE %type_prd% SOLUTION [%AE_SERVICE_NAME%]... ) else ( call :Display STOPPING THE BATCH TASK [%X3TASK%] FROM THE FOLDER [%X3FOLDER%] FOR THE %type_prd% SOLUTION [%AE_SERVICE_NAME%]... ) ) ::Kills all running X3 batch tasks for each folder for /f %%i in ('dir /B %ADXDOS% ^| find /v "." ^| find /v "_" ^| findstr "%X3FOLDER%"') do ( set X3FOLDER=%%i call :Check_x3folder !X3FOLDER! if "!RET2!"=="0" if exist %ADXDOS%\!X3FOLDER!\FIL\%X3TASK%.run ( call :Display for /F "delims=" %%i in ('dir /B %ADXDOS%\!X3FOLDER!\FIL\%X3TASK%.run') do ( set FUNCTION=%%~ni if not exist %ADXDOS%\!X3FOLDER!\FIL\!FUNCTION!.stop ( for /F "delims=_" %%j in ('echo !FUNCTION!') do if "%%j"=="ITL" (set X3TASK=INTERFACE) else (set X3TASK=!FUNCTION!) set SILENT=1 call :stat_task !X3FOLDER! !X3TASK! !FUNCTION! set SILENT=0 if "!RET!"=="0" ( if "!X3TASK!"=="!FUNCTION!" ( call :Display ## Stopping the running batch task [!X3TASK!] from the !X3FOLDER! folder... ) else ( call :Display ## Stopping the running batch task [!X3TASK!:!FUNCTION!] from the !X3FOLDER! folder... ) echo>%ADXDOS%\!X3FOLDER!\FIL\!FUNCTION!.stop call :waitstoptask !X3FOLDER! !X3TASK! !FUNCTION! set SILENT=1 call :stat_task !X3FOLDER! !X3TASK! !FUNCTION! set SILENT=0 if "!RET!"=="0" (call :Display KO) else (call :Display OK) call :Display ) else ( del %ADXDOS%\!X3FOLDER!\FIL\!FUNCTION!.run>NUL ) ) ) ) ) set CPT=%TIMEOUT% set X3FOLDER=%X3FOLDER_BAK% if defined X3TASK_BAK goto:EOF if defined X3FOLDER_BAK goto:EOF ::Kill any left running X3 batch tasks for the whole folders set SILENT=1 call :stat_anybatch %%i set SILENT=0 if "!RET!"=="0" ( call :Display ## Stopping any left running batch tasks in %type_prd% folders... if exist %ADXDIR%\%BATCH_FOLDER% echo >%ADXDIR%\%BATCH_FOLDER%\FIL\kill :: Compatibility ensured from the V8 version if exist %ADXDOS%\%BATCH_FOLDER% echo >%ADXDOS%\%BATCH_FOLDER%\FIL\kill call :waitstopanybatch set SILENT=1 call :stat_anybatch %%i set SILENT=0 if "!RET!"=="0" ( call :Display KO ) else ( call :Display OK if exist %ADXDOS%\!X3FOLDER!\FIL\*.run del %ADXDOS%\!X3FOLDER!\FIL\*.run>NUL set MSG=ALL RUNNING TASKS STOPPED SUCCESSFULLY. set RET=0) ) else (set RET=2) if /I %ACTION%==killstop call :Status goto:EOF ::# ::# End of Stop_allbatch ::#************************************************************# :waitstoptask ::#************************************************************# ::# Loop for waiting end for the running x3 batch task ::# ::# List of arguments passed to the function: ::# %1 = folder name ::# %2 = task name ::# %3 = function name ::# if "%2"=="%3" (set X3TASK=%2) else (set X3TASK=%2:%3) call :Display waiting [%CPT%]... call :Sleep 2 set SILENT=1 call :stat_task %1 %2 %3 set SILENT=0 if (!RET!)==(1) ( set MSG=X3 BATCH TASK STOPPED ON THE FOLDER [%1] set RET=0 goto:EOF ) else ( if "!CPT!"=="0" ( set MSG=X3 BATCH TASK DID NOT STOP PROPERLY ON THE FOLDER [%1] set RET=1 goto:EOF ) ) set /A CPT=%CPT%-1 goto waitstoptask ::# ::# End of waitstoptask ::#************************************************************# :waitstopanybatch ::#************************************************************# ::# Loop for waiting end for any running batch task ::# call :Display waiting [%CPT%]... call :Sleep 2 set SILENT=1 call :stat_anybatch set SILENT=0 if (!RET!)==(1) ( set MSG=ALL RUNNING TASKS STOPPED SUCCESSFULLY. set RET=0 goto:EOF ) else ( if "!CPT!"=="0" ( set MSG=SOME RUNNING TASKS DID NOT STOP PROPERLY set RET=1 goto:EOF ) ) set /A CPT=%CPT%-1 goto waitstopanybatch ::# ::# End of waitstopanybatch ::#************************************************************# :stat_task ::#************************************************************# ::# Checks if the X3 batch task is running for a folder ::# ::# List of arguments passed to the function: ::# %1 = folder name ::# %2 = task name ::# %3 = function name ::# call :Display Checking if the batch task is running [%2] for the %type_prd% folder [%1]... set RET=1 for /F "tokens=4,5 delims= " %%i in ('psadx -fpox ^| find " %AE_SERVICE% " ^| find "BATCH" ^| find "%1" ') do if (%%j)==(%2) set RET=0 if "!RET!"=="1" for /F "tokens=4 delims= " %%i in ('psadx -fpox ^| find "BATCH" ') do if (%%i)==(%1) set RET=0 ::if "!RET!"=="1" if exist %ADXDOS%\%1\FIL\%3.run (set RET=2) if "!RET!"=="0" if not exist %ADXDOS%\%1\FIL\%3.run set RET=1 ) goto:EOF ::# ::# End of stat_task ::#************************************************************# :stat_anybatch ::#************************************************************# ::# Checks if some task is left running for any folder ::# call :Display Checking if some task is left running for any folder... set RET=1 for /F "tokens=1,2,3 delims= " %%i in ('psadx -fp ^| find " %AE_SERVICE% " ^| find "BATCH" ^| find /V "%BATCH_FOLDER%" ') do set RET=0 if (!RET!)==(1) for /F "tokens=1,2,3 delims= " %%i in ('psadx -fp ^| find "BATCH" ^| find /V "%BATCH_FOLDER%" ') do set RET=0 goto:EOF ::# ::# End of stat_anybatch ::#************************************************************# :stat_allbatch ::#************************************************************# ::# Counting all running batch tasks for each folder ::# call :Display if not defined X3FOLDER ( set X3FOLDER=.* if not defined X3TASK ( set X3TASK=* call :Display ## Listing all running batch tasks for each %type_prd% folder... ) else ( call :Display ## Checking if running batch task [%X3TASK%] for each %type_prd% folder... ) ) else ( if not defined X3TASK ( set X3TASK=* call :Display ## Listing all running batch tasks from the folder [%X3FOLDER%]... ) else ( call :Display ## Checking if running batch task [%X3TASK%] from the folder [%X3FOLDER%]... ) ) call :Display ------------------------------------------------------------------------------- set RET2=1 set SUM=0 set NB=0 for /f %%i in ('dir /B %ADXDOS% ^| find /v "." ^| find /v "_" ^| findstr "%X3FOLDER%" ^| find /V "%BATCH_FOLDER%" ^| find /V "Uninstaller"') do ( set X3FOLDER=%%i call :Check_x3folder !X3FOLDER! if "!RET2!"=="0" ( for /F "tokens=1 delims= " %%i in ('psadx -fp ^| find " %AE_SERVICE% " ^| find "BATCH" ^| find /V "%BATCH_FOLDER%" ^| find " !X3FOLDER! " ^| find /C " " ') do set NB=%%i if "!NB!"=="0" for /F "tokens=1 delims= " %%i in ('psadx -fp ^| find "BATCH" ^| find /V "%BATCH_FOLDER%" ^| find " !X3FOLDER! " ^| find /C " " ') do set NB=%%i if not "!NB!"=="0" ( set RET2=0 if exist %ADXDOS%\!X3FOLDER!\FIL\%X3TASK%.run ( set X3TASKLIST= for /F "delims=" %%i in ('dir /B %ADXDOS%\!X3FOLDER!\FIL\%X3TASK%.run') do if not exist %ADXDOS%\!X3FOLDER!\FIL\%%~ni.stop if "!X3TASKLIST!"=="" (set X3TASKLIST=%%~ni) else (set X3TASKLIST=!X3TASKLIST!, %%~ni) if defined X3TASKLIST if defined X3TASK_BAK set NB=1 call :Display !NB! task^(s^) on the folder !X3FOLDER! ^(!X3TASKLIST!^) ) else ( call :Display !NB! task^(s^) on the folder !X3FOLDER! ** WARNING: RUN FILE MISSING ** ) ) else ( call :Display !NB! task^(s^) on the folder !X3FOLDER! ) ) if defined X3FOLDER_BAK call :Display set /A SUM=!SUM!+!NB! ) if /I %ACTION%==STATUS ( call :Display if "!SUM!"=="0" (call :Display ** NO RUNNING TASK FOUND **) else (call :Display !SUM! RUNNING TASK^(S^) FOUND.) ) goto:EOF ::# ::# End of stat_allbatch ::#************************************************************# :Restart_srvbatch ::#************************************************************# ::# Restarts the x3 batch server (killstop + start options) ::# without the stop of all running batch tasks ::# call :Stop_srvbatch call :Display call :Start_srvbatch goto:EOF ::# ::# End of Restart_srvbatch ::#************************************************************# :Status ::#************************************************************# ::# Displays status at the end of the command execution ::# call :Display ------------------------------------------------------------------------------- if "!RET!"=="0" set STATUS=OK if "!RET!"=="1" set STATUS=^^!^^! ERROR ^^!^^! if "!RET!"=="2" set STATUS=** WARN ** call :Display %progname% %ACTION% : %DATE% %TIME:~,5% !STATUS! call :Display ADXDIR=%ADXDIR%, Port '%AE_SERVICE_NAME%' (%AE_SERVICE%/tcp) if "!RET!"=="0" call :Display !MSG! if "!RET!"=="1" call :Display ^^!^^! !MSG! ^^!^^! if "!RET!"=="2" call :Display ** !MSG! ** if not "!ERR!"=="" call :Display %ERR% call :Display ------------------------------------------------------------------------------- goto:EOF ::# ::# End of status ::#************************************************************# :Sleep ::#************************************************************# ::# Loop wait for a number of seconds ::# ::# List of arguments passed to the function: ::# %1 = delay in seconds ::# :: Automatic wait for the display when the program runs from Windows Explorer ping -n %1 localhost>NUL goto:EOF ::# ::# End of Sleep ::#************************************************************# :Check_x3folder ::#************************************************************# ::# Checks existing folder for the X3 Solution ::# ::# List of arguments passed to the function: ::# %1 = folder name ::# if exist %ADXDOS%\FOLDERS.xml ( find """%1""" %ADXDOS%\FOLDERS.xml >NUL set RET2=!ERRORLEVEL! ) else (if exist %ADXDOS%\%1\.passwd (set RET2=0) else set RET2=1) if "!RET2!"=="1" ( for /f %%i in ('dir /B %ADXDOS% ^| find /v "." ^| find /v "_"') do ( if exist %ADXDOS%\%%i\FIL\%1.run ( set X3TASK=%1 set X3FOLDER= set RET2=2 ) ) ) goto:EOF ::# ::# End of Check_x3folder ::#************************************************************# :Upper ::#************************************************************# ::# Converts lowercase character to uppercase for a variable ::# setlocal enabledelayedexpansion if not defined %~1 endlocal & exit /B set STR=!%1! if not "%STR%"=="%%" for %%z in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do call set STR=!STR:%%z=%%z! for /f "delims=" %%a in ("!STR!") do endlocal & set "%1=%%a" exit /B 0 ::# ::# End of Upper ::#************************************************************# :Display ::#************************************************************# ::# Displays and redirects a message to standard output and/or the trace file ::# ::# List of arguments passed to the function: ::# %* = message text ::# if (%SILENT%)==(1) exit /B if (%OUTPUT%)==(NUL) exit /B set ARGS=%* if not defined file_log if defined ARGS echo %ARGS% if not defined file_log if not defined ARGS echo: if not defined file_log exit /B if defined ARGS echo %ARGS% >>%file_log% if not defined ARGS echo: >>%file_log% goto:EOF ::# ::# End of Display ::#************************************************************# :Version ::#************************************************************# ::# Displays the version number, the last modified date of the program, ::# and the list of variables modified & functions defined. ::# set file_tmp=%dirname%\%progname%.tmp for /f "tokens=5" %%i in ('findstr /C:"Last date" %dirname%\%progname%%extname% ^| findstr /V findstr') do set lastdate=%%i >%file_tmp% echo %dirname%\%progname%%extname% - v%version% ^(%lastdate%^) >>%file_tmp% echo: >>%file_tmp% echo List of variables modified: >>%file_tmp% echo -------------------------- set END= for /f "tokens=1* delims=:" %%i in ('findstr /n /c:"END OF IMPLEMENTATION-DEPENDANT VARIABLES" %dirname%\%progname%%extname% ^| findstr /v findstr') do if not defined END set END=%%i for /f "tokens=1,* delims=[:]" %%i in ('findstr /n "^set" %dirname%\%progname%%extname% ^| findstr /v "=$" ^| findstr /v "setlocal"') do @if %%i leq %END% (>>%file_tmp% echo %%j) >>%file_tmp% echo: >>%file_tmp% echo List of functions defined: >>%file_tmp% echo ------------------------- for /f "delims=: " %%i in ('findstr "^:[A-Z]" %dirname%\%progname%%extname% ^| findstr /v ":option"') do @echo %%i >>%file_tmp% type %file_tmp% | more del %file_tmp% goto End ::# ::# End of Version ::#************************************************************# :Banner ::#************************************************************# ::# Banner displayed at the beginning of the command execution ::# ::# List of optional arguments passed to the function: ::# %1 = 1st argument passed to the program ::# %2 = 2nd argument passed to the program ::# for /D %%i in (SIL NUL) do if /I (%1)==(%%i) goto:EOF for /D %%i in (SIL NUL) do if /I (%2)==(%%i) goto:EOF if not defined AE_SERVICE_NAME set AE_SERVICE_NAME=X3 call :Display #------------------------------------------------------------------------------ call :Display # %progname%%extname% - version %version% for %platform%. call :Display # Manages the X3 Batch server for the Sage X3 Solution [%AE_SERVICE_NAME%]. call :Display # %copyright% by %author% - All Rights Reserved. call :Display #------------------------------------------------------------------------------ goto:EOF ::# ::# End of Banner ::#************************************************************# :Usage ::#************************************************************# ::# Syntax for the execution of the command ::# if not defined TMPDIR set TMPDIR=%%TMPDIR%% echo Usage: %progname%%extname% [ ^ ^| ^ ^| ^ ^| ^ ] ... echo: echo ^ = status : Checks status of the batch server (default value) echo stop : stops the batch server echo start : starts the batch server echo kill : kills only running tasks echo killstop : kills running tasks and stops the batch server echo restart : stops and starts the batch server echo: echo ^ = CON : redirects the standard output to the console (default option) echo NUL : redirects the standard output to nothing echo FIL : redirects the standard output to a trace file ^(%TMPDIR%\batchsrv.log^) echo SIL : redirects the standard output to a trace file in silent mode echo: echo ^ = X3 folder existing for the Sage X3 Solution echo: echo ^ = X3 batch task running for the Sage X3 Solution echo: echo Exit status = 0 : OK echo = 1 : ^^!^^! ERROR ^^!^^! echo = 2 : ** WARN ** echo: echo Examples : %dirname%\%progname% status echo %dirname%\%progname% restart FIL echo %dirname%\%progname% killstop echo %dirname%\%progname% kill DEMO echo %dirname%\%progname% kill DEMO ACCENTRY01 ::# ::# End of Usage ::#************************************************************# :End exit /B %RET% endlocal