9
from optparse import OptionParser
11
13
cherrypy.lowercase_api = True
16
def setup_logging(home, foreground):
15
from loggerhead import daemon, release, util
18
def make_handler(config, filename):
19
roll = config.get('log.roll', 'never')
21
h = logging.handlers.TimedRotatingFileHandler(filename, 'midnight', 0, 100)
22
elif roll == 'weekly':
23
h = logging.handlers.TimedRotatingFileHandler(filename, 'W0', 0, 100)
25
h = logging.FileHandler(filename)
29
def setup_logging(home, config, foreground):
17
30
# i hate that stupid logging config format, so just set up logging here.
19
32
log_folder = os.path.join(home, 'logs')
49
if sys.argv[1] == '-f':
52
home = os.path.realpath(os.path.dirname(__file__))
53
pidfile = os.path.join(home, 'loggerhead.pid')
55
# read loggerhead config
57
from configobj import ConfigObj
58
config = ConfigObj(os.path.join(home, 'loggerhead.conf'), encoding='utf-8')
59
extra_path = config.get('bzrpath', None)
61
sys.path.insert(0, extra_path)
63
turbogears.update_config(configfile="dev.cfg", modulename="loggerhead.config")
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)
69
value = keytype(value)
70
turbogears.config.update({ key: value })
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')
78
from loggerhead.daemon import daemonize
79
daemonize(pidfile, home)
81
setup_logging(home, foreground=foreground)
83
log = logging.getLogger('loggerhead')
84
log.info('Starting up...')
86
from loggerhead.controllers import Root
90
# re-index every 6 hours
92
index_freq = config.get('cache_rebuild_frequency', 6 * 3600)
93
turbogears.scheduler.add_interval_task(initialdelay=1, interval=index_freq, action=Root._check_rebuild)
96
turbogears.start_server(Root)
61
parser = OptionParser(usage='usage: %prog [options]', version='%prog ' + release.version)
62
parser.add_option('-f', '--foreground', action='store_true', dest='foreground', default=False,
63
help="run in the foreground; don't daemonize")
64
parser.add_option('-C', '--check', action='store_true', dest='check', default=False,
65
help="only start if not already running (useful for cron jobs)")
66
options, args = parser.parse_args()
68
parser.error('No filename arguments are used, only options.')
71
home = os.path.realpath(os.path.dirname(__file__))
72
pidfile = os.path.join(home, 'loggerhead.pid')
75
if daemon.is_running(pidfile):
77
sys.stderr.write('Did not find loggerhead running in %r; restarting...\n' % (pidfile,))
79
# read loggerhead config
81
from configobj import ConfigObj
82
config = ConfigObj(os.path.join(home, 'loggerhead.conf'), encoding='utf-8')
83
extra_path = config.get('bzrpath', None)
85
sys.path.insert(0, extra_path)
87
turbogears.update_config(configfile="dev.cfg", modulename="loggerhead.config")
89
potential_overrides = [ ('server.socket_port', int), ('server.webpath', str), ('server.thread_pool', int) ]
90
for key, keytype in potential_overrides:
91
value = config.get(key, None)
93
value = keytype(value)
94
turbogears.config.update({ key: value })
96
if not options.foreground:
97
sys.stderr.write('\n')
98
sys.stderr.write('Launching loggerhead into the background.\n')
99
sys.stderr.write('PID file: %s\n' % (pidfile,))
100
sys.stderr.write('\n')
102
daemon.daemonize(pidfile, home)
104
setup_logging(home, config, foreground=options.foreground)
106
log = logging.getLogger('loggerhead')
107
log.info('Starting up...')
109
from loggerhead.controllers import Root
113
# re-index every 6 hours
114
index_freq = config.get('cache_rebuild_frequency', 6 * 3600)
115
turbogears.scheduler.add_interval_task(initialdelay=1, interval=index_freq, action=Root._check_rebuild)
117
util.set_date_format(config.get('date_format', 'fancy'))
119
turbogears.start_server(Root)
121
log.info('Shutdown.')
128
if __name__ == '__main__':