123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- # 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 <http://www.gnu.org/licenses/>.
- # -*- 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
- 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("--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)
- logger.setLevel(get_log_level(config["loglevel"]))
- if args.apache:
- if config:
- apache.run(config["apache"], config["acme_dir"],
- config["named_key_path"])
- else:
- apache.run()
|