24.1.2
by robey
use python2.4 from the env, not mac-style :) |
1 |
#!/usr/bin/env python2.4
|
89
by Robey Pointer
fix up dev.cfg so that nobody will ever have to edit it, by letting the |
2 |
|
1
by Robey Pointer
initial checkin |
3 |
import pkg_resources |
4 |
pkg_resources.require("TurboGears") |
|
5 |
||
93
by Robey Pointer
slight cleanup, and add '-f' option for running in the foreground. |
6 |
import logging |
89
by Robey Pointer
fix up dev.cfg so that nobody will ever have to edit it, by letting the |
7 |
import os |
8 |
||
1
by Robey Pointer
initial checkin |
9 |
import turbogears |
10 |
import cherrypy |
|
11 |
cherrypy.lowercase_api = True |
|
12 |
||
13 |
import sys |
|
14 |
||
93
by Robey Pointer
slight cleanup, and add '-f' option for running in the foreground. |
15 |
|
16 |
def setup_logging(home, foreground): |
|
17 |
# i hate that stupid logging config format, so just set up logging here.
|
|
18 |
||
19 |
log_folder = os.path.join(home, 'logs') |
|
20 |
if not os.path.exists(log_folder): |
|
21 |
os.mkdir(log_folder) |
|
22 |
||
23 |
f = logging.Formatter('%(levelname)-.3s [%(asctime)s.%(msecs)03d] %(name)s: %(message)s', |
|
24 |
'%Y%m%d-%H:%M:%S') |
|
25 |
debug_log = logging.FileHandler(os.path.join(log_folder, 'debug.log')) |
|
26 |
debug_log.setLevel(logging.DEBUG) |
|
27 |
debug_log.setFormatter(f) |
|
28 |
if foreground: |
|
29 |
stdout_log = logging.StreamHandler(sys.stdout) |
|
30 |
stdout_log.setLevel(logging.DEBUG) |
|
31 |
stdout_log.setFormatter(f) |
|
32 |
f = logging.Formatter('[%(asctime)s.%(msecs)03d] %(message)s', |
|
33 |
'%Y%m%d-%H:%M:%S') |
|
34 |
access_log = logging.FileHandler(os.path.join(log_folder, 'access.log')) |
|
35 |
access_log.setLevel(logging.INFO) |
|
36 |
access_log.setFormatter(f) |
|
37 |
||
38 |
logging.getLogger('').addHandler(debug_log) |
|
39 |
logging.getLogger('turbogears.access').addHandler(access_log) |
|
40 |
logging.getLogger('turbogears.controllers').setLevel(logging.INFO) |
|
41 |
||
42 |
if foreground: |
|
43 |
logging.getLogger('').addHandler(stdout_log) |
|
44 |
||
45 |
||
46 |
||
47 |
foreground = False |
|
48 |
if len(sys.argv) > 1: |
|
49 |
if sys.argv[1] == '-f': |
|
50 |
foreground = True |
|
51 |
||
89
by Robey Pointer
fix up dev.cfg so that nobody will ever have to edit it, by letting the |
52 |
home = os.path.realpath(os.path.dirname(__file__)) |
53 |
pidfile = os.path.join(home, 'loggerhead.pid') |
|
54 |
||
55 |
# read loggerhead config
|
|
56 |
||
57 |
from configobj import ConfigObj |
|
58 |
config = sys._loggerhead_config = ConfigObj(os.path.join(home, 'loggerhead.conf'), encoding='utf-8') |
|
59 |
extra_path = config.get('bzrpath', None) |
|
60 |
if extra_path: |
|
61 |
sys.path.insert(0, extra_path) |
|
62 |
||
63 |
turbogears.update_config(configfile="dev.cfg", modulename="loggerhead.config") |
|
64 |
||
65 |
potential_overrides = [ ('server.socket_port', int), ('server.webpath', str), ('server.thread_pool', int) ] |
|
66 |
for key, keytype in potential_overrides: |
|
67 |
value = config.get(key, None) |
|
68 |
if value is not None: |
|
69 |
value = keytype(value) |
|
70 |
turbogears.config.update({ key: value }) |
|
71 |
||
72 |
||
93
by Robey Pointer
slight cleanup, and add '-f' option for running in the foreground. |
73 |
if not foreground: |
74 |
sys.stderr.write('\n') |
|
75 |
sys.stderr.write('Launching loggerhead into the background.\n') |
|
76 |
sys.stderr.write('PID file: %s\n' % (pidfile,)) |
|
77 |
sys.stderr.write('\n') |
|
78 |
||
79 |
from loggerhead.daemon import daemonize |
|
80 |
daemonize(pidfile, home) |
|
81 |
||
82 |
setup_logging(home, foreground=foreground) |
|
83 |
||
89
by Robey Pointer
fix up dev.cfg so that nobody will ever have to edit it, by letting the |
84 |
log = logging.getLogger('loggerhead') |
85 |
log.info('Starting up...') |
|
1
by Robey Pointer
initial checkin |
86 |
|
87 |
from loggerhead.controllers import Root |
|
88 |
||
89
by Robey Pointer
fix up dev.cfg so that nobody will ever have to edit it, by letting the |
89 |
# re-index every 6 hours
|
90 |
index_freq = 6 * 3600 |
|
91 |
turbogears.scheduler.add_interval_task(initialdelay=1, interval=index_freq, action=Root._check_rebuild) |
|
92 |
||
93 |
try: |
|
94 |
turbogears.start_server(Root) |
|
95 |
finally: |
|
96 |
log.info('Shutdown.') |
|
93
by Robey Pointer
slight cleanup, and add '-f' option for running in the foreground. |
97 |
try: |
98 |
os.remove(pidfile) |
|
99 |
except OSError: |
|
100 |
pass
|
|
101 |
||
89
by Robey Pointer
fix up dev.cfg so that nobody will ever have to edit it, by letting the |
102 |