Moved all debconf and config to glance-common instead of spreading it around.

This commit is contained in:
Thomas Goirand 2012-10-11 07:03:46 +00:00
parent ce9f9e9810
commit ba377c8069
19 changed files with 183 additions and 295 deletions

View File

@ -1,5 +0,0 @@
/var/lib/glance/image-cache
/var/lib/glance/image-cache/incomplete
/var/lib/glance/image-cache/invalid
/var/lib/glance/image-cache/queue
/var/lib/glance/images

View File

@ -1,6 +1,3 @@
etc/glance-cache.conf etc/glance
etc/glance-scrubber.conf etc/glance
etc/policy.json etc/glance
usr/bin/glance-api
usr/bin/glance-cache-cleaner
usr/bin/glance-cache-manage

View File

@ -1,16 +0,0 @@
#!/bin/sh
set -e
if [ "$1" = "configure" ] ; then
# Create user and group for glance
if ! getent group glance > /dev/null 2>&1 ; then
addgroup --quiet --system glance >/dev/null
fi
if ! getent passwd glance > /dev/null 2>&1 ; then
adduser --quiet --system --home /var/lib/glance --ingroup glance --no-create-home --shell /bin/false glance
fi
chown glance:glance /var/lib/glance -R
fi
#DEBHELPER#

View File

@ -1,12 +0,0 @@
#!/bin/sh
set -e
if [ "${1}" = "purge" ] ; then
rm -f /etc/glance/glance-api.conf /etc/glance/glance-api.conf
[ -d /etc/glance ] && rmdir --ignore-fail-on-non-empty /etc/glance
fi
#DEBHELPER#
exit 0

View File

@ -1,13 +0,0 @@
#!/bin/sh
set -e
case $1 in
remove|purge)
if [ -x /etc/init.d/glance-api ]; then
invoke-rc.d glance-api stop || true
fi
;;
esac
#DEBHELPER#

View File

@ -6,6 +6,8 @@ set -e
API_CONF=/etc/glance/glance-api.conf
APIPASTE_CONF=/etc/glance/glance-api-paste.ini
GREG_CONF=/etc/glance/glance-registry.conf
if [ -r "${API_CONF}" ] ; then
FLAVOR=`grep -E '^[#\t ]*flavor[ \t]*=[\.]*' ${API_CONF} | cut -d"=" -f2 | awk '{print $1}'`
case "${FLAVOR}" in
@ -31,3 +33,68 @@ keystone*)
db_go || true
;;
esac
db_input high glance/configure_db || true
db_go
db_get glance/configure_db
if [ "$RET" = "true" ] && [ -f /usr/share/dbconfig-common/dpkg/config ] ; then
. /usr/share/dbconfig-common/dpkg/config
# Parse sql_connection from our config file if it's there.
if [ -r ${GREG_CONF} ] ; then
DB_CON_INFO=`grep -E "^([ \t])*sql_connection([ \t])*=([ \t])*" ${GREG_CONF} | awk '{print $3}'`
if [ -z "${DB_CON_INFO}" ] ; then
DB_CON_INFO="sqlite:///var/lib/glance/glance.sqlite"
fi
else
DB_CON_INFO="sqlite:///var/lib/glance/glance.sqlite"
fi
DB_TYPE=`echo ${DB_CON_INFO} | cut -d":" -f1`
if [ "${DB_TYPE}" != "sqlite" ] && [ "${DB_TYPE}" != "mysql" ] && [ "${DB_TYPE}" != "pgsql" ] ; then
DB_CON_INFO="sqlite:///var/lib/glance/glance.sqlite"
DB_TYPE="sqlite"
fi
if [ "${DB_TYPE}" = "sqlite" ] ; then
if [ "${DB_CON_INFO}" = "sqlite:///glance.db" ] ; then
DB_CON_INFO="sqlite:///var/lib/glance/glance.sqlite"
fi
DB_PATH=`echo "${DB_CON_INFO}" | awk '{print substr($0,11)}'`
if [ -z "${DB_PATH}" ] ; then
DB_PATH=/var/lib/glance/glance.sqlite
fi
dbc_basepath=`dirname "${DB_PATH}"`
dbc_dbname=`basename "${DB_PATH}"`
dbc_dbtypes="sqlite3, mysql, pgsql"
else
ADDR=`echo "${DB_CON_INFO}" | awk '{print substr($0,9)}'`
BEFORE_AT=`echo "${ADDR}" | cut -d"@" -f1`
AFTER_AT=`echo "${ADDR}" | cut -d"@" -f2`
USER=`echo "${BEFORE_AT}" | cut -d":" -f2`
USER=`echo "${USER}" | cut -d"/" -f3`
PASS=`echo "${BEFORE_AT}" | cut -d":" -f3`
SERVER_PORT=`echo "${AFTER_AT}" | cut -d"/" -f1`
DB_NAME=`echo "${AFTER_AT}" | cut -d"/" -f2`
SERVER=`echo "${SERVER_PORT}" | cut -d":" -f1`
if echo "${SERVER_PORT}" | grep -Eq ":" ; then
PORT=`echo "${SERVER_PORT}" | cut -d":" -f2`
else
PORT=""
fi
if [ -n "${USER}" ] && [ -n "${PASS}" ] && [ -n "${SERVER}" ] && [ -n "${DB_NAME}" ] ; then
dbc_dbuser=${USER}
dbc_dbpass=${PASS}
dbc_dbserver=${SERVER}
dbc_dbport=${PORT}
dbc_dbname=${DB_NAME}
fi
if [ "${DB_TYPE}" = "mysql" ] ; then
dbc_dbtypes="mysql, pgsql, sqlite3"
else
dbc_dbtypes="pgsql, mysql, sqlite3"
fi
db_authmethod_user="password"
fi
dbc_go glance $@
fi

View File

@ -1,4 +1,7 @@
/var/lib/glance/
/var/lib/glance/image-cache/
/var/lib/glance/image-cache/incomplete
/var/lib/glance/image-cache/invalid
/var/lib/glance/image-cache/queue
/var/lib/glance/images/
/var/log/glance/

View File

@ -1,4 +1,9 @@
etc/glance-registry.conf usr/share/glance-common
etc/glance-registry-paste.ini usr/share/glance-common
etc/glance-api.conf usr/share/glance-common
etc/glance-api-paste.ini usr/share/glance-common
etc/glance-cache.conf usr/share/glance-common
etc/glance-scrubber.conf usr/share/glance-common
etc/policy.json usr/share/glance-common
usr/bin/glance-control
usr/bin/glance-manage

View File

@ -2,6 +2,22 @@
set -e
# Param:
# $1 = name of config file
install_config_file (){
if [ ! -e ${ETC}/${1} ] ; then
install -D -m 660 -o glance -g glance /usr/share/glance-common/${1} ${ETC}/${1}
fi
}
# Param:
# $1 = variable name
# $2 = value to put in
# $3 = name of config file
customize_config_file (){
sed -i 's|^[#\t ]*'${1}'[ \t]*=.*|'${1}' = '${2}'|' ${3}
}
if [ "$1" = "configure" ] ; then
# Create user and group for glance
if ! getent group glance > /dev/null 2>&1 ; then
@ -14,17 +30,20 @@ if [ "$1" = "configure" ] ; then
# Make sure we have a /etc/glance folder with config files in it.
ETC=/etc/glance
API_CONF=${ETC}/glance-api.conf
APIPASTE_CONF=${ETC}/glance-api-paste.ini
GREG_CONF=${ETC}/glance-registry.conf
if [ ! -e ${ETC} ] ; then
install -d -m 0700 -o glance -g glance ${ETC}
fi
if [ ! -e ${API_CONF} ] ; then
install -D -m 660 -o glance -g glance /usr/share/glance-common/glance-api.conf ${API_CONF}
fi
if [ ! -e ${APIPASTE_CONF} ] ; then
install -D -m 660 -o glance -g glance /usr/share/glance-common/glance-api-paste.ini ${APIPASTE_CONF}
fi
install_config_file glance-api.conf
install_config_file glance-registry.conf
install_config_file glance-api-paste.ini
install_config_file glance-registry-paste.ini
install_config_file glance-cache.conf
install_config_file glance-scrubber.conf
install_config_file policy.json
# Customize glance-api.conf
. /usr/share/debconf/confmodule
@ -35,30 +54,64 @@ if [ "$1" = "configure" ] ; then
caching)
;;
keystone*)
set -i 's|^[#\t ]*flavor[ \t]*=.*|flavor = '$FLAVOR'|' ${API_CONF}
customize_config_file flavor ${FLAVOR} ${API_CONF}
customize_config_file flavor ${FLAVOR} ${GREG_CONF}
db_get glance/auth-host
AUTH_HOST=${RET}
sed -i 's|^[#\t ]*auth_host[ \t]*=.*|auth_host = '${AUTH_HOST}'|' ${API_CONF}
sed -i 's|^[#\t ]*auth_host[ \t]*=.*|auth_host = '${AUTH_HOST}'|' ${APIPASTE_CONF}
customize_config_file auth_host ${AUTH_HOST} ${API_CONF}
customize_config_file auth_host ${AUTH_HOST} ${GREG_CONF}
db_get glance/admin-tenant-name
TENANT_NAME=${RET}
sed -i 's|^[\t ]*admin_tenant_name[ \t]*=.*|admin_tenant_name = '${TENANT_NAME}'|' ${API_CONF}
sed -i 's|^[\t ]*admin_tenant_name[ \t]*=.*|admin_tenant_name = '${TENANT_NAME}'|' ${APIPASTE_CONF}
customize_config_file admin_tenant_name ${TENANT_NAME} ${API_CONF}
customize_config_file admin_tenant_name ${TENANT_NAME} ${GREG_CONF}
db_get glance/admin-user
ADMIN_USER=${RET}
sed -i 's|^[\t ]*admin_user[ \t]*=.*|admin_user = '${ADMIN_USER}'|' ${API_CONF}
sed -i 's|^[\t ]*admin_user[ \t]*=.*|admin_user = '${ADMIN_USER}'|' ${APIPASTE_CONF}
customize_config_file admin_user ${ADMIN_USER} ${API_CONF}
customize_config_file admin_user ${ADMIN_USER} ${GREG_CONF}
db_get glance/admin-password
ADMIN_PASS=${RET}
sed -i 's|^[\t ]*admin_password[ \t]*=.*|admin_password = '${ADMIN_PASS}'|' ${API_CONF}
sed -i 's|^[\t ]*admin_password[ \t]*=.*|admin_password = '${ADMIN_PASS}'|' ${APIPASTE_CONF}
customize_config_file admin_password ${ADMIN_PASS} ${API_CONF}
customize_config_file admin_password ${ADMIN_PASS} ${GREG_CONF}
;;
*)
customize_config_file flavor ${FLAVOR} ${API_CONF}
customize_config_file flavor ${FLAVOR} ${GREG_CONF}
;;
esac
db_get glance/configure_db
if [ "$RET" = "true" ] && [ -f /usr/share/dbconfig-common/dpkg/config ] ; then
. /usr/share/dbconfig-common/dpkg/config
db_get glance/database-type
if [ $RET = "sqlite3" ] ; then
dbc_name="glance.sqlite"
db_set glance/db/dbname $dbc_name
fi
dbc_dbfile_owner="glance:glance"
dbc_go glance $@
if [ "$dbc_install" = "true" ] ; then
case "$dbc_dbtype" in
mysql|pgsql)
[ -n "$dbc_dbport" ] && dbport=:$dbc_dbport
SQL_CONNECTION="$dbc_dbtype://$dbc_dbuser:$dbc_dbpass@${dbc_dbserver:-localhost}$dbport/$dbc_dbname"
;;
*)
SQL_CONNECTION="sqlite:///$dbc_basepath/$dbc_dbname"
;;
esac
customize_config_file sql_connection ${SQL_CONNECTION} ${API_CONF}
customize_config_file sql_connection ${SQL_CONNECTION} ${GREG_CONF}
if [ "$dbc_upgrade" = "true" ] ; then
su glance -c "glance-manage db_sync" || true
fi
fi
fi
chown -R glance:adm /var/log/glance/
chmod 0750 /var/log/glance/
chown glance:glance -R /var/lib/glance/ /etc/glance/

View File

@ -15,7 +15,9 @@ case $1 in
[ -e /var/lib/glance ] && rm -rf /var/lib/glance
[ -e /var/log/glance ] && rm -rf /var/log/glance
rm -f /etc/glance/glance-api-paste.ini
rm -f /etc/glance/glance-registry.conf /etc/glance/glance-registry-paste.ini /etc/glance/glance-api.conf /etc/glance/glance-api-paste.ini
rm -f /etc/glance/glance-cache.conf /etc/glance/glance-scrubber.conf /etc/glance/policy.json
[ -d /etc/glance ] && rmdir --ignore-fail-on-non-empty /etc/glance
;;
esac

13
debian/glance-common.prerm vendored Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
set -e
. /usr/share/debconf/confmodule
db_get glance/configure_db
if [ "$RET" = "true" ]; then
. /usr/share/dbconfig-common/dpkg/prerm
dbc_go glance $@
fi
#DEBHELPER#

View File

@ -22,18 +22,35 @@ Template: glance/auth-host
Type: string
Default: 127.0.0.1
_Description: Auth server hostname:
Please specify the hostname of your Glance authentication server. Typically
this is also the hostname or IP address of your OpenStack Identity Service
(Keystone).
Please specify the URL of your Glance authentication server. Typically
this is also the URL of your OpenStack Identity Service (Keystone).
Template: glance/admin-tenant-name
Type: string
_Description: Auth server admin tenant name:
_Description: Auth server tenant name:
Template: glance/admin-user
Type: string
_Description: Auth server admin username:
_Description: Auth server username:
Template: glance/admin-password
Type: password
_Description: Auth server admin password:
_Description: Auth server password:
Template: glance/configure_db
Type: boolean
Default: false
_Description: Set up a database for glance-registry?
No database has been set up for glance-registry to use. Before
continuing, you should make sure you have:
.
- the server host name (that server must allow TCP connections
from this machine);
- a username and password to access the database.
- A database type that you want to use.
.
If some of these requirements are missing, reject this option and
run with regular sqlite support.
.
You can change this setting later on by running 'dpkg-reconfigure
-plow glance-registry

View File

@ -1,71 +0,0 @@
#!/bin/sh
set -e
. /usr/share/debconf/confmodule
GREG_CONF=/etc/glance/glance-registry.conf
db_input low glance-registry/configure_db || true
db_go
db_get glance-registry/configure_db
if [ "$RET" = "true" ] && [ -f /usr/share/dbconfig-common/dpkg/config ] ; then
. /usr/share/dbconfig-common/dpkg/config
# Parse sql_connection from our config file if it's there.
if [ -r ${GREG_CONF} ] ; then
DB_CON_INFO=`grep -E "^([ \t])*sql_connection([ \t])*=([ \t])*" ${GREG_CONF} | awk '{print $3}'`
if [ -z "${DB_CON_INFO}" ] ; then
DB_CON_INFO="sqlite:///var/lib/glance/glance.sqlite"
fi
else
DB_CON_INFO="sqlite:///var/lib/glance/glance.sqlite"
fi
DB_TYPE=`echo ${DB_CON_INFO} | cut -d":" -f1`
if [ "${DB_TYPE}" != "sqlite" ] && [ "${DB_TYPE}" != "mysql" ] && [ "${DB_TYPE}" != "pgsql" ] ; then
DB_CON_INFO="sqlite:///var/lib/glance/glance.sqlite"
DB_TYPE="sqlite"
fi
if [ "${DB_TYPE}" = "sqlite" ] ; then
if [ "${DB_CON_INFO}" = "sqlite:///glance.db" ] ; then
DB_CON_INFO="sqlite:///var/lib/glance/glance.sqlite"
fi
DB_PATH=`echo "${DB_CON_INFO}" | awk '{print substr($0,11)}'`
if [ -z "${DB_PATH}" ] ; then
DB_PATH=/var/lib/glance/glance.sqlite
fi
dbc_basepath=`dirname "${DB_PATH}"`
dbc_dbname=`basename "${DB_PATH}"`
dbc_dbtypes="sqlite3, mysql, pgsql"
else
ADDR=`echo "${DB_CON_INFO}" | awk '{print substr($0,9)}'`
BEFORE_AT=`echo "${ADDR}" | cut -d"@" -f1`
AFTER_AT=`echo "${ADDR}" | cut -d"@" -f2`
USER=`echo "${BEFORE_AT}" | cut -d":" -f2`
USER=`echo "${USER}" | cut -d"/" -f3`
PASS=`echo "${BEFORE_AT}" | cut -d":" -f3`
SERVER_PORT=`echo "${AFTER_AT}" | cut -d"/" -f1`
DB_NAME=`echo "${AFTER_AT}" | cut -d"/" -f2`
SERVER=`echo "${SERVER_PORT}" | cut -d":" -f1`
if echo "${SERVER_PORT}" | grep -Eq ":" ; then
PORT=`echo "${SERVER_PORT}" | cut -d":" -f2`
else
PORT=""
fi
if [ -n "${USER}" ] && [ -n "${PASS}" ] && [ -n "${SERVER}" ] && [ -n "${DB_NAME}" ] ; then
dbc_dbuser=${USER}
dbc_dbpass=${PASS}
dbc_dbserver=${SERVER}
dbc_dbport=${PORT}
dbc_dbname=${DB_NAME}
fi
if [ "${DB_TYPE}" = "mysql" ] ; then
dbc_dbtypes="mysql, pgsql, sqlite3"
else
dbc_dbtypes="pgsql, mysql, sqlite3"
fi
db_authmethod_user="password"
fi
dbc_go glance-registry $@
fi

View File

@ -1,3 +1 @@
etc/glance-registry.conf usr/share/glance-registry
etc/glance-registry-paste.ini etc/glance
usr/bin/glance-registry

View File

@ -1,98 +0,0 @@
#!/bin/sh
set -e
if [ "$1" = "configure" ] ; then
. /usr/share/debconf/confmodule
. /usr/share/dbconfig-common/dpkg/postinst
# Make sure glance:glance user and group exist
if ! getent group glance > /dev/null 2>&1 ; then
addgroup --quiet --system glance >/dev/null
fi
if ! getent passwd glance > /dev/null 2>&1 ; then
adduser --quiet --system --home /var/lib/glance --ingroup glance --no-create-home --shell /bin/false glance
fi
# Make sure we have a /etc/glance/glance-registry-paste.ini config file
if [ ! -d /etc/glance ] ; then
mkdir -p /etc/glance
if [ -d /etc/glance ] ; then
chown glance:glance /etc/glance
fi
fi
GREG_CONF=/etc/glance/glance-registry.conf
if [ ! -e ${GREG_CONF} ] && [ -r /usr/share/glance-registry/glance-registry.conf ] ; then
install -D -m 660 -o glance -g glance /usr/share/glance-registry/glance-registry.conf ${GREG_CONF}
fi
db_get glance/paste-flavor || true
FLAVOR="$RET"
case $FLAVOR in
caching)
;;
keystone*)
sed -i 's|^[#\t ]*flavor[ \t]*=.*|flavor = '$FLAVOR'|' ${GREG_CONF}
db_get glance/auth-host
AUTH_HOST=${RET}
sed -i 's|^[#\t ]*auth_host[ \t]*=.*|auth_host = '${AUTH_HOST}'|' ${GREG_CONF}
db_get glance/admin-tenant-name
TENANT_NAME=${RET}
sed -i 's|^[\t ]*admin_tenant_name[ \t]*=.*|admin_tenant_name = '${TENANT_NAME}'|' ${GREG_CONF}
db_get glance/admin-user
ADMIN_USER=${RET}
sed -i 's|^[\t ]*admin_user[ \t]*=.*|admin_user = '${ADMIN_USER}'|' ${GREG_CONF}
db_get glance/admin-password
ADMIN_PASS=${RET}
sed -i 's|^[\t ]*admin_password[ \t]*=.*|admin_password = '${ADMIN_PASS}'|' ${GREG_CONF}
;;
*)
sed -i 's|^[#\t ]*flavor\[\t ]=.*|flavor = '${FLAVOR}'|' /etc/glance/glance-registry.conf
;;
esac
db_get glance-registry/configure_db
if [ "$RET" = "true" ]; then
db_get glance-registry/database-type
if [ $RET = "sqlite3" ] ; then
dbc_name="glance.sqlite"
db_set glance-registry/db/dbname $dbc_name
fi
dbc_dbfile_owner="glance:glance"
dbc_go glance-registry $@
if [ "$dbc_install" = "true" ] ; then
case "$dbc_dbtype" in
mysql|pgsql)
[ -n "$dbc_dbport" ] && dbport=:$dbc_dbport
SQL_CONNECTION="$dbc_dbtype://$dbc_dbuser:$dbc_dbpass@${dbc_dbserver:-localhost}$dbport/$dbc_dbname"
;;
*)
SQL_CONNECTION="sqlite:///$dbc_basepath/$dbc_dbname"
;;
esac
echo "Inserting ${SQL_CONNECTION} in /etc/glance/glance-registry.conf"
echo -n "Current value: "
grep sql_connection /etc/glance/glance-registry.conf
sed -e -i 's|^[\t ]*sql_connection[\t ]*=.*|sql_connection = '${SQL_CONNECTION}'|' /etc/glance/glance-registry.conf
echo -n "After insertion: "
grep sql_connection /etc/glance/glance-registry.conf
if [ "$dbc_upgrade" = "true" ] ; then
su glance -c "glance-manage db_sync" || true
fi
fi
fi
fi
#DEBHELPER#
exit 0

View File

@ -1,13 +0,0 @@
#!/bin/sh
set -e
if [ "${1}" = "purge" ] ; then
rm -f /etc/glance/glance-registry-paste.ini
rm -f /etc/glance/glance-registry.conf
[ -d /etc/glance ] && rmdir --ignore-fail-on-non-empty /etc/glance
fi
#DEBHELPER#
exit 0

View File

@ -1,21 +0,0 @@
#!/bin/sh
set -e
. /usr/share/debconf/confmodule
db_get glance-registry/configure_db
if [ "$RET" = "true" ]; then
. /usr/share/dbconfig-common/dpkg/prerm
dbc_go glance-registry $@
fi
case $1 in
remove|purge)
if [ -x /etc/init.d/glance-registry ]; then
invoke-rc.d glance-registry stop || true
fi
;;
esac
#DEBHELPER#

View File

@ -1,17 +0,0 @@
Template: glance-registry/configure_db
Type: boolean
Default: false
_Description: Set up a database for glance-registry?
No database has been set up for glance-registry to use. Before
continuing, you should make sure you have:
.
- the server host name (that server must allow TCP connections
from this machine);
- a username and password to access the database.
- A database type that you want to use.
.
If some of these requirements are missing, reject this option and
run with regular sqlite support.
.
You can change this setting later on by running 'dpkg-reconfigure
-plow glance-registry

View File

@ -1,2 +1 @@
[type: gettext/rfc822deb] glance-registry.templates
[type: gettext/rfc822deb] glance-common.templates