Scott Stroz (who's always up for a round of golf) today asked How Do You Set Up Your Development Environment? In his article, he has an excellent tip for restarting your local install of Apache using an Ant script. This is a great tip and something I quite frankly never thought to do.
But what if you're using Windows and want to stop a service on remote server?
Fortunately Microsoft has included a command line tool called sc.exe which handles things like stopping and starting services remotely. (The sc.exe command line application should come with Windows XP, but is also available in the Windows Resource Kits.)
Here's an XML script to restart IIS under Windows:
NOTE:Change the {SERVER_NAME} to the actual IP or server name of the remote computer you want to restart the web server on.
If you're using Apache v2.x, like Scott is, just replace the "W3SVC" argument with "Apache2". You can use this same setup to stop/start any service you like.
To run the script, simply save the file as an XML file in a project (I suggest putting all ANT scripts in a subfolder in your project titled "build" or "ant".) Once you've saved the file to your project, just right-click on the file and select Run As > Ant Build.
If you have problems running this script, just remember that the account your using must have the correct permissions to start/stop services on the remote computer.
3 Comments
Comments for this entry have been disabled.