9.4.6 Settings of Management Action Execution Commands
You can code the commands to be executed as Management actions in the command files (batch files or shell script files). Create command files as required. Note that for batch servers, you cannot use request scheduling by CTM, and therefore, CTM- related description is not applicable.
The following are the environment variables that can be used in the command files and samples of command files:
- Organization of this subsection
(1) Environment variables that can be used in command files
The following table lists the environment variables that you can use in the command files:
(2) Samples of command files
Reference the provided samples of command files and create a command file. The samples are stored in the following location:
-
In Windows
Cosminexus-installation-directory\manager\examples\maction
-
In UNIX
/opt/Cosminexus/manager/examples/maction
For using a sample, change the arguments of the mngsvrutil command (such as -m, -u, and -p options), and the storage destination of a log file in conformity with the environment.
(a) Sample to restart the server that issues Management events
- File name of a sample
-
-
In Windows: mActionSample_restartServer.bat
-
In UNIX: mActionSample_restartServer.sh
-
- Operating the sample
-
Restart the logical server from where the Management event is issued.
You can use this sample to issue Management events with the resource depletion monitoring function.
-
The resource depletion monitoring functionality monitors the memory usage of a Java VM, and outputs a message if Full GC is likely to occur when the threshold value that is set is exceeded.
-
The Management event issuing function executes a Management action after issuing a Management event in correspondence with the output message, and restarts the J2EE server from where the Management event is issued.
By terminating the J2EE server from where the Management event is issued, you can block the J2EE application. Furthermore, if the J2EE server uses CTM for the load balancing of requests, you can terminate the J2EE server for distributing new requests to other J2EE servers.
-
The sample to restart the server from where the Management event is issued is described below:
-
In Windows
(Omitted) ... rem Management action sample for restart server. setlocal set LSNAME=%COSMI_MNG_MACT_LSNAME% set MSGID=%COSMI_MNG_MACT_MSG_ID% set CJCLDELLOG=%COSMINEXUS_HOME%\CC\client\bin\cjcldellog.bat set LOG_ROOT_DIR=%SystemDrive%\<MyLogDir> if not exist "%LOG_ROOT_DIR%" mkdir "%LOG_ROOT_DIR%" call "%CJCLDELLOG%" -t 30d -f "%LOG_ROOT_DIR%" set LOG_DIR=%LOG_ROOT_DIR%\%date:/=% if not exist "%LOG_DIR%" mkdir "%LOG_DIR%" set LOG=%LOG_DIR%\%time::=%_%LSNAME%_%MSGID%.txt echo %0 > "%LOG%" set MNGSVR=localhost:%COSMI_MNG_MACT_MNGSVR_PORT% set UID=<User-id> set PWD=<Password> echo mngsvrutil.exe -m %MNGSVR% -u %UID% -p %PWD% -t %LSNAME% -s stop server >> "%LOG%" 2>&1 mngsvrutil.exe -m %MNGSVR% -u %UID% -p %PWD% -t %LSNAME% -s stop server >> "%LOG%" 2>&1 set RET=%ERRORLEVEL% echo %RET% >> "%LOG%" if not %RET% == 0 goto END echo mngsvrutil.exe -m %MNGSVR% -u %UID% -p %PWD% -t %LSNAME% -s start server >> "%LOG%" 2>&1 mngsvrutil.exe -m %MNGSVR% -u %UID% -p %PWD% -t %LSNAME% -s start server >> "%LOG%" 2>&1 set RET=%ERRORLEVEL% echo %RET% >> "%LOG%" :END exit %RET%
-
In UNIX
(Omitted) ... # Management action sample for restart server. LSNAME=${COSMI_MNG_MACT_LSNAME} MSGID=${COSMI_MNG_MACT_MSG_ID} LOG_ROOT_DIR=/tmp/<MyLogDir> if [ ! -d ${LOG_ROOT_DIR} ]; then /bin/mkdir ${LOG_ROOT_DIR} fi /usr/bin/find ${LOG_ROOT_DIR}/* -depth -mtime +30 | /usr/bin/xargs /bin/rm -fr LOG_DIR=${LOG_ROOT_DIR}/`/bin/date +%y%m%d` if [ ! -d ${LOG_DIR} ]; then /bin/mkdir ${LOG_DIR} fi LOG=${LOG_DIR}/`/bin/date +%H%M%S`_${LSNAME}_${MSGID}.txt echo $0 > "${LOG}" MNGSVR=localhost:${COSMI_MNG_MACT_MNGSVR_PORT} USERID=<User-id> PASSWD=<Password> echo ./mngsvrutil -m ${MNGSVR} -u ${USERID} -p ${PASSWD} -t ${LSNAME} -s stop server >> "${LOG}" 2>&1 ./mngsvrutil -m ${MNGSVR} -u ${USERID} -p ${PASSWD} -t ${LSNAME} -s stop server >> "${LOG}" 2>&1 RET=$? echo ${RET} >> "${LOG}" if [ $RET -eq 0 ]; then echo ./mngsvrutil -m ${MNGSVR} -u ${USERID} -p ${PASSWD} -t ${LSNAME} -s start server >> "${LOG}" 2>&1 ./mngsvrutil -m ${MNGSVR} -u ${USERID} -p ${PASSWD} -t ${LSNAME} -s start server >> "${LOG}" 2>&1 RET=$? echo ${RET} >> "${LOG}" fi exit ${RET}
(b) A sample for blocking a service unit belonging to the server issuing Management events
Reference the sample provided for blocking the service units belonging to the server from where the management event is issued, and create a sample. The sample file name and operations are as follows:
- File name of a sample
-
-
In Windows: mActionSample_closeUnit.bat
-
In UNIX: mActionSample_closeUnit.sh
-
- Operating the sample
-
When errors such as resource depletion occur in a J2EE server belonging to a service unit, block the server from where the Management event is issued.
The sample for blocking service units belonging to the server from where the Management event is issued is described below:
-
In Windows
(Omitted) ... rem Management action sample for close unit. setlocal set LSNAME=%COSMI_MNG_MACT_LSNAME% set MSGID=%COSMI_MNG_MACT_MSG_ID% set WEBSYSTEM=%COSMI_MNG_MACT_WEBSYSTEM% set UNIT=%COSMI_MNG_MACT_UNIT% set CJCLDELLOG=%COSMINEXUS_HOME%\CC\client\bin\cjcldellog.bat set LOG_ROOT_DIR=%SystemDrive%\<MyLogDir> if not exist "%LOG_ROOT_DIR%" mkdir "%LOG_ROOT_DIR%" call "%CJCLDELLOG%" -t 30d -f "%LOG_ROOT_DIR%" set LOG_DIR=%LOG_ROOT_DIR%\%date:/=% if not exist "%LOG_DIR%" mkdir "%LOG_DIR%" set LOG=%LOG_DIR%\%time::=%_%LSNAME%_%MSGID%.txt echo %0 > "%LOG%" if "%WEBSYSTEM%" == "" goto :ERR if "%UNIT%" == "" goto :ERR set MNGSVR=localhost:%COSMI_MNG_MACT_MNGSVR_PORT% set UID=<User-id> set PWD=<Password> echo cmx_stop_target.exe -m %MNGSVR% -u %UID% -p %PWD% -mode ALL -s %WEBSYSTEM% -unit %UNIT% >> "%LOG%" 2>&1 cmx_stop_target.exe -m %MNGSVR% -u %UID% -p %PWD% -mode ALL -s %WEBSYSTEM% -unit %UNIT% >> "%LOG%" 2>&1 set RET=%ERRORLEVEL% echo %RET% >> "%LOG%" goto :END :ERR set RET=2 :END exit %RET%
-
In UNIX
(Omitted) ... # Management action sample for close unit. LSNAME=${COSMI_MNG_MACT_LSNAME} MSGID=${COSMI_MNG_MACT_MSG_ID} WEBSYSTEM=${COSMI_MNG_MACT_WEBSYSTEM} UNIT=${COSMI_MNG_MACT_UNIT} LOG_ROOT_DIR=/tmp/<MyLogDir> if [ ! -d ${LOG_ROOT_DIR} ]; then /bin/mkdir ${LOG_ROOT_DIR} fi /usr/bin/find ${LOG_ROOT_DIR} -depth -mtime +30 -mindepth 1 -exec /bin/rm -fr {} \; LOG_DIR=${LOG_ROOT_DIR}/`/bin/date +%y%m%d` if [ ! -d ${LOG_DIR} ]; then /bin/mkdir ${LOG_DIR} fi LOG=${LOG_DIR}/`/bin/date +%H%M%S`_${LSNAME}_${MSGID}.txt echo $0 > "${LOG}" if [ "${WEBSYSTEM}" = "" -o "${UNIT}" = "" ]; then exit 2 fi MNGSVR=localhost:${COSMI_MNG_MACT_MNGSVR_PORT} USERID=<User-id> PASSWD=<Password> echo ./cmx_stop_target -m ${MNGSVR} -u ${USERID} -p ${PASSWD} -mode ALL -s ${WEBSYSTEM} -unit ${UNIT} >> "${LOG}" 2>&1 ./cmx_stop_target -m ${MNGSVR} -u ${USERID} -p ${PASSWD} -mode ALL -s ${WEBSYSTEM} -unit ${UNIT} >> "${LOG}" 2>&1 RET=$? echo ${RET} >> "${LOG}" exit ${RET}
(3) Operations of Management action execution commands
The following section describes the operation of management action execution commands:
-
The Management Server does not acquire the standard output and standard error output from the commands to execute a Management action. To acquire the standard output and standard error output of a command, information must be output to a file during command execution.
-
The Management Server runs commands to execute Management actions. The executing user is the user who executes the Management Server. The environment variables are inherited from the environment variables set in the Management Server.
-
The working directory for the management action execution commands is Cosminexus-installation-directory\manager\bin (in Windows) or /opt/Cosminexus/manager/bin (in UNIX).