Cognos Services Manager

Here’s a batch file I’ve written over the past few years that automates the starting, stopping, testing and restarting of distributed Cognos services across three environments.

This particular script has been anonymised, but is hopefully still in working order. It’s been in use for ~3 years on Windows 2008 R2 Server.

@echo off
SETLOCAL EnableDelayedExpansion
set BI=On
Set Planning=On
:: 17/09/2012
:: Script by Andrew Mosey 
:: Distributed starting of Cognos Environments Automation.

:menu
cls
echo S) SAP-Dev && echo 1) Dev && echo 2) Test && echo 3) Prod && echo.
echo 0) Exit && echo.
choice /c 123S0
set env=!errorlevel!
if !env!==5 goto :eof

:env_menu
cls
if !env!==1 echo Environment: Development
if !env!==2 echo Environment: Test
if !env!==3 echo Environment: Production
echo.
echo B) Include BI Services: !BI!
echo P) Include Planning Services: !Planning!
echo.
echo 1) Test Services && echo 2) Stop Services && echo 3) Start Services && echo 4) Restart Services && echo. && echo 0) exit && echo.
choice /C 1234BP0
set operation=!errorlevel!

if !operation!==5 (	if !BI!==On 	(set BI=Off
			) else (
			set BI=On
			)
			goto :env_menu
		)
if !operation!==6 (	if !Planning!==On 	(set Planning=Off
			) else (
			set Planning=On
			)
			goto :env_menu
		)

if !operation!==7 goto :menu

goto menu_!env!_!errorlevel!



:: Sandpit
:menu_4_1
call :test_sapdev
goto :env_menu

:menu_4_2
call :stop_sapdev
pause
goto :menu

:menu_4_3
call :start_sapdev
pause
goto :menu

:menu_4_4
call :stop_sapdev
call :start_sapdev
pause
goto :menu



::Development
:menu_1_1
call :test_dev
goto :env_menu

:menu_1_2
call :stop_dev
pause
goto :menu

:menu_1_3
call :start_dev
pause
goto :menu

:menu_1_4
call :stop_dev
call :start_dev
pause
goto :menu



:: Test
:menu_2_1
call :test_test
goto :env_menu

:menu_2_2
call :stop_test
pause
goto :menu

:menu_2_3
call :start_test
pause
goto :menu

:menu_2_4
call :stop_test
call :start_test
pause
goto :menu



:: Production
:menu_3_1
call :test_prod
goto :env_menu

:menu_3_2
call :stop_prod
pause
goto :menu

:menu_3_3
call :start_prod
pause
goto :menu

:menu_3_4
call :stop_prod
call :start_prod
pause
goto :menu



:stop_dev
echo. && echo.
choice /M "Do you REALLY want to STOP Development?"
if ERRORLEVEL 2 goto :menu
if ERRORLEVEL 1 goto :really_stop_dev
goto :menu

:really_stop_dev
echo.
echo.
echo -x-x-x-x-x-x-x-x-x
echo Stopping Dev (All)
echo -x-x-x-x-x-x-x-x-x
echo. && echo Date: !date! && echo Time: !time:~0,8! && echo.

IF !Bi!==On (
	call :stop_service server1238 "IBM Cognos" 
		call :stop_service server1242 "IBM Cognos" 
			call :stop_service server1239 "IBM Cognos" 
			call :stop_service server1237 "IBM Cognos" 
				call :stop_service server1240 "IBM Cognos" 
	)
			if !Planning!==On (
				call :stop_service server1243 "IBM Cognos 1011 Dev Planning:9503"
				call :wait_service_state server1243 "IBM Cognos 1011 Dev Planning:9503" STOPPED
REM
				call :stop_service server1243 "IBM Cognos 10 Planning"
				call :wait_service_state server1243 "IBM Cognos 10 Planning" STOPPED
				)

IF !Bi!==On (
				call :wait_service_state server1240 "IBM Cognos" STOPPED
			call :wait_service_state server1237 "IBM Cognos" STOPPED
			call :wait_service_state server1239 "IBM Cognos" STOPPED
		call :wait_service_state server1242 "IBM Cognos" STOPPED
	call :wait_service_state server1238 "IBM Cognos" STOPPED
	)

echo. && echo Date: !date! && echo Time: !time:~0,8! && echo.
exit /B


:start_dev
echo. && echo.
echo -x-x-x-x-x-x
echo Starting Dev
echo -x-x-x-x-x-x
echo. && echo Date: !date! && echo Time: !time:~0,8! && echo.

IF !Bi!==On (
	call :start_service server1238 "IBM Cognos" 
	call :wait_service_state server1238 "IBM Cognos" RUNNING
REM
	call :start_service server1242 "IBM Cognos" 
	call :wait_service_state server1242 "IBM Cognos" RUNNING
REM
	call :start_service server1239 "IBM Cognos" 
	call :start_service server1237 "IBM Cognos" 
		call :start_service server1240 "IBM Cognos" 
	)
	if !Planning!==On (	
		call :start_service server1243 "IBM Cognos 1011 Dev Planning:9503"
		call :wait_service_state server1243 "IBM Cognos 1011 Dev Planning:9503" RUNNING
REM
		call :start_service server1243 "IBM Cognos 10 Planning"
		call :wait_service_state server1243 "IBM Cognos 10 Planning" RUNNING
		)
IF !Bi!==On (
		call :wait_service_state server1240 "IBM Cognos" RUNNING
	call :wait_service_state server1237 "IBM Cognos" RUNNING
	call :wait_service_state server1239 "IBM Cognos" RUNNING
	)

echo. && echo Date: !date! && echo Time: !time:~0,8! && echo.
exit /B




:test_dev
echo Testing Dev
echo. && echo BI
call :test_service_state server1238 "IBM Cognos" RUNNING
call :test_service_state server1242 "IBM Cognos" RUNNING
call :test_service_state server1239 "IBM Cognos" RUNNING
call :test_service_state server1237 "IBM Cognos" RUNNING
call :test_service_state server1240 "IBM Cognos" RUNNING

echo. && echo Planning
call :test_service_state server1243 "IBM Cognos 1011 Dev Planning:9503" RUNNING
call :test_service_state server1243 "IBM Cognos 10 Planning" RUNNING
pause
exit /B




:stop_test
echo. && echo.
choice /M "Do you REALLY want to STOP Test?"
if ERRORLEVEL 2 goto :menu
if ERRORLEVEL 1 goto :really_stop_test
goto :menu

:really_stop_test
echo. && echo.
echo -x-x-x-x-x-x-x-x-x-
echo Stopping Test (All)
echo -x-x-x-x-x-x-x-x-x-
echo. && echo Date: !date! && echo Time: !time:~0,8! && echo.

IF !Bi!==On (
	call :stop_service server1229 "IBM Cognos" 
		call :stop_service server1233 "IBM Cognos" 
			call :stop_service server1230 "IBM Cognos"
			call :stop_service server1245 "IBM Cognos"
				call :stop_service server1231 "IBM Cognos"
	)

			IF !Planning!==On (
				call :stop_service server1234 "IBM Cognos 1011 Test Planning:9503" 
					call :stop_service server6348 "IBM Cognos 1011 Test Planning:9503" 
					call :wait_service_state server6348 "IBM Cognos 1011 Test Planning:9503" STOPPED
				call :wait_service_state server1234 "IBM Cognos 1011 Test Planning:9503" STOPPED

				call :stop_service server1234 "IBM Cognos 10 Planning" 
					call :stop_service server6348 "IBM Cognos 10 Planning" 
						call :stop_service server6348 "IBM Cognos 10 Planning" 
						call :wait_service_state server6348 "IBM Cognos 10 Planning" STOPPED
					call :wait_service_state server6348 "IBM Cognos 10 Planning" STOPPED
				call :wait_service_state server1234 "IBM Cognos 10 Planning" STOPPED
				)

IF !Bi!==On (
				call :wait_service_state server1231 "IBM Cognos" STOPPED
			call :wait_service_state server1245 "IBM Cognos" STOPPED
			call :wait_service_state server1230 "IBM Cognos" STOPPED
		call :wait_service_state server1233 "IBM Cognos" STOPPED
	call :wait_service_state server1229 "IBM Cognos" STOPPED
	)

echo. && echo Date: !date! && echo Time: !time:~0,8! && echo.
exit /B



:start_test
echo. && echo.
echo -x-x-x-x-x-x-x-x-x-
echo Starting Test (All)
echo -x-x-x-x-x-x-x-x-x-
echo. && echo Date: !date! && echo Time: !time:~0,8! && echo.

IF !Bi!==On (
	call :start_service server1229 "IBM Cognos"
	call :wait_service_state server1229 "IBM Cognos" RUNNING
REM
	call :start_service server1233 "IBM Cognos"
	call :wait_service_state server1233 "IBM Cognos" RUNNING
REM
	call :start_service server1230 "IBM Cognos"
	call :start_service server1245 "IBM Cognos"
		call :start_service server1231 "IBM Cognos"
	)

	IF !Planning!==On (
		call :start_service server1234 "IBM Cognos 10 Planning" 
		call :wait_service_state server1234 "IBM Cognos 10 Planning" RUNNING
REM
		call :start_service server1234 "IBM Cognos 1011 Test Planning:9503" 
		call :wait_service_state server1234 "IBM Cognos 1011 Test Planning:9503" RUNNING
REM
		call :start_service server6348 "IBM Cognos 10 Planning" 
		call :wait_service_state server6348 "IBM Cognos 10 Planning" RUNNING
REM
		call :start_service server6348 "IBM Cognos 1011 Test Planning:9503" 
		call :wait_service_state server6348 "IBM Cognos 1011 Test Planning:9503" RUNNING
		)

IF !Bi!==On (
		call :wait_service_state server1231 "IBM Cognos" RUNNING
	call :wait_service_state server1245 "IBM Cognos" RUNNING
	call :wait_service_state server1230 "IBM Cognos" RUNNING
	)

echo. && echo Date: !date! && echo Time: !time:~0,8! && echo.
exit /B




:test_test
echo Testing Test
echo. && echo BI
call :test_service_state server1229 "IBM Cognos" RUNNING
call :test_service_state server1233 "IBM Cognos" RUNNING
call :test_service_state server1230 "IBM Cognos" RUNNING
call :test_service_state server1245 "IBM Cognos" RUNNING
call :test_service_state server1231 "IBM Cognos" RUNNING
call :test_service_state server1231 "IBM Cognos" RUNNING
echo. && echo Planning
call :test_service_state server1234 "IBM Cognos 10 Planning" RUNNING
call :test_service_state server1234 "IBM Cognos 1011 Test Planning:9503" RUNNING
call :test_service_state server6348 "IBM Cognos 10 Planning" RUNNING
call :test_service_state server6348 "IBM Cognos 1011 Test Planning:9503" RUNNING
pause
exit /B




:stop_prod
echo. && echo.
echo ======================
echo Really serious warning
echo ====================== && echo.
echo You are about to STOP PRODUCTION!!!
echo.
set /p Prod_conf=To Stop Production, type the word "prod" (without quotes, lowercase) then press ENTER: 
if !prod_conf!==prod goto :really_stop_prod
echo Not stopping Production, this time.
pause
goto :menu

:really_stop_prod
echo. && echo.
echo -x-x-x-x-x-x-x-x-x-
echo Stopping Production
echo -x-x-x-x-x-x-x-x-x-
echo. && echo Date: !date! && echo Time: !time:~0,8! && echo.

IF !Bi!==On (
	call :stop_service server1274 "IBM Cognos" 
	call :stop_service server5717 "IBM Cognos" 
		call :stop_service server1273 "IBM Cognos"
	)

	IF !Planning!==On (
		call :test_and_wait_for_incremental_publish
		call :stop_service server5716 "IBM Cognos 10 Planning" 
			call :stop_service server1250 "IBM Cognos 10 Planning" 
				call :stop_service server1251 "IBM Cognos 10 Planning" 
					call :stop_service server1252 "IBM Cognos 10 Planning" 
						call :stop_service server1276 "IBM Cognos 10 Planning" 
							call :stop_service server5750 "IBM Cognos 10 Planning" 
							call :wait_service_state server5750 "IBM Cognos 10 Planning" STOPPED
REM						call :wait_service_state server1276 "IBM Cognos 10 Planning" STOPPED
REM					call :wait_service_state server1252 "IBM Cognos 10 Planning" STOPPED
REM				call :wait_service_state server1251 "IBM Cognos 10 Planning" STOPPED
REM			call :wait_service_state server1250 "IBM Cognos 10 Planning" STOPPED
REM		call :wait_service_state server5716 "IBM Cognos 10 Planning" STOPPED
REM
		call :stop_service server5716 "IBM Cognos 1011 Prod Planning:9303"
			call :stop_service server1250 "IBM Cognos 1011 Prod Planning" 
				call :stop_service server1251 "IBM Cognos 1011 Prod Planning" 
					call :stop_service server1252 "IBM Cognos 1011 Prod Planning" 
						call :stop_service server1276 "IBM Cognos 1011 Prod Planning" 
							call :stop_service server5750 "IBM Cognos 1011 Prod Planning" 
REM
							call :wait_service_state server5750 "IBM Cognos 1011 Prod Planning" STOPPED
REM						call :wait_service_state server1276 "IBM Cognos 1011 Prod Planning" STOPPED
REM					call :wait_service_state server1252 "IBM Cognos 1011 Prod Planning" STOPPED
REM				call :wait_service_state server1251 "IBM Cognos 1011 Prod Planning" STOPPED
REM			call :wait_service_state server1250 "IBM Cognos 1011 Prod Planning" STOPPED
REM		call :wait_service_state server5716 "IBM Cognos 1011 Prod Planning:9303" STOPPED
echo 10 second delay
ping 127.0.0.1 -n 15 > nul
echo pskill planning on 5716 as it can be stubborn
\\server1820\cognos$\Scripts\pskill \\server5716 epPlanningService8.exe
		)

IF !Bi!==On (
		call :wait_service_state server1273 "IBM Cognos" STOPPED
	call :wait_service_state server1274 "IBM Cognos" STOPPED
	call :wait_service_state server5717 "IBM Cognos" STOPPED
	)

:: Stop Secondary CM
IF !Bi!==On (
	call :stop_service server1272 "IBM Cognos" 
	call :wait_service_state server1272 "IBM Cognos" STOPPED
	)


:: Stop Primary CM
IF !Bi!==On (
	call :stop_service server1271 "IBM Cognos" 
	call :wait_service_state server1271 "IBM Cognos" STOPPED
	)

echo. && echo Date: !date! && echo Time: !time:~0,8! && echo.
exit /B



:start_prod
echo. && echo.
echo -x-x-x-x-x-x-x-x-x-
echo Starting Production
echo -x-x-x-x-x-x-x-x-x-
echo. && echo Date: !date! && echo Time: !time:~0,8! && echo.

IF !Bi!==On (
	call :start_service server1271 "IBM Cognos" 
	call :wait_service_state server1271 "IBM Cognos" RUNNING
REM
	call :start_service server1272 "IBM Cognos"
	call :wait_service_state server1272 "IBM Cognos" RUNNING
REM
	call :start_service server1274 "IBM Cognos"
	call :start_service server5717 "IBM Cognos"
	)

	IF !Planning!==On (
		call :start_service server5716 "IBM Cognos 10 Planning" 
		call :wait_service_state server5716 "IBM Cognos 10 Planning" RUNNING
	REM
		call :start_service server5716 "IBM Cognos 1011 Prod Planning:9303"
		call :wait_service_state server5716 "IBM Cognos 1011 Prod Planning:9303" RUNNING
	REM
		call :start_service server1250 "IBM Cognos 10 Planning" 
			call :start_service server1251 "IBM Cognos 10 Planning" 
				call :start_service server1252 "IBM Cognos 10 Planning" 
					call :start_service server1276 "IBM Cognos 10 Planning" 
						call :start_service server5750 "IBM Cognos 10 Planning" 
	REM
						call :wait_service_state server5750 "IBM Cognos 10 Planning" RUNNING
					call :wait_service_state server1276 "IBM Cognos 10 Planning" RUNNING
				call :wait_service_state server1252 "IBM Cognos 10 Planning" RUNNING
			call :wait_service_state server1251 "IBM Cognos 10 Planning" RUNNING
		call :wait_service_state server1250 "IBM Cognos 10 Planning" RUNNING
	REM
		call :start_service server1250 "IBM Cognos 1011 Prod Planning" 
			call :start_service server1251 "IBM Cognos 1011 Prod Planning"
				call :start_service server1252 "IBM Cognos 1011 Prod Planning" 
					call :start_service server1276 "IBM Cognos 1011 Prod Planning" 
						call :start_service server5750 "IBM Cognos 1011 Prod Planning" 
	REM
						call :wait_service_state server5750 "IBM Cognos 1011 Prod Planning" RUNNING
					call :wait_service_state server1276 "IBM Cognos 1011 Prod Planning" RUNNING
				call :wait_service_state server1252 "IBM Cognos 1011 Prod Planning" RUNNING
			call :wait_service_state server1251 "IBM Cognos 1011 Prod Planning" RUNNING
		call :wait_service_state server1250 "IBM Cognos 1011 Prod Planning" RUNNING
		)

IF !Bi!==On (
	call :wait_service_state server1274 "IBM Cognos" RUNNING
	call :wait_service_state server5717 "IBM Cognos" RUNNING
	REM
	call :start_service server1273 "IBM Cognos"
	call :wait_service_state server1273 "IBM Cognos" RUNNING
	)

echo. && echo Date: !date! && echo Time: !time:~0,8! && echo.
exit /B



:test_prod
echo Testing Prod
echo. && echo BI

call :test_service_state server1271 "IBM Cognos" RUNNING
call :test_service_state server1272 "IBM Cognos" RUNNING
call :test_service_state server5717 "IBM Cognos" RUNNING
call :test_service_state server1273 "IBM Cognos" RUNNING
call :test_service_state server1274 "IBM Cognos" RUNNING

echo. && echo Planning
call :test_service_state server5716 "IBM Cognos 10 Planning" RUNNING
call :test_service_state server5716 "IBM Cognos 1011 Prod Planning:9303" RUNNING
call :test_service_state server1250 "IBM Cognos 10 Planning" RUNNING
call :test_service_state server1251 "IBM Cognos 10 Planning" RUNNING
call :test_service_state server1252 "IBM Cognos 10 Planning" RUNNING
call :test_service_state server1276 "IBM Cognos 10 Planning" RUNNING
call :test_service_state server5750 "IBM Cognos 10 Planning" RUNNING
call :test_service_state server1250 "IBM Cognos 1011 Prod Planning" RUNNING
call :test_service_state server1251 "IBM Cognos 1011 Prod Planning" RUNNING
call :test_service_state server1252 "IBM Cognos 1011 Prod Planning" RUNNING
call :test_service_state server1276 "IBM Cognos 1011 Prod Planning" RUNNING
call :test_service_state server5750 "IBM Cognos 1011 Prod Planning" RUNNING
pause
exit /B



:: Modular functions

:stop_service
::  	call :stop_service	computername	servicename

echo.
echo Action: STOP %2 on %1 at !time:~0,8!
call :test_service_state %1 %2 RUNNING
if !service_state!==RUNNING (
	echo Sending STOP command to %1
	sc \\%1 stop %2 > nul
	)
exit /B
goto :EOF


:start_service
::  	call :start_service	computername	servicename

echo.
echo Action: Start %2 on %1 at !time:~0,8!
REM	Check the event viewer is running, and hence the server is up
call :test_service_state %1 "eventlog" RUNNING
if !service_state!==NOT_RUNNING (
	echo Error: Event Viewer is not running. %1 may be down.
	exit /B
	) else (
	REM	Check if service is already running
	call :test_service_state %1 %2 RUNNING
	if !service_state!==NOT_RUNNING (
		echo Action: Sending START comamnd at !time:~0,8!
		sc \\%1 start %2 > nul
		) else (
		echo Result: Already Running
		)
	)
exit /B
goto :EOF


:test_service_state
:: test a remote service to see if it is in a specified state
:: usage
::  	call :test_service_state 	computername	servicename	desired_state
::	desired_state is either "RUNNING" or "STOPPED"

:: first test permissions to use SC on remote host

sc \\%1 query %2 > nul
if !ERRORLEVEL!==5 (
	echo.
	echo =========================================================
	echo Insuffient Permissions on %1&& echo.
	echo Run this script from an account with permissions && echo to remotely view services on %1
	echo. && echo =========================================================
	exit /B
	)

SET /P echo_status_dot=Test: Is %2 %3 on %1 ? <NUL
sc \\%1 query %2 | FIND "%3" > NUL 
if !ERRORLEVEL!==0 (
	set service_state=%3
	echo [%3]
	) else (
	set service_state=NOT_%3
	echo [NOT %3]
	)
exit /B


:wait_service_state
:: test a remote service and keep retrying until it is in specified state
:: usage
::  	call :wait_service_state 	computername	servicename	desired_state
::	desired_state is either "RUNNING" or "STOPPED"

set wait_service_count=0
set service_wait=INIT

SET /P echo_status_dot=Wait: %2 to be %3 on %1 <NUL

:wait_service_loop
:: Timeout is 180 x 5 pings which is roughly 900 seconds or 15 minutes.
if !wait_service_count! GEQ 180 (
	echo.
	echo ERROR: TIMED OUT waiting for %2 to be %3 on %1
	set service_wait=FAIL
	echo.
	exit /B
	)

:: counter for number of iterations
set /A wait_service_count = wait_service_count + 1

:: test current state of service
sc \\%1 query %2 | FIND "%3" > nul
if !ERRORLEVEL!==0 (
	echo . [done]
	set service_wait=PASS
	exit /B
	) else (
	SET /P echo_status_dot=.<NUL
	ping 127.0.0.1 -n 5 > nul
	goto :wait_service_loop
	)
exit /B


:test_and_wait_for_incremental_publish
set wait_publish_count=0
set publish_wait=INIT

SET /P echo_status_dot=Wait: Pricing Tool Incremental Publish to be not running <NUL

:wait_publish_loop
:: Timeout is 180 x 5 pings which is roughly 900 seconds or 15 minutes.
if !wait_publish_count! GEQ 180 (
	echo.
	echo ERROR: TIMED OUT waiting for Incremental Publish to be not running.
	set publish_wait=FAIL
	echo.
	goto :EOF
	)

:: counter for number of iterations
set /A wait_publish_count = wait_publish_count + 1

:: test current state of publish
if not exist "\\server5716\AnalystLibs\Log files\0_prc_tool_inc_logs\0_inc_publish_running.YES" (
	echo . [done]
	set publish_wait=PASS
	exit /B
	) else (
	SET /P echo_status_dot=.<NUL
	ping 127.0.0.1 -n 5 > nul
	goto :wait_publish_loop
	)
exit /B


:EOF
Tags: ,

0 Comments

You can be the first one to leave a comment.

Leave a Comment