diff --git a/packaging/common/cfengine-hub/postinstall.sh b/packaging/common/cfengine-hub/postinstall.sh index ecaa043ef..c853ecd6f 100644 --- a/packaging/common/cfengine-hub/postinstall.sh +++ b/packaging/common/cfengine-hub/postinstall.sh @@ -1,3 +1,5 @@ +# force locale to C as recommended by postgresql docs https://www.postgresql.org/docs/current/locale.html +export LC_ALL=C # (re)load SELinux policy if available and required before we start working with # our daemons and services below if [ `os_type` = "redhat" ] && @@ -411,7 +413,7 @@ init_postgres_dir() # Note: postgres expects $PWD to be writeable, so all postgres commands # should be executed from cfpostgres-writeable directory. # /tmp is such directory on most cases - (cd /tmp && su --login cfpostgres -c "$PREFIX/bin/initdb -D $PREFIX/state/pg/data") + (cd /tmp && su cfpostgres -c "$PREFIX/bin/initdb -D $PREFIX/state/pg/data") touch /var/log/postgresql.log chown cfpostgres:cfpostgres /var/log/postgresql.log chmod 600 /var/log/postgresql.log @@ -430,13 +432,13 @@ init_postgres_dir() # User-modified file from the previous old version of CFEngine exists, try to use it. cp -a "$BACKUP_DIR/data/postgresql.conf.modified" "$PREFIX/state/pg/data/postgresql.conf" failure=0 - (cd /tmp && su --login cfpostgres -c "$PREFIX/bin/pg_ctl -w -D $PREFIX/state/pg/data -l /var/log/postgresql.log start") || failure=1 + (cd /tmp && su cfpostgres -c "$PREFIX/bin/pg_ctl -w -D $PREFIX/state/pg/data -l /var/log/postgresql.log start") || failure=1 if [ $failure = 0 ]; then wait_for_cf_postgres || failure=1 fi if [ $failure = 0 ]; then # Started successfully, stop it again, the migration requires it to be not running. - (cd /tmp && su --login cfpostgres -c "$PREFIX/bin/pg_ctl -w -D $PREFIX/state/pg/data -l /var/log/postgresql.log stop") || failure=1 + (cd /tmp && su cfpostgres -c "$PREFIX/bin/pg_ctl -w -D $PREFIX/state/pg/data -l /var/log/postgresql.log stop") || failure=1 if [ $failure = 0 ]; then wait_for_cf_postgres_down || failure=1 fi @@ -513,7 +515,7 @@ check_disk_space() { # and then importing it into new one migrate_db_using_pg_upgrade() { - su --login cfpostgres -c "$PREFIX/bin/pg_upgrade --old-bindir=$BACKUP_DIR/bin --new-bindir=$PREFIX/bin --old-datadir=$BACKUP_DIR/data --new-datadir=$PREFIX/state/pg/data" + su cfpostgres -c "$PREFIX/bin/pg_upgrade --old-bindir=$BACKUP_DIR/bin --new-bindir=$PREFIX/bin --old-datadir=$BACKUP_DIR/data --new-datadir=$PREFIX/state/pg/data" } migrate_db_using_pipe() { @@ -521,14 +523,14 @@ migrate_db_using_pipe() { ( set -e # setting up: starting postgres servers and creating fifo - su --login cfpostgres -c "LD_LIBRARY_PATH=$BACKUP_DIR/lib/ $BACKUP_DIR/bin/pg_ctl -w -D $BACKUP_DIR/data/ -o '-p 5433' -l /tmp/postgresql-old.log start" - su --login cfpostgres -c "$PREFIX/bin/pg_ctl -w -D $PREFIX/state/pg/data/ -o '-p 5434' -l /tmp/postgresql-new.log start" - su --login cfpostgres -c "mkfifo pg_stream" + su cfpostgres -c "LD_LIBRARY_PATH=$BACKUP_DIR/lib/ $BACKUP_DIR/bin/pg_ctl -w -D $BACKUP_DIR/data/ -o '-p 5433' -l /tmp/postgresql-old.log start" + su cfpostgres -c "$PREFIX/bin/pg_ctl -w -D $PREFIX/state/pg/data/ -o '-p 5434' -l /tmp/postgresql-new.log start" + su cfpostgres -c "mkfifo pg_stream" # dump from old database to pg_stream - su --login cfpostgres -c "LD_LIBRARY_PATH=$BACKUP_DIR/lib/ $BACKUP_DIR/bin/pg_dumpall --clean --port=5433 >pg_stream" & + su cfpostgres -c "LD_LIBRARY_PATH=$BACKUP_DIR/lib/ $BACKUP_DIR/bin/pg_dumpall --clean --port=5433 >pg_stream" & dump_pid=$! # read into new database from pg_stream - su --login cfpostgres -c "$PREFIX/bin/psql --port=5434 postgres "$BACKUP_DIR/db_dump.sql" + su cfpostgres -c "$PREFIX/bin/pg_ctl -w -D '$PREFIX/state/pg/data/' -l /tmp/postgresql-old.log start" + su cfpostgres -c "$PREFIX/bin/pg_dumpall --clean" >"$BACKUP_DIR/db_dump.sql" ) dump_result=$? set -e @@ -595,7 +597,7 @@ migrate_db_using_dump_file() { # `mv` will not be executed. All the groups are `set +e` on the outside, # so we'll do the next one if previous fails - we'll check their success # afterwards. - su --login cfpostgres -c "$PREFIX/bin/pg_ctl -w -D '$PREFIX/state/pg/data/' stop" + su cfpostgres -c "$PREFIX/bin/pg_ctl -w -D '$PREFIX/state/pg/data/' stop" ( set -e # rename "bin.new" to "bin" (if "bin.new" exists) test -d "$PREFIX/bin.new" @@ -634,7 +636,7 @@ migrate_db_using_dump_file() { # this dir should not exist test ! -d "$PREFIX/bin.new" # and there should be no server running - ! su --login cfpostgres -c "$PREFIX/bin/pg_ctl -w -D '$PREFIX/state/pg/data/' status" >/dev/null + ! su cfpostgres -c "$PREFIX/bin/pg_ctl -w -D '$PREFIX/state/pg/data/' status" >/dev/null ) restore_result=$? set -e @@ -654,11 +656,11 @@ migrate_db_using_dump_file() { # run import cf_console echo "Importing SQL file into new database..." init_postgres_dir "$new_pgconfig_file" "$pgconfig_type" - su --login cfpostgres -c "$PREFIX/bin/pg_ctl -w -D $PREFIX/state/pg/data/ -l /tmp/postgresql-new.log start" - if ! su --login cfpostgres -c "$PREFIX/bin/psql postgres" <"$BACKUP_DIR/db_dump.sql"; then + su cfpostgres -c "$PREFIX/bin/pg_ctl -w -D $PREFIX/state/pg/data/ -l /tmp/postgresql-new.log start" + if ! su cfpostgres -c "$PREFIX/bin/psql postgres" <"$BACKUP_DIR/db_dump.sql"; then restore_failed=1 fi - su --login cfpostgres -c "$PREFIX/bin/pg_ctl -w -D $PREFIX/state/pg/data/ -l /tmp/postgresql-new.log stop" + su cfpostgres -c "$PREFIX/bin/pg_ctl -w -D $PREFIX/state/pg/data/ -l /tmp/postgresql-new.log stop" if [ -n "$restore_failed" -o $DEBUG = 4 ]; then cf_console echo "Importing failed." return 2 @@ -787,7 +789,7 @@ if is_upgrade && [ -d "$BACKUP_DIR/data" ]; then do_migration "$new_pgconfig_file" "$pgconfig_type" fi -(cd /tmp && su --login cfpostgres -c "$PREFIX/bin/pg_ctl -w -D $PREFIX/state/pg/data -l /var/log/postgresql.log start") +(cd /tmp && su cfpostgres -c "$PREFIX/bin/pg_ctl -w -D $PREFIX/state/pg/data -l /var/log/postgresql.log start") #make sure that server is up and listening TRYNO=1 @@ -797,7 +799,7 @@ set +e while [ $TRYNO -le 10 ] do echo -n . - ALIVE=$(cd /tmp && su --login cfpostgres -c "$PREFIX/bin/psql -l 1>/dev/null 2>/dev/null") + ALIVE=$(cd /tmp && su cfpostgres -c "$PREFIX/bin/psql -l 1>/dev/null 2>/dev/null") if [ $? -eq 0 ];then LISTENING=yes @@ -821,27 +823,27 @@ else ( cd /tmp - db_name_list=$(su --login cfpostgres -c "$PREFIX/bin/psql --list") + db_name_list=$(su cfpostgres -c "$PREFIX/bin/psql --list") for db_name in cfdb cfmp cfsettings; do if ! echo "$db_name_list" | grep ${db_name} >/dev/null; then - su --login cfpostgres -c "$PREFIX/bin/createdb -E SQL_ASCII --lc-collate=C --lc-ctype=C -T template0 ${db_name}" + su cfpostgres -c "$PREFIX/bin/createdb -E SQL_ASCII --lc-collate=C --lc-ctype=C -T template0 ${db_name}" fi done - db_user_list=$(su --login cfpostgres -c "$PREFIX/bin/psql -d postgres -c '\du'") + db_user_list=$(su cfpostgres -c "$PREFIX/bin/psql -d postgres -c '\du'") if ! echo "$db_user_list" | grep $MP_APACHE_USER >/dev/null; then - su --login cfpostgres -c "$PREFIX/bin/createuser -S -D -R -w $MP_APACHE_USER" + su cfpostgres -c "$PREFIX/bin/createuser -S -D -R -w $MP_APACHE_USER" fi if ! echo "$db_user_list" | grep root >/dev/null; then - su --login cfpostgres -c "$PREFIX/bin/createuser -d -s -w root" + su cfpostgres -c "$PREFIX/bin/createuser -d -s -w root" fi ) # Create the cfengine mission portal postgres user ( cd /tmp && - if ! su --login cfpostgres -c "$PREFIX/bin/psql -d postgres -c '\du' | grep cfmppostgres >/dev/null"; then - su --login cfpostgres -c "$PREFIX/bin/psql cfmp" < $PREFIX/share/GUI/phpcfenginenova/create_cfmppostgres_user.sql + if ! su cfpostgres -c "$PREFIX/bin/psql -d postgres -c '\du' | grep cfmppostgres >/dev/null"; then + su cfpostgres -c "$PREFIX/bin/psql cfmp" < $PREFIX/share/GUI/phpcfenginenova/create_cfmppostgres_user.sql fi ) @@ -850,24 +852,24 @@ else chown cfpostgres $PREFIX/share/db/*.sql #create database for MISSION PORTAL - (cd /tmp && su --login cfpostgres -c "$PREFIX/bin/psql cfmp" < $PREFIX/share/GUI/phpcfenginenova/pgschema.sql) - (cd /tmp && su --login cfpostgres -c "$PREFIX/bin/psql cfmp" < $PREFIX/share/GUI/phpcfenginenova/ootb_import.sql) + (cd /tmp && su cfpostgres -c "$PREFIX/bin/psql cfmp" < $PREFIX/share/GUI/phpcfenginenova/pgschema.sql) + (cd /tmp && su cfpostgres -c "$PREFIX/bin/psql cfmp" < $PREFIX/share/GUI/phpcfenginenova/ootb_import.sql) #create database for hub internal data ( set -e cd /tmp - chown cfpostgres "$PREFIX/share/db/schema_settings.sql" && su --login cfpostgres -c "$PREFIX/bin/psql cfsettings -f $PREFIX/share/db/schema_settings.sql" && chown root "$PREFIX/share/db/schema_settings.sql" - chown cfpostgres "$PREFIX/share/db/ootb_settings.sql" && su --login cfpostgres -c "$PREFIX/bin/psql cfsettings -f $PREFIX/share/db/ootb_settings.sql" && chown root "$PREFIX/share/db/ootb_settings.sql" + chown cfpostgres "$PREFIX/share/db/schema_settings.sql" && su cfpostgres -c "$PREFIX/bin/psql cfsettings -f $PREFIX/share/db/schema_settings.sql" && chown root "$PREFIX/share/db/schema_settings.sql" + chown cfpostgres "$PREFIX/share/db/ootb_settings.sql" && su cfpostgres -c "$PREFIX/bin/psql cfsettings -f $PREFIX/share/db/ootb_settings.sql" && chown root "$PREFIX/share/db/ootb_settings.sql" # cfdb schema relies on cfsettings already existing for a foreign data wrapper association for shared and personal host groups tables - chown cfpostgres "$PREFIX/share/db/schema.sql" && su --login cfpostgres -c "$PREFIX/bin/psql cfdb -f $PREFIX/share/db/schema.sql" && chown root "$PREFIX/share/db/schema.sql" - chown cfpostgres "$PREFIX/share/db/ootb_import.sql" && su --login cfpostgres -c "$PREFIX/bin/psql cfdb -f $PREFIX/share/db/ootb_import.sql" && chown root "$PREFIX/share/db/ootb_import.sql" + chown cfpostgres "$PREFIX/share/db/schema.sql" && su cfpostgres -c "$PREFIX/bin/psql cfdb -f $PREFIX/share/db/schema.sql" && chown root "$PREFIX/share/db/schema.sql" + chown cfpostgres "$PREFIX/share/db/ootb_import.sql" && su cfpostgres -c "$PREFIX/bin/psql cfdb -f $PREFIX/share/db/ootb_import.sql" && chown root "$PREFIX/share/db/ootb_import.sql" ) ( cd /tmp - su --login cfpostgres -c "$PREFIX/bin/psql cfdb" << EOF + su cfpostgres -c "$PREFIX/bin/psql cfdb" << EOF \set ON_ERROR_STOP true -- revoke create permission on public schema for cfdb database REVOKE CREATE ON SCHEMA public FROM public; @@ -881,7 +883,7 @@ EOF ( cd /tmp - su --login cfpostgres -c "$PREFIX/bin/psql cfsettings" << EOF + su cfpostgres -c "$PREFIX/bin/psql cfsettings" << EOF -- grant permission for apache user to use the cfsettings database GRANT ALL ON DATABASE cfsettings TO $MP_APACHE_USER; GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO $MP_APACHE_USER; @@ -1036,7 +1038,7 @@ if [ -n "$httpds" ]; then fi fi -(cd /tmp && su --login cfpostgres -c "$PREFIX/bin/pg_ctl stop -D $PREFIX/state/pg/data -m smart" || su --login cfpostgres -c "$PREFIX/bin/pg_ctl stop -D $PREFIX/state/pg/data -m fast") +(cd /tmp && su cfpostgres -c "$PREFIX/bin/pg_ctl stop -D $PREFIX/state/pg/data -m smart" || su cfpostgres -c "$PREFIX/bin/pg_ctl stop -D $PREFIX/state/pg/data -m fast") ## # ENT-3921: Make bin/runalerts.php executable diff --git a/packaging/common/cfengine-hub/preinstall.sh b/packaging/common/cfengine-hub/preinstall.sh index c6bd28195..ad0022f6a 100644 --- a/packaging/common/cfengine-hub/preinstall.sh +++ b/packaging/common/cfengine-hub/preinstall.sh @@ -1,4 +1,5 @@ - +# force locale to C as recommended by postgresql docs https://www.postgresql.org/docs/current/locale.html +export LC_ALL=C if is_upgrade; then # This is nice to know to provide fixes for bugs in already released @@ -169,9 +170,9 @@ ensure_postgres_terminated() { if [ -x "$PREFIX/bin/pg_ctl" ]; then (cd /tmp && - su --login cfpostgres -c "$PREFIX/bin/pg_ctl stop -D $PREFIX/state/pg/data -m smart" || + su cfpostgres -c "$PREFIX/bin/pg_ctl stop -D $PREFIX/state/pg/data -m smart" || # '-m fast' quits directly, without proper session shutdown - su --login cfpostgres -c "$PREFIX/bin/pg_ctl stop -D $PREFIX/state/pg/data -m fast") + su cfpostgres -c "$PREFIX/bin/pg_ctl stop -D $PREFIX/state/pg/data -m fast") else cf_console echo "No pg_ctl found at $PREFIX/bin/pg_ctl, aborting" return 1