[med-svn] r16062 - in trunk/packages/gnuhealth/trunk/debian: . database-scripts/install database-scripts/upgrade/pgsql

Emilien Klein e2jk-guest at moszumanska.debian.org
Tue Feb 18 21:44:17 UTC 2014


Author: e2jk-guest
Date: 2014-02-18 21:44:16 +0000 (Tue, 18 Feb 2014)
New Revision: 16062

Added:
   trunk/packages/gnuhealth/trunk/debian/gnuhealth-server.preinst
Modified:
   trunk/packages/gnuhealth/trunk/debian/changelog
   trunk/packages/gnuhealth/trunk/debian/database-scripts/install/pgsql
   trunk/packages/gnuhealth/trunk/debian/database-scripts/upgrade/pgsql/2.0.0
   trunk/packages/gnuhealth/trunk/debian/gnuhealth-server.postinst
Log:
Overhaul of the upgrade process in preparation of new GNU Health version 2.4.1.
Now the database gets backed up by preinst, and updated by postinst.
If upstream-provided upgrade scripts need to be run, that is handled by dbconfig-common.


Modified: trunk/packages/gnuhealth/trunk/debian/changelog
===================================================================
--- trunk/packages/gnuhealth/trunk/debian/changelog	2014-02-18 19:30:59 UTC (rev 16061)
+++ trunk/packages/gnuhealth/trunk/debian/changelog	2014-02-18 21:44:16 UTC (rev 16062)
@@ -1,3 +1,15 @@
+gnuhealth (2.4.1-1) experimental; urgency=low
+
+  * New upstream release
+  * Move the dbconfig-common upgrade script to the correct place
+    (DBTYPE/VERSION instead of just DBTYPE)
+  * Create gnuhealth-server.preinst, and overhaul of the upgrade process.
+    Now the database gets backed up by preinst, and updated by postinst.
+    If upstream-provided upgrade scripts need to be run, that is handled
+    by dbconfig-common.
+
+ -- Emilien Klein <emilien+debian at klein.st>  Tue, 18 Feb 2014 19:10:47 +0100
+
 gnuhealth (2.4.0-2) unstable; urgency=low
 
   * Upload to unstable

Modified: trunk/packages/gnuhealth/trunk/debian/database-scripts/install/pgsql
===================================================================
--- trunk/packages/gnuhealth/trunk/debian/database-scripts/install/pgsql	2014-02-18 19:30:59 UTC (rev 16061)
+++ trunk/packages/gnuhealth/trunk/debian/database-scripts/install/pgsql	2014-02-18 21:44:16 UTC (rev 16062)
@@ -8,11 +8,9 @@
 
 GNUHEALTH_USER="gnuhealth"
 GNUHEALTH_HOMEDIR="/var/lib/gnuhealth"
+GNUHEALTH_NODBUPDATEFILE="${GNUHEALTH_HOMEDIR}/no-db-update"
 GNUHEALTH_CONFFILE="/etc/gnuhealth/gnuhealth-server.conf"
 
-# Start printing output on a new line
-echo
-
 # Create system user
 adduser --home ${GNUHEALTH_HOMEDIR} --quiet --system --group ${GNUHEALTH_USER}
 
@@ -28,5 +26,8 @@
 # default authentication is set to peer method)
 sudo -u postgres psql -U postgres -c 'ALTER DATABASE gnuhealth OWNER TO gnuhealth'
 
+# Create a temporary file that indicates we've just created the database.
+# Will be used in postinst to know not to update the database.
+touch ${GNUHEALTH_NODBUPDATEFILE}
+
 exit 0
-

Modified: trunk/packages/gnuhealth/trunk/debian/database-scripts/upgrade/pgsql/2.0.0
===================================================================
--- trunk/packages/gnuhealth/trunk/debian/database-scripts/upgrade/pgsql/2.0.0	2014-02-18 19:30:59 UTC (rev 16061)
+++ trunk/packages/gnuhealth/trunk/debian/database-scripts/upgrade/pgsql/2.0.0	2014-02-18 21:44:16 UTC (rev 16062)
@@ -6,18 +6,14 @@
 # Source the config file from dbconfig-common
 . /etc/dbconfig-common/gnuhealth-server.conf
 
-GNUHEALTH_CONFFILE="/etc/gnuhealth/gnuhealth-server.conf"
-BACKUP_FILE="/var/lib/gnuhealth/backups/backup_${dbc_dbname}_`date +\%F_\%H-\%M-\%S`.sql"
+echo "Applying upgrade script for version 2.0"
 
-# Start printing output on a new line
-echo
+# A backup of the database was already created by gnuhealth-server.preinst
 
-# Make a backup of the database prior to upgrading
-sudo -u ${dbc_dbuser} pg_dump gnuhealth > ${BACKUP_FILE}
 # Run the pre script provided by upstream
 sudo -u ${dbc_dbuser} python /usr/share/gnuhealth/scripts/upgrade/2.0/pre.py --pg="dbname=${dbc_dbname}"
-# Upgrade the gnuhealth database
-sudo -u ${dbc_dbuser} trytond --database=${dbc_dbname} --update=all --config=${GNUHEALTH_CONFFILE}
 
+# Upgrading the database will be done by gnuhealth-server.postinst
+
 exit 0
 

Modified: trunk/packages/gnuhealth/trunk/debian/gnuhealth-server.postinst
===================================================================
--- trunk/packages/gnuhealth/trunk/debian/gnuhealth-server.postinst	2014-02-18 19:30:59 UTC (rev 16061)
+++ trunk/packages/gnuhealth/trunk/debian/gnuhealth-server.postinst	2014-02-18 21:44:16 UTC (rev 16062)
@@ -29,6 +29,7 @@
 
 GNUHEALTH_USER="gnuhealth"
 GNUHEALTH_HOMEDIR="/var/lib/gnuhealth"
+GNUHEALTH_NODBUPDATEFILE="${GNUHEALTH_HOMEDIR}/no-db-update"
 GNUHEALTH_LOGDIR="/var/log/gnuhealth"
 GNUHEALTH_CONFFILE="/etc/gnuhealth/gnuhealth-server.conf"
 
@@ -47,6 +48,22 @@
 		# Setting ownership and permissions on configuration file
 		chown ${GNUHEALTH_USER}:${GNUHEALTH_USER} ${GNUHEALTH_CONFFILE}
 		chmod 0440 ${GNUHEALTH_CONFFILE}
+
+		# Check if the DB should not be updated
+		if [ ! -f ${GNUHEALTH_NODBUPDATEFILE} ]; then
+			# Source the config file from dbconfig-common
+			. /etc/dbconfig-common/gnuhealth-server.conf
+
+			# Update the gnuhealth database
+			echo "Updating the '${dbc_dbname}' database"
+			sudo -u ${dbc_dbuser} trytond --database=${dbc_dbname} --update=all \
+				--config=${GNUHEALTH_CONFFILE}
+		else
+			# Do not update the database, as it's just been created.
+			# Just remove the temporary file, so that the database will be updated next time.
+			echo "The database was just created, no need to update it now."
+			rm ${GNUHEALTH_NODBUPDATEFILE}
+		fi
     ;;
 
     abort-upgrade|abort-remove|abort-deconfigure)

Added: trunk/packages/gnuhealth/trunk/debian/gnuhealth-server.preinst
===================================================================
--- trunk/packages/gnuhealth/trunk/debian/gnuhealth-server.preinst	                        (rev 0)
+++ trunk/packages/gnuhealth/trunk/debian/gnuhealth-server.preinst	2014-02-18 21:44:16 UTC (rev 16062)
@@ -0,0 +1,50 @@
+#!/bin/sh
+# preinst script for gnuhealth-server
+#
+# see: dh_installdeb(1)
+
+set -e
+
+# summary of how this script can be called:
+#        * <new-preinst> `install'
+#        * <new-preinst> `install' <old-version>
+#        * <new-preinst> `upgrade' <old-version>
+#        * <old-preinst> `abort-upgrade' <new-version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+
+
+case "$1" in
+    upgrade)
+        # Make a backup and upgrade the database when upgrading from a previous version
+        # Source the config file from dbconfig-common
+        . /etc/dbconfig-common/gnuhealth-server.conf
+
+        BACKUP_FOLDER="/var/lib/gnuhealth/backups"
+        BACKUP_FILE="${BACKUP_FOLDER}/backup_${dbc_dbname}_v$2_`date +\%F_\%H-\%M-\%S`.sql"
+
+        #Create the backup directory if it doesn't already exist
+        mkdir -p ${BACKUP_FOLDER}
+        chown ${dbc_dbuser}:${dbc_dbuser} ${BACKUP_FOLDER}
+
+        # Make a backup of the database prior to upgrading from a previous version
+        echo "Backing up database '${dbc_dbname}' to ${BACKUP_FILE}"
+        sudo -u ${dbc_dbuser} pg_dump gnuhealth > ${BACKUP_FILE}
+        chown ${dbc_dbuser}:${dbc_dbuser} ${BACKUP_FILE}
+    ;;
+
+    install|abort-upgrade)
+    ;;
+
+    *)
+        echo "preinst called with unknown argument \`$1'" >&2
+        exit 1
+    ;;
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0




More information about the debian-med-commit mailing list