X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/0ad1b28497b49bf8baa5cfa2ea4438c4824617a1..861e67dfe848a9d322bdb2b7b89fb669f10ae731:/nominatim/cli.py?ds=sidebyside diff --git a/nominatim/cli.py b/nominatim/cli.py index 4873308d..37bcaffb 100644 --- a/nominatim/cli.py +++ b/nominatim/cli.py @@ -4,6 +4,7 @@ database administration and querying. """ import datetime as dt import os +import socket import sys import time import argparse @@ -11,7 +12,7 @@ import logging from pathlib import Path from .config import Configuration -from .tools.exec_utils import run_legacy_script, run_api_script +from .tools.exec_utils import run_legacy_script, run_api_script, run_php_server from .db.connection import connect from .db import status from .errors import UsageError @@ -81,7 +82,7 @@ class CommandlineParser: for arg in ('module_dir', 'osm2pgsql_path', 'phplib_dir', 'data_dir', 'phpcgi_path'): setattr(args, arg, Path(kwargs[arg])) - args.project_dir = Path(args.project_dir) + args.project_dir = Path(args.project_dir).resolve() logging.basicConfig(stream=sys.stderr, format='%(asctime)s: %(message)s', @@ -90,10 +91,12 @@ class CommandlineParser: args.config = Configuration(args.project_dir, args.data_dir / 'settings') + log = logging.getLogger() + log.warning('Using project directory: %s', str(args.project_dir)) + try: return args.command.run(args) except UsageError as exception: - log = logging.getLogger() if log.isEnabledFor(logging.DEBUG): raise # use Python's exception printing log.fatal('FATAL: %s', exception) @@ -259,11 +262,16 @@ class UpdateReplication: together with --once""") group.add_argument('--osm2pgsql-cache', metavar='SIZE', type=int, help='Size of cache to be used by osm2pgsql (in MB)') + group = parser.add_argument_group('Download parameters') + group.add_argument('--socket-timeout', dest='socket_timeout', type=int, default=60, + help='Set timeout for file downloads.') @staticmethod def _init_replication(args): from .tools import replication, refresh + socket.setdefaulttimeout(args.socket_timeout) + LOG.warning("Initialising replication updates") conn = connect(args.config.get_libpq_dsn()) replication.init_replication(conn, base_url=args.config.REPLICATION_URL) @@ -328,7 +336,8 @@ class UpdateReplication: conn = connect(args.config.get_libpq_dsn()) start = dt.datetime.now(dt.timezone.utc) state = replication.update(conn, params) - status.log_status(conn, start, 'import') + if state is not replication.UpdateState.NO_CHANGES: + status.log_status(conn, start, 'import') batchdate, _, _ = status.get_status(conn) conn.close() @@ -631,6 +640,28 @@ class QueryExport: return run_legacy_script(*params, nominatim_env=args) + +class AdminServe: + """\ + Start a simple web server for serving the API. + + This command starts the built-in PHP webserver to serve the website + from the current project directory. This webserver is only suitable + for testing and develop. Do not use it in production setups! + + By the default, the webserver can be accessed at: http://127.0.0.1:8088 + """ + + @staticmethod + def add_args(parser): + group = parser.add_argument_group('Server arguments') + group.add_argument('--server', default='127.0.0.1:8088', + help='The address the server will listen to.') + + @staticmethod + def run(args): + run_php_server(args.server, args.project_dir / 'website') + STRUCTURED_QUERY = ( ('street', 'housenumber and street'), ('city', 'city, town or village'), @@ -893,6 +924,7 @@ def nominatim(**kwargs): parser.add_subcommand('refresh', UpdateRefresh) parser.add_subcommand('export', QueryExport) + parser.add_subcommand('serve', AdminServe) if kwargs.get('phpcgi_path'): parser.add_subcommand('search', APISearch)