@@ -237,6 +237,8 @@ function step_default_envs() {
237237 POSTGRES_PROVISION_REMOTE_DB=" ${POSTGRES_PROVISION_REMOTE_DB:- FALSE} "
238238 POSTGRES_REMOTE_ADMIN_USER=" ${POSTGRES_REMOTE_ADMIN_USER:- postgres_admin} "
239239 POSTGRES_REMOTE_ADMIN_PASSWORD=" ${POSTGRES_REMOTE_ADMIN_PASSWORD:- } "
240+ # two digit Postgresql version other than distro-repo default - this is supported for Ubuntu only - example values "15" or "16"
241+ POSTGRES_VERSION=" ${POSTGRES_VERSION:- } "
240242
241243 # smtp env vars
242244 SMTP_HOST=" ${SMTP_HOST:- localhost} "
@@ -654,8 +656,7 @@ function step_postgres_configure() {
654656 fi
655657 ;;
656658
657- \
658- _rhel)
659+ _rhel)
659660 if [ ! -e " /etc/yum.repos.d/pgdg-redhat-all.repo" ]; then
660661 sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
661662 # Disable the built-in PostgreSQL module:
@@ -685,43 +686,58 @@ function step_postgres_configure() {
685686 ;;
686687
687688 _ubuntu)
688- # TODO add platform version for 20.04 only
689- # for version 11
690- # Create the file repository configuration:
691- # sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
692-
693- # Import the repository signing key:
694- # wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
695689 sudo DEBIAN_PRIORITY=critical DEBIAN_FRONTEND=noninteractive apt-get update
696- # Postgresql 12 included in Ubuntu 20.04
690+ # Postgresql 12 included in Ubuntu 20.04 APT repo - otherwise install from Postgresql repos
697691 if [ " $POSTGRES_SVR_LOCAL " == " TRUE" ]; then
698692 if [ " $( platform_version) " == " 20.04" ]; then
699- sudo DEBIAN_PRIORITY=critical DEBIAN_FRONTEND=noninteractive apt-get -y install postgresql-12
693+ if [[ -n $POSTGRES_VERSION && $POSTGRES_VERSION != " 12" ]]; then
694+ sudo sh -c ' echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
695+ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
696+ sudo DEBIAN_PRIORITY=critical DEBIAN_FRONTEND=noninteractive apt-get update
697+ sudo DEBIAN_PRIORITY=critical DEBIAN_FRONTEND=noninteractive apt-get -y install " postgresql-$POSTGRES_VERSION "
698+ else
699+ sudo DEBIAN_PRIORITY=critical DEBIAN_FRONTEND=noninteractive apt-get -y install postgresql-12
700+ fi
700701 fi
701- # Postgresql 14 included in Ubuntu 22.04
702+ # Postgresql 14 included in Ubuntu 22.04 APT repo - otherwise install from Postgresql repos
702703 if [ " $( platform_version) " == " 22.04" ]; then
703- sudo DEBIAN_PRIORITY=critical DEBIAN_FRONTEND=noninteractive apt-get -y install postgresql-14
704+ if [[ -n $POSTGRES_VERSION && $POSTGRES_VERSION != " 14" ]]; then
705+ sudo sh -c ' echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
706+ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
707+ sudo DEBIAN_PRIORITY=critical DEBIAN_FRONTEND=noninteractive apt-get update
708+ sudo DEBIAN_PRIORITY=critical DEBIAN_FRONTEND=noninteractive apt-get -y install " postgresql-$POSTGRES_VERSION "
709+ else
710+ sudo DEBIAN_PRIORITY=critical DEBIAN_FRONTEND=noninteractive apt-get -y install postgresql-14
711+ fi
704712 fi
705- # Not needed for conical postgresql package
706- # if [ ! -f /var/lib/postgresql/12/main/PG_VERSION ]; then
707- # /usr/pgsql-11/bin/postgresql-11-setup initdb
708- # fi
709713
710714 sudo systemctl enable postgresql
711715 sudo systemctl start postgresql
712716 sudo -u postgres psql -c " create user $POSTGRES_USER password '$POSTGRES_PASSWORD ';"
713717 sudo -u postgres psql -c " create database $POSTGRES_DB with owner $POSTGRES_USER ;"
714718 sudo -u postgres psql -c " revoke all on database $POSTGRES_DB from public;"
715- # This may not be needed on ubuntu
716- # sed -i 's/host all all 127.0.0.1\/32 ident/host all all 127.0.0.1\/32 md5/' /etc/postgresql/12/main/pg_hba.conf
717719 sudo systemctl restart postgresql
718720 console_msg " Postgres Server and Client Installed ..."
719721 else
720722 if [ " $( platform_version) " == " 20.04" ]; then
721- sudo DEBIAN_PRIORITY=critical DEBIAN_FRONTEND=noninteractive apt-get -y install postgresql-client-12
723+ if [[ -n $POSTGRES_VERSION && $POSTGRES_VERSION != " 12" ]]; then
724+ sudo sh -c ' echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
725+ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
726+ sudo DEBIAN_PRIORITY=critical DEBIAN_FRONTEND=noninteractive apt-get update
727+ sudo DEBIAN_PRIORITY=critical DEBIAN_FRONTEND=noninteractive apt-get -y install " postgresql-client-$POSTGRES_VERSION "
728+ else
729+ sudo DEBIAN_PRIORITY=critical DEBIAN_FRONTEND=noninteractive apt-get -y install postgresql-client-12
730+ fi
722731 fi
723732 if [ " $( platform_version) " == " 22.04" ]; then
724- sudo DEBIAN_PRIORITY=critical DEBIAN_FRONTEND=noninteractive apt-get -y install postgresql-client-14
733+ if [[ -n $POSTGRES_VERSION && $POSTGRES_VERSION != " 14" ]]; then
734+ sudo sh -c ' echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
735+ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
736+ sudo DEBIAN_PRIORITY=critical DEBIAN_FRONTEND=noninteractive apt-get update
737+ sudo DEBIAN_PRIORITY=critical DEBIAN_FRONTEND=noninteractive apt-get -y install " postgresql-client-$POSTGRES_VERSION "
738+ else
739+ sudo DEBIAN_PRIORITY=critical DEBIAN_FRONTEND=noninteractive apt-get -y install postgresql-client-14
740+ fi
725741 fi
726742 console_msg " Postgres Client Installed ..."
727743 fi
@@ -906,7 +922,7 @@ function step_tomcat_service_embedded() {
906922 fi
907923
908924}
909-
925+ # shellcheck disable=SC2120
910926function step_tomcat_service_standard() {
911927 if _skip_step " ${FUNCNAME[0]/ step_/ } " ; then return 0; fi
912928
@@ -960,6 +976,30 @@ function step_tomcat_service_standard() {
960976 fi
961977 fi
962978
979+ # Create Labkey Service script - prevents unexpected shutdown of LabKey service during upgrades etc.
980+ NewScript=" $TOMCAT_INSTALL_HOME /bin/labkey_service.sh"
981+ (
982+ /bin/cat << -HERE_LABKEY_SERVICE_SCRIPT
983+ #!/usr/bin/env bash
984+
985+ OPERATION="\$ 1"
986+
987+ if [[ "\$ OPERATION" == 'stop' ]]; then
988+ # wait for labkey upgrade to complete before stopping tomcat
989+ LOCKFILE="$LABKEY_INSTALL_HOME /labkeyUpgradeLockFile"
990+
991+ while [ -f "\$ LOCKFILE" ]; do
992+ sleep 3
993+ done
994+
995+ fi
996+
997+ "$TOMCAT_INSTALL_HOME /bin/catalina.sh" \$ @
998+
999+ HERE_LABKEY_SERVICE_SCRIPT
1000+ ) > " $NewScript "
1001+ chmod 755 " $NewScript "
1002+
9631003 # Create Standard Tomcat Systemd service file -
9641004
9651005 # create tomcat_lk systemd service file
@@ -982,8 +1022,8 @@ function step_tomcat_service_standard() {
9821022 OOMScoreAdjust=-500
9831023
9841024
985- ExecStart=$TOMCAT_INSTALL_HOME /bin/catalina .sh start
986- ExecStop=$TOMCAT_INSTALL_HOME /bin/catalina .sh stop
1025+ ExecStart=$TOMCAT_INSTALL_HOME /bin/labkey_service .sh start
1026+ ExecStop=$TOMCAT_INSTALL_HOME /bin/labkey_service .sh stop
9871027 SuccessExitStatus=0 143
9881028 Restart=on-failure
9891029 RestartSec=2
0 commit comments