1 | #!/usr/bin/env python |
---|
2 | """A very simple example of a server. |
---|
3 | |
---|
4 | @author Stephen pascoe |
---|
5 | """ |
---|
6 | |
---|
7 | import sys, os, syslog, stat, time, signal |
---|
8 | from glob import glob |
---|
9 | import re, tempfile, getopt |
---|
10 | |
---|
11 | import logging |
---|
12 | logging.basicConfig(level=logging.DEBUG, filename='./bbftpd.log') |
---|
13 | logger = logging.getLogger('ndg.delivery.server') |
---|
14 | |
---|
15 | import ndg.delivery.server.pybbftp as server |
---|
16 | from ndg.delivery.common.auth_plugin import * |
---|
17 | |
---|
18 | |
---|
19 | print ''' |
---|
20 | =================================== |
---|
21 | NDG Delivery Service example server |
---|
22 | =================================== |
---|
23 | ''' |
---|
24 | |
---|
25 | def after_fork_hook(): |
---|
26 | logging.root.handlers = [] |
---|
27 | logging.basicConfig(level=logging.DEBUG, filename='./bbftpd.log') |
---|
28 | logger.info('Called after_fork_hook') |
---|
29 | |
---|
30 | logfile = './bbftpd.log' |
---|
31 | n = len(open(logfile).readlines()) |
---|
32 | c = server.ServerConnector() |
---|
33 | pid = server.start(AuthHandler(c), ['-l', 'DEBUG']) |
---|
34 | print 'Server process started at pid = %d' % pid |
---|
35 | print 'Monitoring %s' % logfile |
---|
36 | |
---|
37 | try: |
---|
38 | while 1: |
---|
39 | newlines = open(logfile).readlines()[n:] |
---|
40 | n += len(newlines) |
---|
41 | for line in newlines: |
---|
42 | print line, |
---|
43 | time.sleep(2) |
---|
44 | except: |
---|
45 | os.kill(pid, signal.SIGTERM) |
---|
46 | print 'Server process killed' |
---|