~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to start-loggerhead.py

  • Committer: Robey Pointer
  • Date: 2007-05-21 06:19:31 UTC
  • Revision ID: robey@lag.net-20070521061931-bp1m3uwwso7lkk6a
on the project list page, for projects using auto_publish, check to see if
the list of discoverable branches is different, and if so, reload the list
of branches.  this should cause the page to update when new branches are
added or removed from an auto_publish project.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
import pkg_resources
4
4
pkg_resources.require("TurboGears")
5
5
 
 
6
import logging
6
7
import os
7
8
 
8
9
import turbogears
11
12
 
12
13
import sys
13
14
 
 
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
 
14
52
home = os.path.realpath(os.path.dirname(__file__))
15
53
pidfile = os.path.join(home, 'loggerhead.pid')
16
54
 
31
69
        value = keytype(value)
32
70
        turbogears.config.update({ key: value })
33
71
 
34
 
 
35
 
sys.stderr.write('\n')
36
 
sys.stderr.write('Launching loggerhead into the background.\n')
37
 
sys.stderr.write('PID file: %s\n' % (pidfile,))
38
 
sys.stderr.write('\n')
39
 
 
40
 
from loggerhead.daemon import daemonize
41
 
daemonize(pidfile, home)
42
 
 
43
 
# i hate that stupid logging config format, so just set up logging here.
44
 
import logging
45
 
 
46
 
log_folder = os.path.join(home, 'logs')
47
 
if not os.path.exists(log_folder):
48
 
    os.mkdir(log_folder)
49
 
 
50
 
f = logging.Formatter('%(levelname)-.3s [%(asctime)s.%(msecs)03d] %(name)s: %(message)s',
51
 
                      '%Y%m%d-%H:%M:%S')
52
 
debug_log = logging.FileHandler(os.path.join(log_folder, 'debug.log'))
53
 
debug_log.setLevel(logging.DEBUG)
54
 
debug_log.setFormatter(f)
55
 
f = logging.Formatter('[%(asctime)s.%(msecs)03d] %(message)s',
56
 
                      '%Y%m%d-%H:%M:%S')
57
 
access_log = logging.FileHandler(os.path.join(log_folder, 'access.log'))
58
 
access_log.setLevel(logging.INFO)
59
 
access_log.setFormatter(f)
60
 
 
61
 
logging.getLogger('').addHandler(debug_log)
62
 
logging.getLogger('turbogears.access').addHandler(access_log)
63
 
logging.getLogger('turbogears.controllers').setLevel(logging.INFO)
64
 
 
 
72
if not foreground:
 
73
    sys.stderr.write('\n')
 
74
    sys.stderr.write('Launching loggerhead into the background.\n')
 
75
    sys.stderr.write('PID file: %s\n' % (pidfile,))
 
76
    sys.stderr.write('\n')
 
77
 
 
78
    from loggerhead.daemon import daemonize
 
79
    daemonize(pidfile, home)
 
80
 
 
81
setup_logging(home, foreground=foreground)
 
82
    
65
83
log = logging.getLogger('loggerhead')
66
84
log.info('Starting up...')
67
85
 
68
86
from loggerhead.controllers import Root
69
87
 
70
88
# re-index every 6 hours
71
 
index_freq = 6 * 3600
 
89
 
 
90
index_freq = config.get('cache_rebuild_frequency', 6 * 3600)
72
91
turbogears.scheduler.add_interval_task(initialdelay=1, interval=index_freq, action=Root._check_rebuild)
73
92
 
74
93
try:
75
94
    turbogears.start_server(Root)
76
95
finally:
77
96
    log.info('Shutdown.')
78
 
    os.remove(pidfile)
 
97
    try:
 
98
        os.remove(pidfile)
 
99
    except OSError:
 
100
        pass
 
101
 
79
102