Managing ColdFusion and Database Services Through Batch Scripting
Managing ColdFusion Application Services » Does StartUp Need So Many Steps? No.
Some time last year I realized the need to manage the application development services running simultaneously on my dev box. On my main box I'm running ColdFusion 8 on IIS 7, MySQL, MSSQL, and a WAMP setup as well. So when the need arose to manage which services were running, I would previously had called up an MMC snap-in and manually cranked up the required ColdFusion services; the MySQL or MSSQL database services and finally the sites I needed running on IIS - ad hoc. A good portion of my daily work schedule was getting consumed going back and forth to my MMC console.
Managing StartUp Services with Batch Scripting
I created a simple batch script to either crank up or shut down ColdFusion as needed and then I put a shortcut in a directory under c:\ where the shortcut would be accessible to my computer's PATH variables. This way I can get even lazier by just running my batch script by typing Win Key + R - enter my batch script shortcut name which is uniquely named "CF" and hitting enter ... Having the shortcut has been really convenient. However, there were some issues with my batch script. Namely, if ColdFusion or a database service were already running and I tried to start them ... Windows would throw help message 1282 - The requested service has already been started. So, I needed to clean up my batch script by testing for the running services first. I also added a call to open a separate cmd window with the status the development services in question. Below is my new and improved batch script - Again, uniquely titled - Dev Cranker. Very Unique - Almost brandable.
TITLE --- Dev Cranker ---
@ECHO OFF
REM - THIS IS A FILE TO MANAGE DEVLOPMENT ... HI
SETLOCAL ENABLEDELAYEDEXPANSION
:BEGIN
IF EXIST CODE.TXT DEL CODE.TXT
SET MySQL=MySQL
SET CF1= "ColdFusion 8 .NET Service"
SET CF2= "ColdFusion 8 ODBC Agent"
SET CF3= "ColdFusion 8 ODBC Server"
SET CF4= "ColdFusion 8 Application Server"
SET SBR= "SQL Browser"
SET MSSQL= "MSSQL$SQLEXPRESS"
ECHO.
SC QUERY %CF1% |FINDSTR "SERVICE_NAME"> CODE.TXT
ECHO.
SC QUERY %CF1% |FINDSTR "DISPLAY_NAME STATE" >> CODE.TXT
ECHO.
SC QUERY %CF2% |FINDSTR "SERVICE_NAME" >> CODE.TXT
ECHO.
SC QUERY %CF2% |FINDSTR "DISPLAY_NAME STATE" >> CODE.TXT
ECHO.
SC QUERY %CF3% |FINDSTR "SERVICE_NAME" >> CODE.TXT
ECHO.
SC QUERY %CF3% |FINDSTR "DISPLAY_NAME STATE" >> CODE.TXT
ECHO.
SC QUERY %CF4% |FINDSTR "SERVICE_NAME" >> CODE.TXT
ECHO.
SC QUERY %CF4% |FINDSTR "DISPLAY_NAME STATE" >> CODE.TXT
SC QUERY %MySQL% |FINDSTR "SERVICE_NAME" >> CODE.TXT
ECHO.
SC QUERY %MySQL% |FINDSTR "DISPLAY_NAME STATE" >> CODE.TXT
ECHO.
SC QUERY %SBR% |FINDSTR "SERVICE_NAME" >> CODE.TXT
ECHO.
SC QUERY %SBR% |FINDSTR "DISPLAY_NAME STATE" >> CODE.TXT
ECHO.
SC QUERY %MSSQL% |FINDSTR "SERVICE_NAME" >> CODE.TXT
ECHO.
SC QUERY %MSSQL% |FINDSTR "DISPLAY_NAME STATE" >> CODE.TXT
ECHO.
START "DEV CRANKER II --- SERVICE STATE " TYPE CODE.TXT
:ZERO
CLS
ECHO.
ECHO ====================================================================================================
ECHO.
ECHO Dev Cranker ...
ECHO
ECHO ====================================================================================================
ECHO.
ECHO 1. Start ColdFusion
ECHO 2. Stop ColdFusion
ECHO 3. Start a Database
ECHO 4. Stop a Database
ECHO 5. Quit and Exit
ECHO.
ECHO What Do You Want To Do?
ECHO ====================================================================================================
CHOICE "/C:12345"
ECHO ====================================================================================================
IF ERRORLEVEL ==5 GOTO NINE
IF ERRORLEVEL ==4 GOTO SIX
IF ERRORLEVEL ==3 GOTO TWO
IF ERRORLEVEL ==2 GOTO FIVE
IF ERRORLEVEL ==1 GOTO ONE
:TEN
ECHO ====================================================================================================
ECHO Good Bye! ...
ECHO Dev Cranker ...
SLEEP 3
GOTO END
:NINE
ECHO ====================================================================================================
ECHO.
ECHO Finished?
ECHO.
ECHO ====================================================================================================
CHOICE "/C:YN"
ECHO ====================================================================================================
IF ERRORLEVEL ==2 GOTO ZERO
IF ERRORLEVEL ==1 GOTO TEN
:EIGHT
SC QUERY %Mysql% |FIND /i "RUNNING" >> code.txt
IF !ERRORLEVEL! NEQ 1 (
SC STOP %Mysql% >> code.txt
ECHO %Mysql% Is Winding Down ...
) ELSE (
ECHO %Mysql% Isn't Running ...
)GOTO NINE
:SEVEN
SC QUERY %SBR% |FIND /i "RUNNING" >> code.txt
IF !ERRORLEVEL! NEQ 1 (
SC STOP %SBR% >> code.txt
ECHO %SBR% Is Winding Down ...
) ELSE (
ECHO %SBR% Isn't Running ...
)SC QUERY %MSSQL% |FIND /i "RUNNING" >> code.txt
IF !ERRORLEVEL! NEQ 1 (
SC STOP %MSSQL% >> code.txt
ECHO %MSSQL% Is Winding Down ...
) ELSE (
ECHO %MSSQL% Isn't Running ...
)
GOTO NINE
:SIX
ECHO ====================================================================================================
ECHO.
ECHO 1. MSSQL (Exp)
ECHO 2. MySql
ECHO 3. Just Exit (N/A)
ECHO ====================================================================================================
ECHO Which Database Are You Stopping?
ECHO ====================================================================================================
CHOICE "/C:123"
IF ERRORLEVEL ==3 GOTO NINE
IF ERRORLEVEL ==2 GOTO EIGHT
IF ERRORLEVEL ==1 GOTO SEVEN
EXIT
:FIVE
SC QUERY %CF1% |FIND /i "RUNNING" >> code.txt
IF !ERRORLEVEL! NEQ 1 (
SC STOP %CF1% >> code.txt
ECHO %CF1% Is Winding Down ...
) ELSE (
ECHO %CF1% Isn't Running ...
)
SC QUERY %CF2% |FIND /i "RUNNING" >> code.txt
IF !ERRORLEVEL! NEQ 1 (
SC STOP %CF2% >> code.txt
ECHO %CF2% Is Winding Down ...
) ELSE (
ECHO %CF2% Isn't Running ...
)
SC QUERY %CF3% |FIND /i "RUNNING" >> code.txt
IF !ERRORLEVEL! NEQ 1 (
SC STOP %CF3% >> code.txt
ECHO %CF3% Is Winding Down ...
) ELSE (
ECHO %CF3% Isn't Running ...
)
SC QUERY %CF4% |FIND /i "RUNNING" >> code.txt
IF !ERRORLEVEL! NEQ 1 (
SC STOP %CF4% >> code.txt
ECHO %CF4% Is Winding Down ...
) ELSE (
ECHO %CF4% Isn't Running ...
)
GOTO NINE
ECHO ====================================================================================================
ECHO.
ECHO Need To Stop a DataBase?
ECHO.
ECHO ====================================================================================================
CHOICE "/C:YN"
IF ERRORLEVEL ==2 GOTO NINE
IF ERRORLEVEL ==1 GOTO SIX
:FOUR
SC QUERY %Mysql% |FIND /i "RUNNING" >> code.txt
IF !ERRORLEVEL! NEQ 0 (
SC START %Mysql% >> code.txt
ECHO %Mysql% Is Cranking Up ...
) ELSE (
ECHO %Mysql% Is Already Cranked Up ...
)
GOTO NINE
:THREE
SC QUERY %SBR% |FIND /i "RUNNING" >> code.txt
IF !ERRORLEVEL! NEQ 0 (
SC START %SBR% >> code.txt
ECHO %SBR% Is Cranking Up ...
) ELSE (
ECHO %SBR% Is Already Cranked Up ...
)
SC QUERY %MSSQL% |FIND /i "RUNNING" >> code.txt
IF !ERRORLEVEL! NEQ 0 (
SC START %MSSQL% >> code.txt
ECHO %MSSQL% Is Cranking Up ...
) ELSE (
ECHO %MSSQL% Is Already Cranked Up ...
)
GOTO NINE
:TWO
CHO ====================================================================================================
ECHO.
ECHO 1. MSSQL (Exp)
ECHO 2. MySql
ECHO 3. Just Exit (N/A)
ECHO.
ECHO Which Database Are You Cranking Up?
ECHO ====================================================================================================
CHOICE "/C:123"
IF ERRORLEVEL ==3 GOTO NINE
IF ERRORLEVEL ==2 GOTO FOUR
IF ERRORLEVEL ==1 GOTO THREE
:ONE
SC QUERY %CF1% |FIND /i "RUNNING" > code.txt
IF !ERRORLEVEL! NEQ 0 (
SC START %CF1% >> code.txt
ECHO %CF1% Is Firing Up ...
) ELSE (
ECHO %CF1% Is Already Cranked Up ...
)SC QUERY %CF2% |FIND /i "RUNNING" >> code.txt
IF !ERRORLEVEL! NEQ 0 (
SC START %CF2% >> code.txt
ECHO %CF2% Is Firing Up ...
) ELSE (
ECHO %CF2% Is Already Cranked Up ...
)
SC QUERY %CF3% |FIND /i "RUNNING" >> code.txt
IF !ERRORLEVEL! NEQ 0 (
SC START %CF3% >> code.txt
ECHO %CF3% Is Firing Up ...
) ELSE (
ECHO %CF3% Is Already Cranked Up ...
)
SC QUERY %CF4% |FIND /i "RUNNING" >> code.txt
IF !ERRORLEVEL! NEQ 0 (
SC START %CF4% >> code.txt
ECHO %CF4% Is Firing Up ...
) ELSE (
ECHO %CF4% Is Already Cranked Up ...
ECHO.
)
ECHO ====================================================================================================
ECHO.
ECHO Need Data?
ECHO.
ECHO ====================================================================================================
CHOICE "/C:YN"
IF ERRORLEVEL ==2 GOTO NINE
IF ERRORLEVEL ==1 GOTO TWO
:END
If any one has some suggestions here - Feel free to share your opinion - This is one of the first batch scripts I've created so I'm sure there could improvements ... That's it.







I hate to be a buzz kill but in my book there really isn't anything exciting about ... data. Maybe if some hot naked blonde was presenting it to me ... I might be a bit more interested ... but that doesn't happen ... everyday. Now don't get me wrong, there are some great software applications that display visual depictions of rankings, conversions, click-patterns, visitor trending and heat maps, in uber cool Flash and Flex applications or snazzy charting and graphics, but the only thing these visuals are representing is data. That's it.
I had to keep what I could use everyday and leave the rest for later. So, that got me looking in to some GTD solutions ... more stuff to learn ... but, this time the learning was definitely worth it.















Managing ColdFusion and Database Services Through Batch Scripting
Edward Beckett said: It took me a while to figure out just how you determined what OS I was on ... But, for the record .... [More]