From 32de2902b48d8ed005262eb28e8158a1c592db11 Mon Sep 17 00:00:00 2001 From: Mehdi Abaakouk Date: Sun, 16 Sep 2012 10:30:59 +0200 Subject: [PATCH] Add dbconfig-common support Rewritten-From: a92453e9e1544e0562cf2cd9486b954a34170b23 --- xenial/debian/cinder-common.config | 37 ++++++++++---- xenial/debian/cinder-common.postinst | 67 ++++++++++++++++++++----- xenial/debian/cinder-common.postrm | 29 +++++++++++ xenial/debian/cinder-common.prerm | 13 +++++ xenial/debian/cinder-common.templates | 25 +++++++++ xenial/debian/cinder-scheduler.postinst | 10 ---- xenial/debian/control | 2 +- 7 files changed, 148 insertions(+), 35 deletions(-) create mode 100644 xenial/debian/cinder-common.postrm create mode 100644 xenial/debian/cinder-common.prerm create mode 100644 xenial/debian/cinder-common.templates diff --git a/xenial/debian/cinder-common.config b/xenial/debian/cinder-common.config index a7c600744..bb9156d2d 100644 --- a/xenial/debian/cinder-common.config +++ b/xenial/debian/cinder-common.config @@ -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 diff --git a/xenial/debian/cinder-common.postinst b/xenial/debian/cinder-common.postinst index 2ac7870de..b14acec5c 100644 --- a/xenial/debian/cinder-common.postinst +++ b/xenial/debian/cinder-common.postinst @@ -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 index 000000000..aa0e336eb --- /dev/null +++ b/xenial/debian/cinder-common.postrm @@ -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 index 000000000..75b6ce159 --- /dev/null +++ b/xenial/debian/cinder-common.prerm @@ -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 index 000000000..f1b7b4baa --- /dev/null +++ b/xenial/debian/cinder-common.templates @@ -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". diff --git a/xenial/debian/cinder-scheduler.postinst b/xenial/debian/cinder-scheduler.postinst index 30bfd114b..1072f3c36 100644 --- a/xenial/debian/cinder-scheduler.postinst +++ b/xenial/debian/cinder-scheduler.postinst @@ -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# diff --git a/xenial/debian/control b/xenial/debian/control index cf33b8841..ffc244275 100644 --- a/xenial/debian/control +++ b/xenial/debian/control @@ -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 -- 2.45.2