From 83189ec0e09f104e8420d9fee9726ca1b914a394 Mon Sep 17 00:00:00 2001 From: Praveen Arimbrathodiyil Date: Fri, 21 Apr 2017 12:47:11 +0530 Subject: [PATCH] use dbconfig-common for database --- debian/config | 13 +++++++++++++ debian/control | 1 + debian/grantpriv.sh | 25 ------------------------- debian/install | 1 - debian/postinst | 11 ++++------- 5 files changed, 18 insertions(+), 33 deletions(-) delete mode 100755 debian/grantpriv.sh diff --git a/debian/config b/debian/config index cb714ed918..f88ea2f6df 100755 --- a/debian/config +++ b/debian/config @@ -42,3 +42,16 @@ fi # Do you want to change gitlab user? db_input high gitlab/user || true db_go +db_get gitlab/user +gitlab_user=$RET + +# source dbconfig-common shell library, and call the hook function +if [ -f /usr/share/dbconfig-common/dpkg/config ]; then + . /usr/share/dbconfig-common/dpkg/config + + dbc_dbtypes="pgsql" + dbc_dbname="gitlab_production" + dbc_dbuser="$gitlab_user" + + dbc_go $gitlab_user "$@" +fi diff --git a/debian/control b/debian/control index 3d3863c07e..32671cbaa3 100644 --- a/debian/control +++ b/debian/control @@ -22,6 +22,7 @@ Depends: ${shlibs:Depends}, ${misc:Depends}, ruby | ruby-interpreter, rake, bundler, postgresql-client, + dbconfig-pgsql | dbconfig-no-thanks, adduser (>= 3.34~), bc, postgresql-contrib, diff --git a/debian/grantpriv.sh b/debian/grantpriv.sh deleted file mode 100755 index 63ce624afd..0000000000 --- a/debian/grantpriv.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh -set -e - -dbname=gitlab_production - -# Take gitlab_user from envornment variable or use gitlab -gitlab_user=${gitlab_user:-gitlab} - -# If gitlab user cannot access gitlab_production, -# then it means the gitlab role does not exist -if ! su ${gitlab_user} -c 'psql gitlab_production -c ""' -then - echo "Create ${gitlab_user} user with create database privillege..." - su postgres -c "psql -c \"CREATE USER ${gitlab_user} CREATEDB;\"" -fi - -# By default the gitlab_prodcution is not owned by gitlab user -echo "Make ${gitlab_user} user owner of $dbname database..." -su postgres -c "psql -c \"ALTER DATABASE $dbname OWNER to ${gitlab_user};\"" - -echo "Grant all privileges to ${gitlab_user} user..." -su postgres -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE template1 to ${gitlab_user};\"" - -# enable the pg_trgm extension -su postgres -c "psql -d $dbname -c \"CREATE EXTENSION IF NOT EXISTS pg_trgm;\"" diff --git a/debian/install b/debian/install index f7bed76108..0d1e9464b9 100644 --- a/debian/install +++ b/debian/install @@ -11,7 +11,6 @@ debian/conf/tmpfiles.d/gitlab.conf.example usr/lib/gitlab/templates/tmpfiles.d debian/conf/nginx.conf.example usr/lib/gitlab/templates debian/conf/nginx.ssl.conf.example usr/lib/gitlab/templates debian/adduser.sh usr/lib/gitlab/scripts -debian/grantpriv.sh usr/lib/gitlab/scripts debian/rake-tasks.sh usr/lib/gitlab/scripts debian/gitlab-check.sh usr/lib/gitlab/scripts app usr/share/gitlab diff --git a/debian/postinst b/debian/postinst index 256c748217..db7fb38275 100755 --- a/debian/postinst +++ b/debian/postinst @@ -20,6 +20,7 @@ gitlab_debian_defaults_copy=/var/lib/gitlab/gitlab-debian.defaults # Show debconf questions . /usr/share/debconf/confmodule +. /usr/share/dbconfig-common/dpkg/postinst # summary of how this script can be called: # * `configure' @@ -310,15 +311,11 @@ case "$1" in echo "Reloading nginx configuration..." invoke-rc.d nginx reload fi + dbc_go gitlab "$@" db_stop - echo "Create database if not present" - if ! su postgres -s /bin/sh -c "psql gitlab_production -c ''"; then - su postgres -c 'createdb -E unicode -T template0 gitlab_production' - fi - - # Adjust database privileges - . /usr/lib/gitlab/scripts/grantpriv.sh + # enable the pg_trgm extension + su postgres -c "psql -d gitlab_production -c \"CREATE EXTENSION IF NOT EXISTS pg_trgm;\"" # Remove Gemfile.lock if present rm -f ${gitlab_data_dir}/Gemfile.lock