blob: 9428c880ebe1b588483c5f055324defedeaa8ae4 (
plain)
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
|
"""
Effectively the same as normal __main__.py. However, we moved it's content over to this
file to allow us to exclude the __main__.py file from black's autoformatting
"""
import argparse
import os
import sys
from pathlib import Path
from typing import NoReturn
from knot_resolver_manager import compat
from knot_resolver_manager.constants import CONFIG_FILE_ENV_VAR, DEFAULT_MANAGER_CONFIG_FILE
from knot_resolver_manager.log import logger_startup
from knot_resolver_manager.server import start_server
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Knot Resolver - caching DNS resolver")
parser.add_argument(
"-c",
"--config",
help="Config file to load. Overrides default config location at '" + str(DEFAULT_MANAGER_CONFIG_FILE) + "'",
type=str,
nargs=1,
required=False,
default=None,
)
return parser.parse_args()
def main() -> NoReturn:
# initial logging is to memory until we read the config
logger_startup()
# parse arguments
args = parse_args()
# where to look for config
config_env = os.getenv(CONFIG_FILE_ENV_VAR)
if args.config is not None:
config_path = Path(args.config[0])
elif config_env is not None:
config_path = Path(config_env)
else:
config_path = DEFAULT_MANAGER_CONFIG_FILE
exit_code = compat.asyncio.run(start_server(config=config_path))
sys.exit(exit_code)
|