IPB

Welcome Guest ( Log In | Register )



Tags
This content has not been tagged yet
 
Reply to this topicStart new topic

Starting Or Stopping Apache And Mysql Server Via Batch File


masterio
no avatar
Newbie [Level 3]
***
Group: Members
Posts: 49
Joined: 25-August 06
Member No.: 28,897



Post #1 post Sep 22 2006, 02:14 PM
Hi guys, this is a litte tutorial about how we start and stop the Apache and MySQL in Windows NT (2000, XP, 2003) via a batch file script.

As we know in Windows NT based system Apache and MySQL installed as Windows Services. So we can stop and start it using NET command.

For more information about DOS command, type HELP at command prompt. I assuming that your MySQL service name is "mysql" and your Apache (Apache 2.0.x) service name is "apache2". If you want to chek it click Start > Run > services.msc > OK. Windows IS NOT Case Sensitive. Let's get started!.

1. Open your command prompt by clicking Start > Run > cmd > OK
2. Type edit then press ENTER to start the EDIT program.
3. Type code below

CODE
@ECHO OFF

if "%1"=="start" goto start_server
if "%1"=="stop"  goto stop_server
if "%1"=="" goto begin

:begin
TITLE ::BATCH SCRIPT::
ECHO ----------------------------------------------------------------------------------
ECHO USAGE OF THIS SCRIPT:
ECHO server.bat option1 [option2]
ECHO WHERE option1 = start/stop (start or stopping server)
ECHO      option2 = yes/no (close the command prompt or not [optional])
ECHO -----------------------------------------------------------------------------------
goto end

:start_server
TITLE ACTIVATING SERVER...
ECHO =================================================
ECHO       BATCH SCRIPT FOR ACTIVATING SERVER
ECHO    By Rio Astamal (masterio.trap17.com)
ECHO =================================================
ECHO _
ECHO Activating MySQL Service . . .
@NET START mysql
ECHO _
ECHO Activating Apache HTTP Server Service. . .
@NET START apache2
ECHO _
ECHO SERVER HAS BEEN STARTED!
DATE /T
TIME /T
goto end

:stop_server
TITLE STOPPING SERVER...
ECHO ==================================================
ECHO       BATCH SCRIPT FOR STOPPING SERVER
ECHO    By Rio Astamal (masterio.trap17.com
ECHO ==================================================
ECHO _
ECHO Stopping Apache HTTP Server Service...
@NET STOP apache2
ECHO _
ECHO Stopping MySQL Service. . .
@NET STOP
ECHO SERVER HAS BEEN SHUTTING DOWN!
DATE /T
TIME /T
goto end

:end
if "%2"=="yes" (
  exit
)


To save the file:
1. Press ALT-F > Save
2. Go to your Windows Directory, so we can start it from anywhere in command prompt
3. OK

Usage:
C:\>server.bat (to show the usage of the script)
C:\>server.bat stop yes (close the command prompt after finished the task)
C:\>server.bat start

EXPLAINATION:
If you create a batch file, Anything inside it is assumed as DOS command by command prompt. In that script, first, we make the ECHO command invisible by using @ECHO OFF command. Then we check the argument given by user. %1 is argument 1, %2 is argument 2 and so on. We use first argument(%1) to check what user want. Is he want to stop/start the server. We use argument2 (%2) to check wheter we close the command prompt or not after it.

TITLE is used for changing the title of command prompt title bar. For starting service We can use NET START [service_name]. In our script we use @NET START to prevent DOS for echoing the command. For stopping service we can use NET STOP [service_name].

SUMMARY
With a batch file we can do alot of thing not just stop/starting service. But we can use it for renaming many files at once, deleting temporer directory and many more. For more tutorial you can googling!!.

ENJOY...! biggrin.gif
Go to the top of the page
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No new   30 chelcy 14,559 11th September 2007 - 10:03 AM
Last post by: .hack//GU
No New Posts   0 OpaQue 17,183 9th September 2004 - 08:40 AM
Last post by: OpaQue
No New Posts 3 chalawanonline 6,269 2nd August 2004 - 02:34 PM
Last post by: Spectre
No New Posts   6 outwarsecrets 10,682 27th October 2009 - 08:09 AM
Last post by: NxTGaming
No New Posts   9 Panzer 2,653 4th January 2007 - 08:52 PM
Last post by: fffanatics
No New Posts   7 Raptrex 13,188 27th August 2004 - 11:16 PM
Last post by: Spectre
No New Posts   8 -Pandemonium- 9,300 25th August 2004 - 04:00 PM
Last post by: -Pandemonium-
No New Posts 3 NuHoaXuLa 9,219 17th November 2006 - 08:33 AM
Last post by: farsiscript
No New Posts 4 NuHoaXuLa 6,230 29th August 2004 - 03:12 AM
Last post by: NuHoaXuLa
No New Posts 5 BoSZ 10,306 8th January 2009 - 07:35 PM
Last post by: Arthur Dent
No New Posts   11 Triple X 6,339 5th September 2004 - 02:33 AM
Last post by: Triple X
No New Posts   4 Schweden 4,967 8th September 2004 - 09:40 AM
Last post by: Schweden
No New Posts 6 dozen 4,653 9th September 2004 - 11:58 PM
Last post by: Triple X
No New Posts   4 annylei 4,651 14th September 2004 - 09:38 PM
Last post by: Triple X
No New Posts   0 sekundar 1,548 26th July 2006 - 07:35 AM
Last post by: sekundar


 



RSS Open Discussion Time is now: 8th November 2009 - 11:28 AM

Web Hosting Powered by ComputingHost.com.