[DRE-commits] [gitlab] 01/02: use postgres commands to create database

Praveen Arimbrathodiyil praveen at moszumanska.debian.org
Sun Nov 1 14:30:59 UTC 2015


This is an automated email from the git hooks/post-receive script.

praveen pushed a commit to branch master
in repository gitlab.

commit f7ca08b540dfb4064b70304b4ac7cde6c2a0da14
Author: Praveen Arimbrathodiyil <praveen at debian.org>
Date:   Sun Nov 1 19:50:55 2015 +0530

    use postgres commands to create database
---
 debian/config       |  5 +----
 debian/grantpriv.sh | 24 ++++++++++++++++++++++++
 debian/install      |  1 +
 debian/postinst     |  7 ++++++-
 4 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/debian/config b/debian/config
index d2720f4..8db43ff 100644
--- a/debian/config
+++ b/debian/config
@@ -3,9 +3,6 @@
  
 set -e
 
+echo "Call debconf to configure gitlab"
 # source debconf stuffs
 . /usr/share/debconf/confmodule
-
-# DB password can be left blank
-db_input high gitlab/dbpass || true
-db_go || true
diff --git a/debian/grantpriv.sh b/debian/grantpriv.sh
new file mode 100755
index 0000000..66c1f2d
--- /dev/null
+++ b/debian/grantpriv.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+user=gitlab
+dbname=gitlab_production
+
+if su gitlab -c 'psql gitlab_production -c ""'
+then
+	echo "Create $user user with create database privillege..."
+	sudo -u postgres psql -c "CREATE USER $user CREATEDB;" || {
+	  exit 1 
+	  }
+fi
+
+echo "Make $user user owner of $dbname database..."
+sudo -u postgres psql -c "ALTER DATABASE $dbname OWNER to $user;" || {
+  exit 1 
+  }
+
+echo "Grant all privileges to $user user..."
+sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE template1 to $user;"|| {
+  exit 1
+  }
+
+
diff --git a/debian/install b/debian/install
index ec6aabf..e4f9bb1 100644
--- a/debian/install
+++ b/debian/install
@@ -2,6 +2,7 @@ debian/database.yml etc/gitlab
 debian/gitlab.yml etc/gitlab
 debian/gitlab-debian.conf etc/gitlab
 debian/adduser.sh usr/lib/gitlab/scripts
+debian/grantpriv.sh usr/lib/gitlab/scripts
 debian/rake-tasks.sh usr/lib/gitlab/scripts
 app usr/share/gitlab
 bin usr/share/gitlab
diff --git a/debian/postinst b/debian/postinst
index bab6d1e..10d8313 100755
--- a/debian/postinst
+++ b/debian/postinst
@@ -32,10 +32,15 @@ case "$1" in
 	. /usr/lib/gitlab/scripts/adduser.sh
 	chown -R ${gitlab_user}: ${gitlab_home}
 	cd ${gitlab_home}
-	
 	# Show debconf questions
         . /usr/share/debconf/confmodule
+	echo "Create database if not present"
+	if ! su gitlab -s /bin/sh -c "psql  gitlab_production -c ''"
+	then
+		su postgres -c 'createdb gitlab_production'
+	fi
 
+	. /usr/lib/gitlab/scripts/grantpriv.sh
 	echo "Setting up environment varibales..."
 	export RAILS_ENV=production
 	export DB=postgres

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/gitlab.git



More information about the Pkg-ruby-extras-commits mailing list