mediagis / nominatim-docker

100% working container for Nominatim
Creative Commons Zero v1.0 Universal
1.07k stars 438 forks source link

pg_ctl: cannot be run as root #279

Closed zabakala closed 2 years ago

zabakala commented 2 years ago

Describe the bug Just copy pasted the 4.0 Dockerfile and I get:

+ '[' https://download.geofabrik.de/europe/czech-republic-latest.osm.pbf '!=' '' ']'
+ echo Downloading OSM extract from https://download.geofabrik.de/europe/czech-republic-latest.osm.pbf
+ curl -L https://download.geofabrik.de/europe/czech-republic-latest.osm.pbf --create-dirs -o /nominatim/data.osm.pbf
Downloading OSM extract from https://download.geofabrik.de/europe/czech-republic-latest.osm.pbf
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  753M  100  753M    0     0  66.2M      0  0:00:11  0:00:11 --:--:-- 68.7M
+ '[' '' '!=' '' ']'
+ '[' '!' -f /var/lib/postgresql/12/main/PG_VERSION ']'
+ sudo service postgresql start
 * Starting PostgreSQL 12 database server
 * Error: /usr/lib/postgresql/12/bin/pg_ctl /usr/lib/postgresql/12/bin/pg_ctl start -D /var/lib/postgresql/12/main -l /var/log/postgresql/postgresql-12-main.log -s -o  -c config_file="/etc/postgresql/12/main/postgresql.conf"  exited with status 1:
pg_ctl: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.
   ...fail!
+ sudo -u postgres createuser -s nominatim
createuser: error: could not connect to database template1: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
+ sudo -u postgres createuser -SDR www-data
createuser: error: could not connect to database template1: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
+ chown -R nominatim:nominatim /nominatim
+ cd /nominatim
+ sudo -E -u nominatim nominatim import --osm-file /nominatim/data.osm.pbf --threads 16
2021-12-23 09:23:22: Using project directory: /nominatim
2021-12-23 09:23:22: Creating database
createdb: error: could not connect to database template1: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
2021-12-23 09:23:22: FATAL: Creating new database failed.

What could be done or attempted to successfully resolve this?

leonardehrenfried commented 2 years ago

What is the command that you run? Am I right in thinking that you build your own image on your local machine rather than using the one we upload to Dockerhub?

zabakala commented 2 years ago

What is the command that you run? Am I right in thinking that you build your own image on your local machine rather than using the one we upload to Dockerhub?

Hi, yop, I am using this Dockerfile https://raw.githubusercontent.com/mediagis/nominatim-docker/master/4.0/Dockerfile

leonardehrenfried commented 2 years ago

I'd use the image from Dockerhub and post the command you're using.

zabakala commented 2 years ago

Using HELM deploy with the image inside my GitLab Dockerfile (cannot use docker-compose) looking like this:

FROM mediagis/nominatim:4.0

ENV PBF_URL=https://download.geofabrik.de/europe/monaco-latest.osm.pbf
ENV REPLICATION_URL=https://download.geofabrik.de/europe/monaco-updates/
The issue above is gone but a new one is:

Processing: Node(52860k 290.4k/s) Way(0k 0.00k/s) Relation(0 0.0/s)2021-12-23 20:54:00  ERROR: planet_osm_nodes - error on COPY: server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.

2021-12-23 20:54:00  ERROR: Data: 3259621956    503551066       170746142
3259621957      503551083       171392948
3259621959      503551116       170578409
3259621960      503551149       171448373
3259621961      503551184       171503551
3259621962      503551193       170925275
3259621963      503551193       171502985
3259621964      503551229       170454796
3259621965      503551303       171384596
3259621966      503551326       171183231
3259621967      503551338       170576270
3259621968      503551369       171447751
3259621969      503551379       171496510
3259621970      503551399       170606413
3259621971      503551413       170577275
3259621972      503551456       171617983
3259
...
287
3262856212      507497733       149131909
3262856213      507497868       148705770
3262856214      507497873       148913747
3262856215      507497876       148696677
3262856216      507497891       150127174
3262856217      507497893       148594990
3262856218      507497897       148702021
3262856220      507497982       148753968
3262856221      507498018       148698385
3262856222      507498063       149207763
3262856223      507498089       149080092
3262856224      507498113       148706648
3262856227      507498170       148870880
3262856228      507498241       148761979
3262856233      507498398       148581856
3262856234      507498410       150188774

2021-12-23 20:54:00  ERROR: DB copy thread failed: COPYing data to Postgresql.
Traceback (most recent call last):
  File "/usr/local/bin/nominatim", line 11, in <module>
    exit(cli.nominatim(module_dir='/usr/local/lib/nominatim/module',
  File "/usr/local/lib/nominatim/lib-python/nominatim/cli.py", line 235, in nominatim
    return parser.run(**kwargs)
  File "/usr/local/lib/nominatim/lib-python/nominatim/cli.py", line 96, in run
    return args.command.run(args)
  File "/usr/local/lib/nominatim/lib-python/nominatim/clicmd/setup.py", line 77, in run
    database_import.import_osm_data(files,
  File "/usr/local/lib/nominatim/lib-python/nominatim/tools/database_import.py", line 98, in import_osm_data
    run_osm2pgsql(options)
  File "/usr/local/lib/nominatim/lib-python/nominatim/tools/exec_utils.py", line 139, in run_osm2pgsql
    subprocess.run(cmd, cwd=options.get('cwd', '.'),
  File "/usr/lib/python3.8/subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/usr/local/lib/nominatim/osm2pgsql', '--hstore', '--latlon', '--slim', '--with-forward-dependencies', 'false', '--log-progress', 'true', '--number-processes', '1', '--cache', '1507', '--output', 'gazetteer', '--style', '/usr/local/etc/nominatim/import-full.style', '--create', '/nominatim/data.osm.pbf']' returned non-zero exit status 2.

But I suspect it to be due to the the server specs (?): RAM 2Gi CPU 1000m


Doubling the specs was of no help. Anybody else having this issue?

zabakala commented 2 years ago

Ok, let´s call it a game of specs, ... trippling the specs got it going :-)

leonardehrenfried commented 2 years ago

Glad you managed to solve your problem. If your deployment code is open source we are happy to link to it so that others have a template for deploying into kubernetes. This is what you're doing, isn't it?