daemon 3.65 KB
Newer Older
1 2
#!/usr/bin/env python2

3 4 5
import argparse
import json
import sys
6 7
import nrm
import nrm.daemon
8 9
import os

10

11
def main(argv=None):
12 13
    if argv is None:
        argv = sys.argv
14

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
    conf_parser = argparse.ArgumentParser(
      description=__doc__,
      formatter_class=argparse.RawDescriptionHelpFormatter,
      add_help=False
      )
    conf_parser.add_argument(
            "-c",
            "--configuration",
            help="Specify a config json-formatted config file to override "
                 "any of the available CLI options. If an option is "
                 "actually provided on the command-line, it overrides "
                 "its corresponding value from the configuration file.",
            metavar="FILE")
    conf_parser.add_argument("-d", "--print_defaults", action='store_true',
                             help="Print the default configuration file.")
    args, remaining_argv = conf_parser.parse_known_args()
31

32 33 34 35
    defaults = {"nrm_log": "/tmp/nrm.log",
                "hwloc": "hwloc",
                "perf": "perf",
                "argo_perf_wrapper": "argo-perf-wrapper",
36 37 38
                "argo_nodeos_config": "argo_nodeos_config",
                "pmpi_lib": "/usr/lib/libnrm-pmpi.so",
                }
39

40 41 42
    if args.print_defaults:
        print defaults
        return(0)
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
    if args.configuration:
        defaults.update(json.load(open(args.configuration)))

    parser = argparse.ArgumentParser(parents=[conf_parser])
    parser.set_defaults(**defaults)
    parser.add_argument(
           "--nrm_log",
           help="Main log file. Override default with the NRM_LOG."
                "environment variable",
           default=os.environ.get('NRM_LOG',
                                  '/tmp/nrm.log'))
    parser.add_argument(
            '--hwloc',
            help="Path to the hwloc to use. This path can be "
                 "relative and makes uses of the $PATH if necessary."
                 "Override default with the HWLOC environment"
                 "variable.",
            default=os.environ.get('HWLOC',
                                   'hwloc'))
    parser.add_argument(
            '--argo_nodeos_config',
            help="Path to the argo_nodeos_config to use. This path "
                 "can be relative and makes uses of the $PATH if "
                 "necessary. Override default with the "
                 "ARGO_NODEOS_CONFIG environment variable.",
            default=os.environ.get('ARGO_NODEOS_CONFIG',
                                   'argo_nodeos_config'))
    parser.add_argument(
            '--perf',
            help="Path to the linux perf tool to use. This path can be"
                 "relative and makes uses of the $PATH if necessary."
                 "Override default with the PERF environment"
                 "variable.",
            default=os.environ.get('PERF',
                                   'perf'))
79 80 81 82 83
    parser.add_argument(
            '--pmpi_lib',
            help="Path to the libnrm PMPI library used for the power policy"
                 "Override default with the PMPI environment variable.",
            default=os.environ.get('PMPI', defaults['pmpi_lib']))
84 85 86 87 88 89 90 91 92 93 94
    parser.add_argument(
            '--argo_perf_wrapper',
            help="Path to the linux perf tool to use. This path can"
                 "be relative and makes uses of the $PATH if "
                 "necessary. Override default with the PERFWRAPPER "
                 "environment variable.",
            default=os.environ.get('ARGO_PERF_WRAPPER',
                                   'argo-perf-wrapper'))
    args = parser.parse_args(remaining_argv)
    nrm.daemon.runner(config=args)
    return(0)
95

96 97

if __name__ == "__main__":
98
    sys.exit(main())