| 115 |
ashish |
1 |
'''
|
|
|
2 |
Created on 06-Apr-2010
|
|
|
3 |
|
|
|
4 |
@author: ashish
|
| 3915 |
chandransh |
5 |
@author: Chandranshu
|
| 115 |
ashish |
6 |
'''
|
| 3915 |
chandransh |
7 |
import optparse
|
|
|
8 |
import sys
|
|
|
9 |
import os
|
|
|
10 |
|
|
|
11 |
if __name__ == '__main__' and __package__ is None:
|
|
|
12 |
sys.path.insert(0, os.getcwd())
|
|
|
13 |
|
| 115 |
ashish |
14 |
from thrift.transport import TSocket, TTransport
|
|
|
15 |
from thrift.protocol.TBinaryProtocol import TBinaryProtocolFactory
|
|
|
16 |
from thrift.server import TServer
|
| 3915 |
chandransh |
17 |
|
|
|
18 |
from shop2020.utils.daemon import Daemon
|
|
|
19 |
from shop2020.model.v1.order.impl.OrderServiceHandler import OrderServiceHandler
|
|
|
20 |
from shop2020.thriftpy.model.v1.order import TransactionService
|
| 115 |
ashish |
21 |
from shop2020.config.client.ConfigClient import ConfigClient
|
|
|
22 |
|
| 3915 |
chandransh |
23 |
class TransactionServer(Daemon):
|
|
|
24 |
|
|
|
25 |
def __init__(self, logfile='/var/log/services/order.log', pidfile='/tmp/transaction-server.pid'):
|
|
|
26 |
Daemon.__init__(self, pidfile, stdout=logfile, stderr=logfile)
|
| 115 |
ashish |
27 |
|
| 3915 |
chandransh |
28 |
def run(self):
|
| 4651 |
rajveer |
29 |
|
|
|
30 |
config_client = ConfigClient()
|
|
|
31 |
host_name = config_client.get_property('transaction_service_server_host')
|
|
|
32 |
port = config_client.get_property('transaction_service_server_port')
|
|
|
33 |
dbname = config_client.get_property('transaction_service_dbname')
|
|
|
34 |
db_hostname = config_client.get_property('transaction_service_db_hostname')
|
| 3915 |
chandransh |
35 |
|
|
|
36 |
handler = OrderServiceHandler(dbname, db_hostname)
|
|
|
37 |
processor = TransactionService.Processor(handler)
|
|
|
38 |
transport = TSocket.TServerSocket(port=port)
|
|
|
39 |
tfactory = TTransport.TFramedTransportFactory()
|
|
|
40 |
pfactory = TBinaryProtocolFactory()
|
|
|
41 |
server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
|
|
|
42 |
print "Starting Transaction Service at, port " + str(port) + " host " + host_name
|
|
|
43 |
sys.stdout.flush()
|
|
|
44 |
server.serve()
|
|
|
45 |
print "Server functioning"
|
| 115 |
ashish |
46 |
|
| 3915 |
chandransh |
47 |
if __name__ == "__main__":
|
|
|
48 |
parser = optparse.OptionParser()
|
|
|
49 |
parser.add_option("-l", "--logfile", dest="logfile",
|
|
|
50 |
type="string",
|
|
|
51 |
help="Log all output to LOG_FILE",
|
|
|
52 |
)
|
|
|
53 |
parser.add_option("-i", "--pidfile", dest="pidfile",
|
|
|
54 |
type="string",
|
|
|
55 |
help="Write the PID to pidfile")
|
|
|
56 |
(options, args) = parser.parse_args()
|
|
|
57 |
daemon = TransactionServer(options.logfile, options.pidfile)
|
|
|
58 |
if len(args) == 0:
|
|
|
59 |
daemon.run()
|
|
|
60 |
elif len(args) == 1:
|
|
|
61 |
if 'start' == args[0]:
|
|
|
62 |
daemon.start()
|
|
|
63 |
elif 'stop' == args[0]:
|
|
|
64 |
daemon.stop()
|
|
|
65 |
elif 'restart' == args[0]:
|
|
|
66 |
daemon.restart()
|
|
|
67 |
else:
|
|
|
68 |
print "Unknown command"
|
|
|
69 |
sys.exit(2)
|
|
|
70 |
sys.exit(0)
|
|
|
71 |
else:
|
|
|
72 |
print "usage: %s start|stop|restart" % sys.argv[0]
|
|
|
73 |
sys.exit(2)
|