1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#!/usr/bin/env python
# $Id$
#
# Copyright (C) 2014 Dragon Research Labs ("DRL")
# Portions copyright (C) 2009--2013 Internet Systems Consortium ("ISC")
# Portions copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN")
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notices and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND DRL, ISC, AND ARIN DISCLAIM ALL
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DRL,
# ISC, OR ARIN BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
"""
Start servers, using config file to figure out which servers the user
wants started.
"""
import os
import sys
import time
import argparse
import subprocess
import rpki.config
import rpki.autoconf
from logging.handlers import SysLogHandler
os.environ["TZ"] = "UTC"
time.tzset()
def non_negative_integer(s):
if int(s) < 0:
raise ValueError
return s
parser = argparse.ArgumentParser(description = __doc__)
parser.add_argument("-c", "--config",
help = "override default location of configuration file")
parser.add_argument("--log-directory", default = ".",
help = "where to write write log files when not using syslog")
parser.add_argument("--log-backup-count", default = "7", type = non_negative_integer,
help = "keep this many old log files when rotating")
parser.add_argument("--log-level", default = "warning",
choices = ("debug", "info", "warning", "error", "critical"),
help = "how verbosely to log")
group = parser.add_mutually_exclusive_group()
group.add_argument("--log-file", action = "store_true",
help = "log to files, reopening if rotated away")
group.add_argument("--log-rotating-file-kbytes",type = non_negative_integer,
help = "log to files, rotating after this many kbytes")
group.add_argument("--log-rotating-file-hours", type = non_negative_integer,
help = "log to files, rotating after this many hours")
group.add_argument("--log-syslog", default = "daemon", nargs = "?",
choices = sorted(SysLogHandler.facility_names.keys()),
help = "log syslog")
args = parser.parse_args()
cfg = rpki.config.parser(set_filename = args.config, section = "myrpki")
def run(name, old_flag = None):
if cfg.getboolean("start_" + name, cfg.getboolean("run_" + name if old_flag is None else old_flag, False)):
log_file = os.path.join(args.log_directory, name + ".log")
cmd = (rpki.autoconf.SUDO, "-u", rpki.autoconf.RPKI_USER,
os.path.join(rpki.autoconf.libexecdir, name), "--log-level", args.log_level)
if args.log_file:
cmd += ("--log-file", log_file)
elif args.log_rotating_file_kbytes:
cmd += ("--log-rotating-file", log_file, args.log_rotating_file_kbytes, args.log_backup_count)
elif args.log_rotating_file_hours:
cmd += ("--log-timed-rotating-file", log_file, args.log_rotating_file_hours, args.log_backup_count)
else:
cmd += ("--log-syslog", args.log_syslog)
proc = subprocess.Popen(cmd)
if proc.wait() != 0:
sys.exit("Problem starting %s, pid %s" % (name, proc.pid))
run("irdbd", "run_rpkid")
run("rpkid")
run("pubd")
|