From 3dc4d6665012b1149310e4c386ad1955f1f9dad0 Mon Sep 17 00:00:00 2001 From: Mauricio Scheffer Date: Thu, 17 Mar 2022 15:45:56 +0000 Subject: [PATCH] #245 Pass environment variables to all sudo commands Not just "nominatim import" This enables passing NOMINATIM_DATABASE_DSN --- 4.0/init.sh | 18 +++++++++--------- 4.0/start.sh | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/4.0/init.sh b/4.0/init.sh index 2ce17f29..96183af2 100755 --- a/4.0/init.sh +++ b/4.0/init.sh @@ -57,13 +57,13 @@ if [ ! -f /var/lib/postgresql/12/main/PG_VERSION ]; then fi sudo service postgresql start && \ -sudo -u postgres psql postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='nominatim'" | grep -q 1 || sudo -u postgres createuser -s nominatim && \ -sudo -u postgres psql postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='www-data'" | grep -q 1 || sudo -u postgres createuser -SDR www-data && \ +sudo -E -u postgres psql postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='nominatim'" | grep -q 1 || sudo -E -u postgres createuser -s nominatim && \ +sudo -E -u postgres psql postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='www-data'" | grep -q 1 || sudo -E -u postgres createuser -SDR www-data && \ -sudo -u postgres psql postgres -tAc "ALTER USER nominatim WITH ENCRYPTED PASSWORD '$NOMINATIM_PASSWORD'" && \ -sudo -u postgres psql postgres -tAc "ALTER USER \"www-data\" WITH ENCRYPTED PASSWORD '${NOMINATIM_PASSWORD}'" && \ +sudo -E -u postgres psql postgres -tAc "ALTER USER nominatim WITH ENCRYPTED PASSWORD '$NOMINATIM_PASSWORD'" && \ +sudo -E -u postgres psql postgres -tAc "ALTER USER \"www-data\" WITH ENCRYPTED PASSWORD '${NOMINATIM_PASSWORD}'" && \ -sudo -u postgres psql postgres -c "DROP DATABASE IF EXISTS nominatim" +sudo -E -u postgres psql postgres -c "DROP DATABASE IF EXISTS nominatim" chown -R nominatim:nominatim ${PROJECT_DIR} @@ -72,10 +72,10 @@ sudo -E -u nominatim nominatim import --osm-file $OSMFILE --threads $THREADS if [ -f tiger-nominatim-preprocessed.csv.tar.gz ]; then echo "Importing Tiger address data" - sudo -u nominatim nominatim add-data --tiger-data tiger-nominatim-preprocessed.csv.tar.gz + sudo -E -u nominatim nominatim add-data --tiger-data tiger-nominatim-preprocessed.csv.tar.gz fi -sudo -u nominatim nominatim admin --check-database +sudo -E -u nominatim nominatim admin --check-database if [ "$REPLICATION_URL" != "" ]; then sudo -E -u nominatim nominatim replication --init @@ -85,14 +85,14 @@ if [ "$REPLICATION_URL" != "" ]; then else if [ "$FREEZE" = "true" ]; then echo "Freezing database" - sudo -u nominatim nominatim freeze + sudo -E -u nominatim nominatim freeze fi fi # gather statistics for query planner to potentially improve query performance # see, https://github.com/osm-search/Nominatim/issues/1023 # and https://github.com/osm-search/Nominatim/issues/1139 -sudo -u nominatim psql -d nominatim -c "ANALYZE VERBOSE" +sudo -E -u nominatim psql -d nominatim -c "ANALYZE VERBOSE" sudo service postgresql stop diff --git a/4.0/start.sh b/4.0/start.sh index c3f2f8d5..263e35e5 100755 --- a/4.0/start.sh +++ b/4.0/start.sh @@ -38,7 +38,7 @@ fi service postgresql start -cd ${PROJECT_DIR} && sudo -u nominatim nominatim refresh --website --functions +cd ${PROJECT_DIR} && sudo -E -u nominatim nominatim refresh --website --functions service apache2 start