Sunday, December 28, 2008

Scripts to restart apache/mysql in windows

Currently I am working on 2 projects. both projects involves Apache and Mysql. but configuration used for each project is different and one project is using WAMP. So I was needed to start and stop services to switch between projects I am working. it was becoming quite tedious. so I tried to write a scripts to restart services whenever I was going to switch between projects. I am linux guy so like writing scripts but was new to writing script for restarting services on windows.
following are the scripts to start the services..

A.bat

sc stop Apache2
sc stop MySQL
pause
sc start wampapache
sc start wampmysqld


B.bat

sc stop wampapache
sc stop wampmysqld
pause
sc start Apache2
sc start MySQL


I first started using actually executables from bin directories from respective apps. but It was not working for stopping the service.

I used pause because didnt find sleep command on windows. these scripts I wrote using whatever help I got from windows help service. as I was working from home without internet.

if sc start/stop says service is not installed then you can install the service.
sc install servicename.

you have any better ways of doing this things let me know.

No comments: