#!/usr/bin/env python import os # Base package import sys # Low level system IO import BaseHTTPServer # Implements a simple web server import CGIHTTPServer # Used to run CGI scripts import commands # Used for running commands in terminal class CCGIRequestHandler( CGIHTTPServer.CGIHTTPRequestHandler ): pass ################################################################################ # Starts the HTTP server # def runServer(): # Fork and kill the parent if os.fork(): sys.stderr.flush() sys.stdout.flush() os._exit( 0 ) # Change the port according to the requirement serverPort = 8001 serverAddress = ( '', serverPort ) httpServer = BaseHTTPServer.HTTPServer( serverAddress, CCGIRequestHandler ) print '[I] HTTP Server started. Serving at port ', serverPort httpServer.serve_forever() ################################################################################ # Kills the running server # def killServer(): retStatus, output = commands.getstatusoutput( 'ps | grep ServerCon' ) lines = output.splitlines() # This required as we'd have lineOfConcern = lines[0] # 2 instances of this crap running temp = lineOfConcern.split( ' ' ) idToKill = temp[0] killCommand = 'kill -9 ' + idToKill retStatus, output = commands.getstatusoutput( killCommand ) if ( retStatus == 0 ): print '[I]Server committed suicide...' else: print '[E]Cannot kill server. Manually kill it yourself' ################################################################################ # Prints to console whether the server is running or not # def reportStatus(): retStatus, output = commands.getstatusoutput( 'ps | grep ServerCon' ) lines = output.splitlines() # This required as we'd have if ( len( lines ) > 2 ): print '[I]More than one instance of server running. Check' elif ( len( lines ) == 2 ): print '[I]Server running' else: print '[I]Server not running' ################################################################################ # Main entry point # if __name__ == "__main__": print " HTTP Server Control script" print " What do you want to do ?" print " [ 1 ] Start Server" print " [ 2 ] Shutdown server" print " [ 3 ] Check status of server" option = raw_input( " Enter your option : " ) if ( option == '1' ): print 'You selected option [1]. Starting server' runServer() elif ( option == '2' ): print 'You selected option [2]. Shutting down server' killServer() elif ( option == '3' ): print 'You selected option [3]. Checking status of server' reportStatus() else: print '[E]Invalid option, try again'
--------------------------------------------------------------------- The official User-To-User support forum of the Apache HTTP Server Project. See <URL:http://httpd.apache.org/userslist.html> for more info. To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx " from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx