-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathp.haul-service
executable file
·49 lines (36 loc) · 1.04 KB
/
p.haul-service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
import sys
import signal
import logging
import phaul.args_parser
import phaul.util
import phaul.xem_rpc
import phaul.service
import phaul.connection
def fin(foo, bar):
global stop_fd
logging.info("Stop by %d", foo)
stop_fd.close()
# Parse arguments
args = phaul.args_parser.parse_service_args()
# Configure logging
logging.basicConfig(filename=args.log_file, filemode="a", level=logging.INFO,
format="%(asctime)s.%(msecs)03d: %(process)d: %(message)s",
datefmt="%H:%M:%S")
# Setup hook to log uncaught exceptions
sys.excepthook = phaul.util.log_uncaught_exception
phaul.util.log_header()
logging.info("Starting p.haul service")
# Establish connection
connection = phaul.connection.establish(args.fdrpc, args.fdmem, args.fdfs)
t = phaul.xem_rpc.rpc_threaded_srv(phaul.service.phaul_service, connection)
# FIXME: Setup stop handlers
stop_fd = t.init_stop_fd()
signal.signal(signal.SIGTERM, fin)
signal.signal(signal.SIGINT, fin)
t.start()
signal.pause()
t.join()
logging.info("Bye!")
# Close connection
connection.close()