| 94 |
ashish |
1 |
'''
|
|
|
2 |
Created on 23-Feb-2010
|
|
|
3 |
|
|
|
4 |
@author: ashish
|
|
|
5 |
'''
|
|
|
6 |
import sys
|
|
|
7 |
from getopt import getopt, GetoptError
|
|
|
8 |
from shop2020.config.impl.ConfigServerHandler import ConfigServerHandler
|
|
|
9 |
from thrift.protocol.TBinaryProtocol import TBinaryProtocolFactory
|
|
|
10 |
from shop2020.thriftpy.config import Configuration
|
|
|
11 |
from thrift.transport import TSocket, TTransport
|
|
|
12 |
from thrift.server import TServer
|
|
|
13 |
|
|
|
14 |
port = 9999
|
|
|
15 |
cfg_file_name = '/tmp/shop2020.cfg'
|
|
|
16 |
|
|
|
17 |
def main(argv):
|
|
|
18 |
|
|
|
19 |
try:
|
|
|
20 |
opts, args = getopt(argv,"p:f:", ["port=", "file="])
|
|
|
21 |
except GetoptError:
|
|
|
22 |
usage()
|
|
|
23 |
sys.exit(2)
|
|
|
24 |
|
|
|
25 |
for opt,arg in opts:
|
|
|
26 |
if opt in ('-p', "--port"):
|
|
|
27 |
port = arg;
|
|
|
28 |
elif opt in ('-f', "--file"):
|
|
|
29 |
cfg_file_name = arg
|
|
|
30 |
|
|
|
31 |
start_server()
|
|
|
32 |
|
|
|
33 |
def start_server():
|
|
|
34 |
handler = ConfigServerHandler(cfg_file_name)
|
|
|
35 |
processor = Configuration.Processor(handler)
|
|
|
36 |
transport = TSocket.TServerSocket(port)
|
|
|
37 |
tfactory = TTransport.TFramedTransportFactory()
|
|
|
38 |
pfactory = TBinaryProtocolFactory()
|
|
|
39 |
server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
|
|
|
40 |
print "Starting config server with config params, port "+ str(port)+" file "+cfg_file_name
|
|
|
41 |
server.serve()
|
|
|
42 |
print "Server functioning"
|
|
|
43 |
|
|
|
44 |
def usage():
|
|
|
45 |
print 'Usage: ConfigServer.py -p <port_to_run> -f <config_file_path> or ConfigServer.py --port=<port_to_run> --file=<config_file_path>'
|
|
|
46 |
|
|
|
47 |
if __name__ == '__main__':
|
|
|
48 |
main(sys.argv[1:])
|
|
|
49 |
|