# This file is part of acme-updater, written by Helmut Pozimski 2016-2017. # # stov is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, version 2 of the License. # # stov is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with stov. If not, see . # -*- coding: utf8 -*- """ Main function of acme-updater, parses command line arguments, sets up logging and executes the modules. """ import argparse import logging import json import sys from amulib.helpers import get_log_level from amulib import apache from amulib import postfix from amulib import dovecot from amulib import ejabberd def main(): """ Main function of acme-updater. """ config = None parser = argparse.ArgumentParser() parser.add_argument("--apache", help="use the apache module", action="store_true") parser.add_argument("--postfix", help="use the postfix module", action="store_true") parser.add_argument("--dovecot", help="use the dovecot module", action="store_true") parser.add_argument("--ejabberd", help="use the ejabberd module", action="store_true") parser.add_argument("--verbose", "-V", help="be verbose, enables debug " "output", action="store_true") parser.add_argument("--config", "-C", help="path to the configuration " "file", type=str) args = parser.parse_args() logger = logging.getLogger("acme-updater") logger.addHandler(logging.StreamHandler()) if args.config: try: with open(args.config, "r") as fobj: config = json.load(fobj) except IOError: logger.error("Error: Could not open configuration file") sys.exit(1) except json.JSONDecodeError: logger.error("Error: Could not parse configuration file") sys.exit(1) if args.verbose: logger.setLevel(logging.DEBUG) elif config: logger.setLevel(get_log_level(config["loglevel"])) else: logger.setLevel(logging.INFO) if args.apache: if config: apache.run(config["apache"], config["acme_dir"], config["named_key_path"], config["dns_server"]) else: apache.run() if args.postfix: if config: postfix.run(config["postfix"], config["acme_dir"], config["named_key_path"], config["dns_server"]) else: postfix.run() if args.dovecot: if config: dovecot.run(config["dovecot"], config["acme_dir"], config["named_key_path"], config["dns_server"]) else: dovecot.run() if args.ejabberd: if config: ejabberd.run(config["ejabberd"], config["acme_dir"], config["named_key_path"], config["dns_server"]) else: ejabberd.run()