diff --git a/CHANGELOG.md b/CHANGELOG.md index f28115aca5cddc4d0cb8b6b64b202b2ef6b2617b..279659f4829bef2b0417dcaea52ba15863300666 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ This file logs the changes that are actually interesting to users (new features, changed functionality, fixed bugs). +## Version 2.0.3 (released 2017-04-07) + +- Made the `flamenco-worker.cfg` file mandatory, as this makes debugging configuration + issues easier. When the file does not exist, the absolute path of its expected + location is logged. + + ## Version 2.0.2 (released 2017-04-07) diff --git a/README.md b/README.md index e3639f00385f6ba6d44789ad9a6c3be98dd0485b..1e20861cc9da2c8a90c35206b86bf7e8ea2c246d 100644 --- a/README.md +++ b/README.md @@ -20,24 +20,24 @@ Configuration is read from three locations: - A hard-coded default in the Python source code. - `flamenco-worker.cfg` in the current working directory. -- `$HOME/.flamenco-worker.cfg`. +- `$HOME/.flamenco-worker.cfg`; this file is optional. -When those files do not exist, they are skipped (i.e. this is not an error). They -should be in INI format, as specified by the +The configuration files should be in INI format, as specified by the [configparser documentation](https://docs.python.org/3/library/configparser.html) ### Configuration contents: All configuration keys should be placed in the `[flamenco-worker]` section of the -config files. +config files. At least take a look at: - `manager_url`: Flamenco Manager URL. -- `job_types`: Space-separated list of job types this worker may execute. +- `task_types`: Space-separated list of task types this worker may execute. - `task_update_queue_db`: filename of the SQLite3 database holding the queue of task updates to be sent to the Master. -These configuration keys are also required, but are created automatically upon startup -when they don't exist yet: + +These configuration keys are also required, but are created automatically in +`$HOME/.flamenco-worker.cfg` when they don't exist yet: - `worker_id`: ID of the worker, handed out by the Manager upon registration (see Registration below) and used for authentication with the Manager. diff --git a/flamenco-worker.cfg b/flamenco-worker.cfg index 7b774fae456a8b1bfb7948bcd8bb1a7c6473301f..0857b8dd6b4475af251fa32e409ce1958e052d32 100644 --- a/flamenco-worker.cfg +++ b/flamenco-worker.cfg @@ -34,6 +34,7 @@ args = (sys.stderr,) class = logging.handlers.TimedRotatingFileHandler formatter = flamenco # (filename, when, interval, backupCount, encoding, delay, utc, atTime=None) +# Be aware that tilde expansion is *not* performed on the path. args = ('/tmp/flamenco-worker.log', 'midnight', 1, 7, 'utf8', True, True) [formatters] diff --git a/flamenco_worker/cli.py b/flamenco_worker/cli.py index fd39d1e072e9928119a6e4c2f0e2f262c30df5be..c9ec21f922b2d56aae56543fd0a5ff4a9bcb652c 100644 --- a/flamenco_worker/cli.py +++ b/flamenco_worker/cli.py @@ -4,13 +4,14 @@ import argparse import asyncio import logging import logging.config +import pathlib import requests def main(): parser = argparse.ArgumentParser() - parser.add_argument('-c', '--config', + parser.add_argument('-c', '--config', type=pathlib.Path, help='Load this configuration file instead of the default files.') parser.add_argument('-v', '--verbose', action='store_true', help='Show configuration before starting, ' diff --git a/flamenco_worker/config.py b/flamenco_worker/config.py index d3481cd7244b8bc4c555a75ee1db3ee2803bab29..5a0e4d22548d87f6d45b306174b2f4e4b9e8de15 100644 --- a/flamenco_worker/config.py +++ b/flamenco_worker/config.py @@ -3,13 +3,13 @@ import collections import configparser import datetime -import os.path +import pathlib import logging from . import worker -HOME_CONFIG_FILE = os.path.expanduser('~/.flamenco-worker.cfg') -GLOBAL_CONFIG_FILE = 'flamenco-worker.cfg' +HOME_CONFIG_FILE = pathlib.Path('~/.flamenco-worker.cfg').expanduser() +GLOBAL_CONFIG_FILE = pathlib.Path('./flamenco-worker.cfg').absolute() CONFIG_SECTION = 'flamenco-worker' DEFAULT_CONFIG = { @@ -56,18 +56,18 @@ def merge_with_home_config(new_conf: dict): for key, value in new_conf.items(): confparser.set(CONFIG_SECTION, key, value) - tmpname = HOME_CONFIG_FILE + '~' + tmpname = HOME_CONFIG_FILE.with_name(HOME_CONFIG_FILE.name + '~') log.debug('Writing configuration file to %s', tmpname) with open(tmpname, mode='wt', encoding='utf8') as outfile: confparser.write(outfile) log.debug('Moving configuration file to %s', HOME_CONFIG_FILE) - os.replace(tmpname, HOME_CONFIG_FILE) + tmpname.replace(HOME_CONFIG_FILE) log.info('Updated configuration file %s', HOME_CONFIG_FILE) -def load_config(config_file: str = None, +def load_config(config_file: pathlib.Path = None, show_effective_config: bool = False) -> ConfigParser: """Loads one or more configuration files.""" @@ -80,11 +80,19 @@ def load_config(config_file: str = None, if config_file: log.info('Loading configuration from %s', config_file) + if not config_file.exists(): + log.fatal('Config file %s does not exist', config_file) + raise SystemExit() loaded = confparser.read(config_file, encoding='utf8') else: + if not GLOBAL_CONFIG_FILE.exists(): + log.fatal('Config file %s does not exist', GLOBAL_CONFIG_FILE) + raise SystemExit() + config_files = [GLOBAL_CONFIG_FILE, HOME_CONFIG_FILE] - log.info('Loading configuration from %s', ', '.join(config_files)) - loaded = confparser.read(config_files, encoding='utf8') + filenames = [str(f.absolute()) for f in config_files] + log.info('Loading configuration from %s', ', '.join(filenames)) + loaded = confparser.read(filenames, encoding='utf8') log.info('Succesfully loaded: %s', loaded)