aboutsummaryrefslogtreecommitdiff
path: root/rpkid/rpki-start-servers
blob: edaffb2e99209176e05e860f77ea6362064b02f8 (plain) (blame)
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
#!/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 subprocess
import os
import argparse
import sys
import time
import rpki.config
import rpki.autoconf

os.environ["TZ"] = "UTC"
time.tzset()

parser = argparse.ArgumentParser(description = __doc__)
parser.add_argument("-c", "--config",
                    help = "override default location of configuration file")
parser.add_argument("-d", "--debug", action = "store_true",
                    help = "enable debugging")
parser.add_argument("--logdir", default = ".",
                    help = "where to write write log files when debugging")
args = parser.parse_args()

cfg = rpki.config.parser(args.config, "myrpki")

def run(name):
  # pylint: disable=E1103
  cmd = (os.path.join(rpki.autoconf.libexecdir, name), "-c", cfg.filename)
  if args.debug:
    proc = subprocess.Popen(cmd + ("-d",),
                            stdout = open(os.path.join(args.logdir, name + ".log"), "a"),
                            stderr = subprocess.STDOUT)
  else:
    proc = subprocess.Popen(cmd)
  if args.debug and proc.poll() is None:
    print "Started %s, pid %s" % (name, proc.pid)
  elif not args.debug and proc.wait() == 0:
    print "Started %s" % name
  else:
    print "Problem starting %s, pid %s" % (name, proc.pid)


if cfg.getboolean("start_irdbd", cfg.getboolean("run_rpkid", False)):
  run("irdbd")

if cfg.getboolean("start_rpkid", cfg.getboolean("run_rpkid", False)):
  run("rpkid")

if cfg.getboolean("start_pubd",  cfg.getboolean("run_pubd",  False)):
  run("pubd")

if cfg.getboolean("start_rootd", cfg.getboolean("run_rootd", False)):
  run("rootd")