From 3680c69edeaa33b5061d75c0006225a64c9cf3cb Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 10 Feb 2012 13:47:35 +0100 Subject: [PATCH] Add dbconfig support Signed-off-by: Julien Danjou --- control | 3 +- keystone.config | 13 ++++++++ keystone.install | 1 + keystone.postinst | 52 +++++++++++++++++++++++++++++--- keystone.postrm | 21 +++++++++++++ keystone.prerm | 9 ++++++ patches/fix-configuration-files.patch | 10 +++--- 7 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 keystone.config create mode 100644 keystone.postrm create mode 100644 keystone.prerm diff --git a/control b/control index 82d545e..73d41f8 100644 --- a/control +++ b/control @@ -69,7 +69,8 @@ Section: python Depends: ${python:Depends}, ${misc:Depends}, python-keystone (= ${source:Version}), adduser, - ssl-cert (>= 1.0.12) + ssl-cert (>= 1.0.12), + dbconfig-common Description: Proposed OpenStack identity service - Daemons Keystone is a proposed independent authentication service for OpenStack. . diff --git a/keystone.config b/keystone.config new file mode 100644 index 0000000..1373551 --- /dev/null +++ b/keystone.config @@ -0,0 +1,13 @@ +#!/bin/sh +set -e + +. /usr/share/debconf/confmodule + +if [ -f /usr/share/dbconfig-common/dpkg/config ] +then + dbc_dbtypes="sqlite3, mysql, pgsql" + dbc_authmethod_user="password" + dbc_basepath="/var/lib/keystone" + . /usr/share/dbconfig-common/dpkg/config + dbc_go keystone $@ +fi diff --git a/keystone.install b/keystone.install index f1478f4..6fe7833 100644 --- a/keystone.install +++ b/keystone.install @@ -1,2 +1,3 @@ usr/bin/* +etc/keystone.conf usr/share/keystone etc/* etc/keystone diff --git a/keystone.postinst b/keystone.postinst index 1efb3ba..ac7e723 100755 --- a/keystone.postinst +++ b/keystone.postinst @@ -4,6 +4,9 @@ set -e if [ "$1" = "configure" ] then + . /usr/share/debconf/confmodule + . /usr/share/dbconfig-common/dpkg/postinst + if ! getent passwd keystone > /dev/null 2>&1 then adduser --system --home /var/lib/keystone --no-create-home --shell /bin/false keystone @@ -15,13 +18,52 @@ then if dpkg --compare-versions "$2" lt "2012.1-0ubuntu1ppa"; then usermod -s "/bin/false" nova fi + + dbc_go keystone $@ + + case "$dbc_dbtype" in + sqlite3) + SQL_CONNECTION="sqlite:///$dbc_basepath/$dbc_dbname.db" + ;; + 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:////var/lib/keystone/keystone.db" + ;; + esac + + [ -z "$2" -o "$dbc_install" = "true" ] \ + && sed -e "s,_DBC_URL_,$SQL_CONNECTION," -i /etc/keystone/keystone.conf + + if [ "$dbc_install" = "true" ] + then + # On first install, create basics configuration and add roles + if [ -z "$2" ] + then + sed -e "s,_DBC_URL_,$SQL_CONNECTION," -i /etc/keystone/keystone.conf + + keystone-manage database sync + keystone-manage role add Admin + keystone-manage role add Member + keystone-manage role add KeystoneAdmin + keystone-manage role add KeystoneServiceAdmin + keystone-manage role add sysadmin + keystone-manage role add netadmin + fi + + if [ "$dbc_upgrade" = "true" ] + then + su -s /bin/sh -c 'exec keystone-manage db sync' keystone + fi + fi chown keystone:keystone -R /var/lib/keystone/ /var/log/keystone/ /etc/keystone/ chmod 0700 /var/lib/keystone/ /var/log/keystone/ /etc/keystone/ - - if ! grep -q sql_connection /etc/keystone/keysone.conf - then - su -s /bin/sh -c 'exec keysone-manage db sync' keystone - fi fi #DEBHELPER# diff --git a/keystone.postrm b/keystone.postrm new file mode 100644 index 0000000..f0d7143 --- /dev/null +++ b/keystone.postrm @@ -0,0 +1,21 @@ +#!/bin/sh + +set -e + +if [ -f /usr/share/debconf/confmodule ] +then + . /usr/share/debconf/confmodule +fi + +if [ -f /usr/share/dbconfig-common/dpkg/postrm ] +then + . /usr/share/dbconfig-common/dpkg/postrm + dbc_go keystone $@ +fi + +case "$1" in + purge) + rm -rf /var/log/keystone +esac + +#DEBHELPER# diff --git a/keystone.prerm b/keystone.prerm new file mode 100644 index 0000000..82e1e06 --- /dev/null +++ b/keystone.prerm @@ -0,0 +1,9 @@ +#!/bin/sh + +set -e + +. /usr/share/debconf/confmodule +. /usr/share/dbconfig-common/dpkg/prerm +dbc_go keystone $@ + +#DEBHELPER# \ No newline at end of file diff --git a/patches/fix-configuration-files.patch b/patches/fix-configuration-files.patch index 5f81384..d575af8 100644 --- a/patches/fix-configuration-files.patch +++ b/patches/fix-configuration-files.patch @@ -1,13 +1,13 @@ diff -Naurp keystone-2012.1.orig/etc/keystone.conf keystone-2012.1/etc/keystone.conf --- keystone-2012.1.orig/etc/keystone.conf 2012-02-01 13:50:31.000000000 -0500 +++ keystone-2012.1/etc/keystone.conf 2012-02-01 14:13:13.319159008 -0500 -@@ -13,7 +13,7 @@ default_store = sqlite +@@ -13,4 +13,4 @@ default_store = sqlite # Log to this file. Make sure you do not set the same log # file for both the API and registry servers! log_file = keystone.log -log_dir = . +log_dir = /var/log/keystone - + # Dictionary Maps every service to a header.Missing services would get header # X_(SERVICE_NAME) Key => Service Name, Value => Header Name @@ -80,7 +80,7 @@ global_service_id = @@ -15,7 +15,7 @@ diff -Naurp keystone-2012.1.orig/etc/keystone.conf keystone-2012.1/etc/keystone. # server. Any valid SQLAlchemy connection string is fine. # See: http://bit.ly/ideIpI -sql_connection = sqlite:///keystone.db -+sql_connection = sqlite:///var/lib/keystone/keystone.db ++sql_connection = _DBC_URL_ backend_entities = ['UserRoleAssociation', 'Endpoints', 'Role', 'Tenant', 'User', 'Credentials', 'EndpointTemplates', 'Token', 'Service'] @@ -36,7 +36,7 @@ diff -Naurp keystone-2012.1.orig/etc/memcache.conf keystone-2012.1/etc/memcache. [keystone.backends.sqlalchemy] -sql_connection = sqlite:///keystone.memcache.db -+sql_connection = sqlite:////var/lib/keystone/keystone.memcache.db ++sql_connection = _DBC_URL_ sql_idle_timeout = 30 backend_entities = ['Endpoints', 'Credentials', 'EndpointTemplates', 'Tenant', 'User', 'UserRoleAssociation', 'Role', 'Service'] @@ -57,7 +57,7 @@ diff -Naurp keystone-2012.1.orig/etc/ssl.conf keystone-2012.1/etc/ssl.conf [keystone.backends.sqlalchemy] -sql_connection = sqlite:///keystone.db -+sql_connection = sqlite:////var/lib/keystone/keystone.db ++sql_connection = _DBC_URL_ sql_idle_timeout = 30 backend_entities = ['Endpoints', 'Credentials', 'EndpointTemplates', 'Tenant', 'User', 'UserRoleAssociation', 'Role', 'Token', 'Service'] -- 1.7.9