Fix issues with configuration/parameters loading

- Change default server directory from plinth/ to /plinth as the program
  expects.

- First load the values from configuration file and then override them
  with command line parameters.

- Show default values on the command line help.

- Use configuration file values as default values to command line
  parameters.

- Log the value of script prefix (server_dir) for easy debugging.

- Make sure the server_dir is properly loaded from configuration files.
This commit is contained in:
Sunil Mohan Adapa 2015-03-08 21:34:53 +05:30
parent 2a83f29b8b
commit e09018fe9a
3 changed files with 11 additions and 8 deletions

View File

@ -9,7 +9,7 @@ config_dir = /etc/plinth
data_dir = /var/lib/plinth
log_dir = /var/log/plinth
pid_dir = /var/run
server_dir = plinth/
server_dir = /plinth
actions_dir = /usr/share/plinth/actions
doc_dir = /usr/share/doc/plinth

View File

@ -40,19 +40,20 @@ LOGGER = logging.getLogger(__name__)
def parse_arguments():
"""Parse command line arguments"""
parser = argparse.ArgumentParser(
description='Plinth web interface for FreedomBox')
description='Plinth web interface for FreedomBox',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
'--pidfile', default='plinth.pid',
'--pidfile', default=cfg.pidfile,
help='specify a file in which the server may write its pid')
# TODO: server_dir is actually a url prefix; use a better variable name
parser.add_argument(
'--server_dir', default='/',
'--server_dir', default=cfg.server_dir,
help='web server path under which to serve')
parser.add_argument(
'--debug', action='store_true', default=False,
'--debug', action='store_true', default=cfg.debug,
help='enable debugging and run server *insecurely*')
parser.add_argument(
'--no-daemon', action='store_true', default=False,
'--no-daemon', action='store_true', default=cfg.no_daemon,
help='do not start as a daemon')
args = parser.parse_args()
@ -239,10 +240,10 @@ def configure_django():
def main():
"""Intialize and start the application"""
parse_arguments()
cfg.read()
parse_arguments()
setup_logging()
service.init()
@ -250,6 +251,7 @@ def main():
configure_django()
LOGGER.info('Configuration loaded from file - %s', cfg.CONFIG_FILE)
LOGGER.info('Script prefix - %s', cfg.server_dir)
module_loader.load_modules()

View File

@ -78,6 +78,7 @@ def read():
('Path', 'status_log_file'),
('Path', 'access_log_file'),
('Path', 'pidfile'),
('Path', 'server_dir'),
('Network', 'host'),
('Network', 'port'),
('Network', 'secure_proxy_ssl_header'),