~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to start-loggerhead.py

  • Committer: Michael Hudson
  • Date: 2008-06-18 03:33:29 UTC
  • mto: This revision was merged to the branch mainline in revision 164.
  • Revision ID: michael.hudson@canonical.com-20080618033329-9d2i32vs7hov4ma2
begin a compatibility app

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
        h = logging.FileHandler(filename)
26
26
    return h
27
27
 
28
 
        
 
28
 
29
29
def setup_logging(home, config, foreground):
30
30
    # i hate that stupid logging config format, so just set up logging here.
31
31
 
32
32
    log_folder = os.path.join(home, 'logs')
33
33
    if not os.path.exists(log_folder):
34
34
        os.mkdir(log_folder)
35
 
    
 
35
 
36
36
    f = logging.Formatter('%(levelname)-.3s [%(asctime)s.%(msecs)03d] %(name)s: %(message)s',
37
37
                          '%Y%m%d-%H:%M:%S')
38
38
    debug_log = make_handler(config, os.path.join(log_folder, 'debug.log'))
47
47
    access_log = make_handler(config, os.path.join(log_folder, 'access.log'))
48
48
    access_log.setLevel(logging.INFO)
49
49
    access_log.setFormatter(f)
50
 
    
 
50
 
51
51
    logging.getLogger('').addHandler(debug_log)
52
52
    logging.getLogger('turbogears.access').addHandler(access_log)
53
53
    logging.getLogger('turbogears.controllers').setLevel(logging.INFO)
54
 
    
 
54
 
55
55
    if foreground:
56
56
        logging.getLogger('').addHandler(stdout_log)
57
 
    
 
57
 
58
58
 
59
59
 
60
60
def main():
66
66
    options, args = parser.parse_args()
67
67
    if len(args) > 0:
68
68
        parser.error('No filename arguments are used, only options.')
69
 
        
70
 
        
 
69
 
 
70
 
71
71
    home = os.path.realpath(os.path.dirname(__file__))
72
72
    pidfile = os.path.join(home, 'loggerhead.pid')
73
 
    
 
73
 
74
74
    if options.check:
75
75
        if daemon.is_running(pidfile):
76
76
            sys.exit(0)
77
77
        sys.stderr.write('Did not find loggerhead running in %r; restarting...\n' % (pidfile,))
78
 
    
 
78
 
79
79
    # read loggerhead config
80
 
    
 
80
 
81
81
    from configobj import ConfigObj
82
82
    config = ConfigObj(os.path.join(home, 'loggerhead.conf'), encoding='utf-8')
83
83
    extra_path = config.get('bzrpath', None)
84
84
    if extra_path:
85
85
        sys.path.insert(0, extra_path)
86
 
    
 
86
 
87
87
    turbogears.update_config(configfile="dev.cfg", modulename="loggerhead.config")
88
 
    
 
88
 
89
89
    potential_overrides = [ ('server.socket_port', int), ('server.webpath', str), ('server.thread_pool', int), ('server.socket_host' ,str) ]
90
90
    for key, keytype in potential_overrides:
91
91
        value = config.get(key, None)
92
92
        if value is not None:
93
93
            value = keytype(value)
94
94
            turbogears.config.update({ key: value })
95
 
    
 
95
 
96
96
    if not options.foreground:
97
97
        sys.stderr.write('\n')
98
98
        sys.stderr.write('Launching loggerhead into the background.\n')
99
99
        sys.stderr.write('PID file: %s\n' % (pidfile,))
100
100
        sys.stderr.write('\n')
101
 
    
 
101
 
102
102
        daemon.daemonize(pidfile, home)
103
103
 
104
104
    setup_logging(home, config, foreground=options.foreground)
105
 
        
 
105
 
106
106
    log = logging.getLogger('loggerhead')
107
107
    log.info('Starting up...')
108
 
    
 
108
 
109
109
    from loggerhead.controllers import Root
110
 
    
 
110
 
111
111
    Root = Root(config)
112
 
    
 
112
 
113
113
    try:
114
114
        turbogears.start_server(Root)
115
115
    finally: