Skip to content

Commit

Permalink
fixup! Remove local DB code from setup scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
cbosdo committed Feb 19, 2025
1 parent 1d33cbb commit 4126f80
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 144 deletions.
2 changes: 0 additions & 2 deletions containers/server-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ RUN echo "rpm.install.excludedocs = yes" >>/etc/zypp/zypp.conf && \
${PRODUCT_PATTERN_PREFIX}_retail \
spacewalk-backend-sql-postgresql \
spacewalk-java-postgresql \
postgresql16-contrib \
postgresql16-server \
postgresql16 \
billing-data-service \
grub2-x86_64-efi \
Expand Down
138 changes: 3 additions & 135 deletions spacewalk/uyuni-setup-reportdb/bin/uyuni-setup-reportdb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ set -e
help() {
echo "Usage: $(basename $0) create [options]" >&2
echo " $(basename $0) remove [options]" >&2
echo " $(basename $0) check [options]" >&2
echo ""
echo "Options for the 'create' command:"
echo " --db <database-name> Name of the database to create"
Expand All @@ -26,10 +25,6 @@ help() {
echo "Options for the 'remove' command:"
echo " --db <database-name> Name of the database to remove"
echo " --user <username> Name of the user to remove"
echo ""
echo "Options for the 'check' command:"
echo " --db <database-name> Name of the database to check for"
echo " --user <username> Name of the user to check for"
}

ask() {
Expand Down Expand Up @@ -93,25 +88,9 @@ def_regexes() {
def_regexes
unset -f def_regexes

PG_DATA=$(runuser -l postgres -c env | grep PGDATA | cut -f2- -d=)
PG_HBA="$PG_DATA/pg_hba.conf"
PG_IDENT="$PG_DATA/pg_ident.conf"
POSTGRESQL="$PG_DATA/postgresql.conf"
PORT=5432
PG_PIDFILE="/run/postmaster.$PORT.pid"
if isSUSE ; then
PG_PIDFILE="$PG_DATA/postmaster.pid"
fi
PG_SOCKET="/tmp/.s.PGSQL.$PORT"
SPACEWALK_TARGET="/usr/lib/systemd/system/spacewalk.target"
SERVICE_LIST="/etc/rhn/service-list"
RHN_CONF="/etc/rhn/rhn.conf"

LSOF="/usr/sbin/lsof"
if [ -x /usr/bin/lsof ]; then
LSOF="/usr/bin/lsof"
fi
RUNUSER=runuser
SSL_CERT=/etc/pki/tls/certs/spacewalk.crt
SSL_KEY=/etc/pki/tls/private/pg-spacewalk.key
CA_CERT=/etc/pki/trust/anchors/LOCAL-RHN-ORG-TRUSTED-SSL-CERT
Expand Down Expand Up @@ -166,14 +145,8 @@ EOF
rhn_reconfig "report_db_name" "$PGNAME"
rhn_reconfig "report_db_host" "$HOST"
rhn_reconfig "report_db_port" "$PORT"
if ! $LOCAL ; then
rhn_reconfig "report_db_ssl_enabled" "1"
if [ $EXTERNALDB = "0" ] ; then
rhn_reconfig "report_db_sslrootcert" "$CA_CERT"
else
rhn_reconfig "report_db_sslrootcert" "$EXTERNALDB_ROOT_CERT"
fi
fi
rhn_reconfig "report_db_ssl_enabled" "1"
rhn_reconfig "report_db_sslrootcert" "$EXTERNALDB_ROOT_CERT"
fi

chmod 640 $RHN_CONF
Expand Down Expand Up @@ -219,43 +192,6 @@ remove() {

}

check() {
if [ -z "$PGUSER" -a -z "$PGNAME" ] ; then
help
exit 1
fi

postgresql_service status >& /dev/null || postgresql_service start

RET=0
if [ -n "$PGUSER" ] ; then
if exists_user ; then
echo "User \"$PGUSER\" already exists"
else
echo "User \"$PGUSER\" does not exist"
RET=1
fi
fi
if [ -n "$PGNAME" ] ; then
if exists_db ; then
echo "Database \"$PGNAME\" already exists"
else
echo "Database \"$PGNAME\" does not exist"
RET=1
fi
fi
exit $RET
}

is_postgres10() {
NUM=$($RUNUSER postgres -c 'psql -t -c "SHOW server_version_num;"')
if (( $NUM > 100000 )) ; then
return 0
else
return 1
fi
}

exists_db() {
EXISTS=$(echo "select datname from pg_database where datname='$PGNAME';" | (export PGPASSWORD=$EXTERNALDB_ADMIN_PASS; exec psql -t -U $EXTERNALDB_ADMIN_USER -h $HOST ))
if [ "x$EXISTS" == "x $PGNAME" ] ; then
Expand Down Expand Up @@ -296,72 +232,10 @@ rhn_reconfig() {
fi
}

postgres_reconfig() {
if grep -E "^$1[[:space:]]*=" $POSTGRESQL >/dev/null; then
sed -i "s|^$1[[:space:]]*=.*|$1 = $2|" $POSTGRESQL
else
echo "$1 = $2" >> $POSTGRESQL
fi
}

pg_hba_set() {
if ! grep -E "^$1[[:space:]]+$2[[:space:]]+$3[[:space:]]+$4[[:space:]]*$5" $PG_HBA >/dev/null; then
echo -e "$1\t$2\t$3\t$4\t$5" >> $PG_HBA
fi
}

pg_hba_remove() {
sed -i "s|^$1[[:space:]]\+$2[[:space:]]\+$3[[:space:]].*||g" $PG_HBA
}

postgresql_service() {
POSTGRESQL_SERVICE=$(systemctl list-unit-files | grep -m 1 postgresql | cut -f1 -d. | tr -d '\n')
case $1 in
initdb)
if isSUSE ; then
# the start script initialize the DB
if ! test -e $PG_PIDFILE; then
$RUNUSER postgres -c "/usr/share/postgresql/postgresql-script start"
fi
else
${POSTGRESQL_SERVICE}-setup initdb
fi
;;
status)
if $LOCAL ; then
pgrep -x postgresql >/dev/null && return 1 || return 0
else
systemctl $1 ${POSTGRESQL_SERVICE}
fi
;;
enable)
if ! $LOCAL ; then
systemctl $1 ${POSTGRESQL_SERVICE}
fi
;;
*)
echo ">> $1"
$RUNUSER postgres -c "/usr/share/postgresql/postgresql-script $1"
;;
esac
}

test_postgres_user() {
set +e
su postgres -c /bin/true
if [ $? != "0" ] ; then
echo "Cannot use postgres user. Terminating" >&2
exit 1
fi
set -e
}

OPTS=$(getopt --longoptions=db:,user:,password:,autogenpw,standalone,local,help,address:,remote:,host:,externaldb-admin-user:,externaldb-admin-password:,externaldb-root-cert:,externaldb-provider: -n ${0##*/} -- d:u:p:gsha:r:l: "$@")
OPTS=$(getopt --longoptions=db:,user:,password:,autogenpw,standalone,help,address:,remote:,host:,externaldb-admin-user:,externaldb-admin-password:,externaldb-root-cert:,externaldb-provider: -n ${0##*/} -- d:u:p:gsha:r:l: "$@")

if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi

test_postgres_user

eval set -- "$OPTS"

PGNAME=""
Expand All @@ -370,7 +244,6 @@ PGPASSWORD=""
STANDALONE=false
ADDRESS=""
REMOTE=""
LOCAL=false
HOST=""
EXTERNALDB_ADMIN_USER=""
EXTERNALDB_ADMIN_PASS=""
Expand Down Expand Up @@ -417,9 +290,6 @@ while true ; do
help;
exit 0;
;;
-l|--local)
LOCAL=true
;;
--host)
HOST=$2
shift
Expand Down Expand Up @@ -461,8 +331,6 @@ case $1 in
;;
remove) remove
;;
check) check
;;
*) help
;;
esac
3 changes: 0 additions & 3 deletions susemanager/bin/mgr-setup
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ db-password=$MANAGER_PASS
db-name=$MANAGER_DB_NAME
db-host=$MANAGER_DB_HOST
db-port=$MANAGER_DB_PORT
db-protocol=$MANAGER_DB_PROTOCOL
externaldb-admin-user=$EXTERNALDB_ADMIN_USER
externaldb-admin-password=$EXTERNALDB_ADMIN_PASS
db-ca-cert=$MANAGER_DB_CA_CERT
Expand Down Expand Up @@ -236,15 +235,13 @@ do_setup() {
ask_input MANAGER_DB_HOST
ask_input MANAGER_DB_PORT
ask_input MANAGER_DB_CA_CERT
ask_input MANAGER_DB_PROTOCOL
ask_input MANAGER_ENABLE_TFTP
ask_input EXTERNALDB_ADMIN_USER
ask_input EXTERNALDB_ADMIN_PASS
ask_input EXTERNALDB_PROVIDER
ask_input SCC_USER
ask_input SCC_PASS
ask_input ISS_PARENT
ask_input ACTIVATE_SLP
ask_input REPORT_DB_NAME
ask_input REPORT_DB_HOST
ask_input REPORT_DB_PORT
Expand Down
3 changes: 1 addition & 2 deletions testsuite/features/step_definitions/command_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1154,8 +1154,7 @@
"[email protected]\n" \
"INSTALL_MONITORING=n\n" \
"POPULATE_CONFIG_CHANNEL=y\n" \
"RHN_USER=admin\n" \
"ACTIVATE_SLP=y\n"
"RHN_USER=admin\n"
settings +=
if running_k3s?
"USE_EXISTING_CERTS=y\n" \
Expand Down
2 changes: 0 additions & 2 deletions testsuite/podman_runner/07_server_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,13 @@ sudo -i podman run --cap-add AUDIT_CONTROL --rm \
-e MANAGER_DB_PORT="5432" \
-e MANAGER_DB_USER="manager" \
-e MANAGER_DB_PASS="manager" \
-e MANAGER_DB_PROTOCOL="TCP" \
-e REPORT_DB_NAME="reportdb" \
-e REPORT_DB_USER="pythia_susemanager" \
-e REPORT_DB_PASS="pythia_susemanager" \
-e EXTERNALDB_ADMIN_USER="" \
-e EXTERNALDB_ADMIN_PASS="" \
-e EXTERNALDB_PROVIDER="" \
-e ISS_PARENT="" \
-e ACTIVATE_SLP="" \
-e SCC_USER="test" \
-e SCC_PASS="test" \
--cgroupns=host \
Expand Down

0 comments on commit 4126f80

Please sign in to comment.