]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add dbconfig-common support
authorMehdi Abaakouk <sileht@sileht.net>
Sun, 16 Sep 2012 08:30:59 +0000 (10:30 +0200)
committerMehdi Abaakouk <sileht@sileht.net>
Sun, 16 Sep 2012 08:30:59 +0000 (10:30 +0200)
Rewritten-From: a92453e9e1544e0562cf2cd9486b954a34170b23

xenial/debian/cinder-common.config
xenial/debian/cinder-common.postinst
xenial/debian/cinder-common.postrm [new file with mode: 0644]
xenial/debian/cinder-common.prerm [new file with mode: 0644]
xenial/debian/cinder-common.templates [new file with mode: 0644]
xenial/debian/cinder-scheduler.postinst
xenial/debian/control

index a7c600744d11a5c9507b435b1742f5e8001e4575..bb9156d2de36b4eeea5491aaf1e8fc260ab24c9e 100644 (file)
@@ -3,27 +3,42 @@ set -e
 
 . /usr/share/debconf/confmodule
 
-NOVA_COM_DEF=/etc/default/nova-common
+CINDER_COM_DEF=/etc/default/cinder-common
 
 # Set the debconf value to whatever is in the config file
-if [ -f ${NOVA_COM_DEF} ] ; then
-    . ${NOVA_COM_DEF}
+if [ -f ${CINDER_COM_DEF} ] ; then
+    . ${CINDER_COM_DEF}
 fi
-if ! [ "${NOVA_ENABLE}" = "true" ] ; then
-    NOVA_ENABLE=false
+if ! [ "${CINDER_ENABLE}" = "true" ] ; then
+    CINDER_ENABLE=false
 fi
-db_set nova-common/start_services ${NOVA_ENABLE}
+db_set cinder-common/start_services ${CINDER_ENABLE}
 
-db_input low nova-common/start_services || true
+db_input low cinder-common/start_services || true
 db_go
 
 # Write a default config file if it doesn't exist yet
 # note that the value will be overwritten by the postinst
-if ! [ -f ${NOVA_COM_DEF} ] ; then
-    echo "# defaults file for nova daemons
+if ! [ -f ${CINDER_COM_DEF} ] ; then
+    echo "# defaults file for cinder daemons
 
-# start nova daemons from init.d script?
+# start cinder daemons from init.d script?
 #  only allowed values are \"true\" and \"false\"
-NOVA_ENABLE=true" >${NOVA_COM_DEF}
+CINDER_ENABLE=true" >${CINDER_COM_DEF}
 fi
 
+db_input high nova-common/configure_db || true
+db_go
+
+db_get cinder-common/configure_db
+if [ "$RET" = "true" ]; then
+    if [ -f /usr/share/dbconfig-common/dpkg/config ]
+    then
+        dbc_dbtypes="sqlite3, mysql, pgsql"
+        dbc_authmethod_user="password"
+        dbc_basepath="/var/lib/cinder"
+        dbc_dbname="cinder"
+        . /usr/share/dbconfig-common/dpkg/config
+        dbc_go cinder-common $@
+    fi
+fi
index 2ac7870ded10a4e2f3af24c2e236c20baf646408..b14acec5c2e5fff36477f84b59ebfc9196ae175e 100644 (file)
@@ -1,38 +1,79 @@
 #!/bin/sh -e
 
-if [ "$1" = "configure" ]; then
+if [ "$1" = "configure" ] || [ "$1" = "reconfigure" ] ; then
     if ! getenv group cinder > /dev/null 2>&1; then
-        addgroup --system cinder >/dev/null
+        addgroup --quiet --system cinder >/dev/null
     fi
 
     if ! getenv passwd cinder > /dev/null 2>&1; then
-        adduser --system --home /var/lib/cinder --ingroup cinder --no-create-home \
+        adduser --quiet --system --home /var/lib/cinder --ingroup cinder --no-create-home \
             --shell /bin/false cinder
     fi
 
+    # Create config files if they don't exist
+    if ! [ -d /etc/cinder ] ; then
+        mkdir /etc/cinder
+    fi
+    if ! [ -e /etc/cinder/cinder.conf ] ; then
+        cp /usr/share/doc/cinder-common/cinder.conf.dist /etc/cinder/cinder.conf
+    fi
+
     chown -R cinder:adm /var/log/cinder
     chmod 0750 /var/log/cinder
     chown -R cinder:cinder /var/lib/cinder /etc/cinder
     chmod 0750 /etc/cinder
     chmod 0440 /etc/sudoers.d/cinder_sudoers
 
+    . /usr/share/debconf/confmodule
+
+    db_get cinder-common/configure_db
+
+    if [ "$RET" = "true" ]; then
+        . /usr/share/dbconfig-common/dpkg/postinst
+
+        db_get cinder-common/database-type
+        if [ "$RET" = "sqlite3" ]
+        then
+            dbc_name="cinder.sqlite"
+            db_set cinder-common/db/dbname $dbc_name
+        fi
+
+        dbc_dbfile_owner="cinder:cinder"
+        dbc_go cinder-common $@
+
+        if [ "$dbc_install" = "true" ]
+        then
+
+            case "$dbc_dbtype" in
+                mysql)
+                    [ -n "$dbc_dbport" ] && dbport=:$dbc_dbport
+                    SQL_CONNECTION="mysql://$dbc_dbuser:$dbc_dbpass@${dbc_dbserver:-localhost}$dbport/$dbc_dbname"
+                    ;;
+                pgsql)
+                    [ -n "$dbc_dbport" ] && dbport=:$dbc_dbport
+                    SQL_CONNECTION="pgsql://$dbc_dbuser:$dbc_dbpass@${dbc_dbserver:-localhost}$dbport/$dbc_dbname"
+                    ;;
+                *)
+                    SQL_CONNECTION="sqlite:///$dbc_basepath/$dbc_dbname"
+                    ;;
+            esac
+
+            sed -e "s,^[- \t]*sql_connection=.\+,sql_connection=$SQL_CONNECTION," -i /etc/cinder/cinder.conf
+
+        fi
+    fi
+
     if ! grep -q sql_connection /etc/cinder/cinder.conf
     then
         su -s /bin/sh -c 'cinder-manage db sync' cinder
     fi
 
-    if [ -e /var/lib/cinder/cinder.sqlite ]; then
-        chown cinder:cinder /var/lib/cinder/cinder.sqlite
-        chown 0600 /var/lib/cinder/cinder.sqlite
-    fi
-
-    . /usr/share/debconf/confmodule
-
-    db_get nova-common/start_services
+    db_get cinder-common/start_services
     if [ " $RET" = "false" ]; then
-        sed -e "s,^NOVA_ENABLE=.\+,NOVA_ENABLE=false," -i /etc/default/nova
+        sed -e "s,^CINDER_ENABLE=.\+,CINDER_ENABLE=false," -i /etc/default/cinder
     fi
-
 fi
 
+chmod 0640 /etc/cinder/cinder.conf
+
 #DEBHELPER#
diff --git a/xenial/debian/cinder-common.postrm b/xenial/debian/cinder-common.postrm
new file mode 100644 (file)
index 0000000..aa0e336
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+set -e
+
+if [ -f /usr/share/debconf/confmodule ]; then
+    . /usr/share/debconf/confmodule
+fi
+
+db_get cinder-common/configure_db
+if [ "$RET" = "true" ]; then
+
+    if [ -f /usr/share/dbconfig-common/dpkg/postrm ]; then
+        . /usr/share/dbconfig-common/dpkg/postrm
+        dbc_go cinder-common $@
+    else
+        rm -f /etc/dbconfig-common/cinder-common.conf
+        if which ucf >/dev/null 2>&1; then
+            ucf --purge /etc/dbconfig-common/cinder-common.conf
+            ucfr --purge cinder-common /etc/dbconfig-common/cinder-common.conf
+        fi
+    fi
+fi
+
+if [ "$1" = "purge" ] ; then
+    rm -f /etc/cinder/cinder.conf
+    rm -f /etc/default/cinder-common
+fi
+
+#DEBHELPER#
diff --git a/xenial/debian/cinder-common.prerm b/xenial/debian/cinder-common.prerm
new file mode 100644 (file)
index 0000000..75b6ce1
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+set -e
+
+. /usr/share/debconf/confmodule
+
+db_get cinder-common/configure_db
+if [ "$RET" = "true" ]; then
+    . /usr/share/dbconfig-common/dpkg/prerm
+    dbc_go cinder-common $@
+fi
+
+#DEBHELPER#
diff --git a/xenial/debian/cinder-common.templates b/xenial/debian/cinder-common.templates
new file mode 100644 (file)
index 0000000..f1b7b4b
--- /dev/null
@@ -0,0 +1,25 @@
+Template: cinder-common/start_services
+Type: boolean
+Default: true
+_Description: Start cinder services at boot?
+ Please choose whether you want to start Cinder services when the
+ machine is booted up.
+
+Template: cinder-common/configure_db
+Type: boolean
+Default: false
+_Description: Set up a database for Cinder?
+ No database has been set up for Cinder to use. If you want
+ to set one up now, please make sure you have all needed
+ information:
+ .
+  * the host name of the database server (which must allow TCP
+    connections from this machine);
+  * a username and password to access the database;
+  * the type of database management software you want to use.
+ .
+ If you don't choose this option, no database will be set up and Cinder
+ will use regular SQLite support.
+ .
+ You can change this setting later on by running "dpkg-reconfigure
+ -plow cinder-common".
index 30bfd114bf7a1fee4dfd0e5cf820bfc7c225bbac..1072f3c3618d628c516bcad803f57add429dbcae 100644 (file)
@@ -1,14 +1,4 @@
 #!/bin/sh -e
 
-if [ "$1" = "configure" ]; then
-  # only migrate the database if configured to use a local sqlite db (default)
-  if grep -q 'sql_connection=sqlite' /etc/cinder/cinder.conf ; then
-    su -s /bin/sh -c 'cinder-manage db sync' cinder
-  fi
-  if [ -e /var/lib/cinder/cinder.sql ] ; then
-    chown cinder:cinder /var/lib/cinder/cinder.sqlite
-    chmod 0640 /var/lib/cinder/cinder.sqlite
-  fi
-fi
 
 #DEBHELPER#
index cf33b8841127db7f0129caf9395689fc64a1a3c7..ffc2442753096e6a1142735f6be1ad441d2d446e 100644 (file)
@@ -72,7 +72,7 @@ Description: Cinder python libraries
 
 Package: cinder-common
 Architecture: all
-Depends: python-cinder (= ${binary:Version}), ${python:Depends}, ${misc:Depends}, adduser
+Depends: python-cinder (= ${binary:Version}), ${python:Depends}, ${misc:Depends}, adduser, debconf, dbconfig-common
 Provides: ${python:Provides}
 Description: Cinder starage service - common files
  Cinder is a storage service for the Openstack project