~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to start-loggerhead

  • Committer: Jelmer Vernooij
  • Date: 2008-08-06 18:27:51 UTC
  • mto: (197.1.9 pathargs)
  • mto: This revision was merged to the branch mainline in revision 202.
  • Revision ID: jelmer@samba.org-20080806182751-s68wtdpxaryvylhp
Add --configfile argument.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
from paste.httpexceptions import make_middleware
30
30
from paste.translogger import make_filter
31
31
 
32
 
from loggerhead import daemon
 
32
from loggerhead import daemon, release
33
33
from loggerhead.apps.config import Root
34
34
 
35
35
 
36
36
def make_handler(config, filename):
37
37
    roll = config.get('log.roll', 'never')
38
38
    if roll == 'daily':
39
 
        h = logging.handlers.TimedRotatingFileHandler(filename, 'midnight', 1, 100)
 
39
        h = logging.handlers.TimedRotatingFileHandler(filename, 'midnight', 0, 100)
40
40
    elif roll == 'weekly':
41
 
        h = logging.handlers.TimedRotatingFileHandler(filename, 'W0', 1, 100)
 
41
        h = logging.handlers.TimedRotatingFileHandler(filename, 'W0', 0, 100)
42
42
    else:
43
43
        h = logging.FileHandler(filename)
44
44
    return h
45
45
 
46
46
 
47
 
def setup_logging(log_folder, config, foreground):
 
47
def setup_logging(home, config, foreground):
48
48
    # i hate that stupid logging config format, so just set up logging here.
49
49
 
 
50
    log_folder = os.path.join(home, 'logs')
50
51
    if not os.path.exists(log_folder):
51
52
        os.mkdir(log_folder)
52
53
 
78
79
    home = os.path.realpath(os.path.dirname(__file__))
79
80
    default_pidfile = os.path.join(home, 'loggerhead.pid')
80
81
    default_configfile = os.path.join(home, 'loggerhead.conf')
81
 
    default_log_folder = os.path.join(home, 'logs')
82
 
    parser = OptionParser(usage='usage: %prog [options]', version='%prog')
 
82
    parser = OptionParser(usage='usage: %prog [options]', version='%prog ' + release.version)
83
83
    parser.add_option('-f', '--foreground', action='store_true', dest='foreground', default=False,
84
84
                      help="run in the foreground; don't daemonize")
85
85
    parser.add_option('-C', '--check', action='store_true', dest='check', default=False,
86
86
                      help="only start if not already running (useful for cron jobs)")
87
87
    parser.add_option('-p', '--pidfile', dest="pidfile", default=default_pidfile,
88
 
                      type=str, help="override pidfile location")
89
 
    parser.add_option('-c', '--config-file', dest="configfile", default=default_configfile,
90
 
                                          type=str, help="override configuration file location")
91
 
    parser.add_option('-L', '--log-folder', dest="log_folder", default=default_log_folder,
92
 
                      type=str, help="override log file directory")
 
88
                      help="override pidfile location")
 
89
    parser.add_option('-c', '--configfile', dest="configfile", default=default_configfile,
 
90
                      help="override configuration file location")
93
91
    options, args = parser.parse_args()
94
92
    if len(args) > 0:
95
93
        parser.error('No filename arguments are used, only options.')
106
104
    if extra_path:
107
105
        sys.path.insert(0, extra_path)
108
106
 
 
107
    #turbogears.update_config(configfile="dev.cfg", modulename="loggerhead.config")
 
108
 
109
109
    potential_overrides = [ ('server.socket_port', int),
110
110
                            ('server.webpath', str),
111
111
                            ('server.thread_pool', int),
119
119
        value = config.get(key, None)
120
120
        if value is not None:
121
121
            value = keytype(value)
 
122
            #turbogears.config.update({ key: value })
122
123
 
123
124
    if not options.foreground:
124
125
        sys.stderr.write('\n')
128
129
 
129
130
        daemon.daemonize(options.pidfile, home)
130
131
 
131
 
    setup_logging(options.log_folder, config, foreground=options.foreground)
 
132
    setup_logging(home, config, foreground=options.foreground)
132
133
 
133
134
    log = logging.getLogger('loggerhead')
134
135
    log.info('Starting up...')