Rev 4651 | Blame | Compare with Previous | Last modification | View Log | RSS feed
'''Created on 25-Mar-2010@author: ashish'''import optparseimport sysimport osif __name__ == '__main__' and __package__ is None:sys.path.insert(0, os.getcwd())from thrift.transport import TSocket, TTransportfrom thrift.protocol.TBinaryProtocol import TBinaryProtocolFactoryfrom thrift.server import TServerfrom shop2020.utils.daemon import Daemonfrom shop2020.config.client.ConfigClient import ConfigClientfrom shop2020.thriftpy.model.v1.catalog import CatalogServicefrom shop2020.model.v1.catalog.impl.CatalogServiceHandler import CatalogServiceHandlerclass CatalogServer(Daemon):def __init__(self, logfile='/var/log/services/catalog.log', pidfile='/tmp/catalog-server.pid'):Daemon.__init__(self, pidfile, stdout=logfile, stderr=logfile)def run(self):config_client = ConfigClient()host_name = config_client.get_property('catalog_service_server_host')port = config_client.get_property('catalog_service_server_port')dbname = config_client.get_property('catalog_service_dbname')db_hostname = config_client.get_property('catalog_service_db_hostname')handler = CatalogServiceHandler(dbname, db_hostname)processor = CatalogService.Processor(handler)transport = TSocket.TServerSocket(port=port)tfactory = TTransport.TFramedTransportFactory()pfactory = TBinaryProtocolFactory()server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)print "Starting CatalogService at, port " + str(port) + " host " + host_namesys.stdout.flush()server.serve()print "Server functioning"if __name__ == "__main__":parser = optparse.OptionParser()parser.add_option("-l", "--logfile", dest="logfile",type="string",help="Log all output to LOG_FILE",)parser.add_option("-i", "--pidfile", dest="pidfile",type="string",help="Write the PID to pidfile")(options, args) = parser.parse_args()daemon = CatalogServer(options.logfile, options.pidfile)if len(args) == 0:daemon.run()elif len(args) == 1:if 'start' == args[0]:daemon.start()elif 'stop' == args[0]:daemon.stop()elif 'restart' == args[0]:daemon.restart()else:print "Unknown command"sys.exit(2)sys.exit(0)else:print "usage: %s start|stop|restart" % sys.argv[0]sys.exit(2)