[Webapps-common-discuss] [commit] r75 - in trunk: . debian debian/po dpkg internal templates

Sean Finney seanius at costa.debian.org
Fri Apr 21 09:45:25 UTC 2006


Author: seanius
Date: 2006-04-21 09:45:24 +0000 (Fri, 21 Apr 2006)
New Revision: 75

Added:
   trunk/TODO
   trunk/templates/apache-virtualhost.conf
   trunk/templates/apache2-wc-master.conf
Modified:
   trunk/debian/changelog
   trunk/debian/po/templates.pot
   trunk/debian/webapps-common.dirs
   trunk/debian/webapps-common.postinst
   trunk/debian/webapps-common.postrm
   trunk/debian/webapps-common.templates
   trunk/dpkg/common
   trunk/dpkg/config
   trunk/dpkg/postinst
   trunk/dpkg/postrm
   trunk/dpkg/prerm
   trunk/internal/common
   trunk/internal/httpd
Log:
here comes a big chunk of work i did on the latest roadtrip.

see TODO for what i'm currently working on fixing up.  not quite
presentable yet, but close....


Added: trunk/TODO
===================================================================
--- trunk/TODO	2006-04-21 08:57:40 UTC (rev 74)
+++ trunk/TODO	2006-04-21 09:45:24 UTC (rev 75)
@@ -0,0 +1,22 @@
+- i'm in the middle of redoing configuration layout in /etc/webapps-common
+  to something that actually makes sense
+
+- have an available/enabled directory for the generated httpd files.
+  - almost there... but layout enabled/disabled isn't quite consistant
+    across all the code.  in some places it's 
+
+    /e/w/apps-enabled/$httpd/$pkg_$vhost_$dir.conf
+
+    and others it's
+
+    /e/w/apps-enabled/$httpd/$vhost/$pkg_$dir.conf
+
+    i think the latter is the way to go, as it is easier to include
+    from virtual-host configurations.
+
+- "default" isn't really the right name for the default virtual host
+  choice.  maybe "global" would be better because it's not the "default
+  host", but "all hosts" (those that include conf.d?).
+
+- using [new vhost] and [default] is a PITA for special case checks in
+  anything that uses grep.  maybe {new vhost} etc would be better...

Modified: trunk/debian/changelog
===================================================================
--- trunk/debian/changelog	2006-04-21 08:57:40 UTC (rev 74)
+++ trunk/debian/changelog	2006-04-21 09:45:24 UTC (rev 75)
@@ -2,8 +2,15 @@
 
   [sean finney]
   * webapps-common has migrated to svn.
+  * even more work on the debconf<->config interaction.  at this point,
+    pretty much all debconf information is purged at the end of the
+    postinst script, and preseeded from config files when the config
+    script is run.
+  * retooling the postrm remove/purge code.
+  * initial version of apps-enabled/apps-available
+  * lots of other work+fixes.
 
- -- sean finney <seanius at debian.org>  Fri, 21 Apr 2006 10:57:03 +0200
+ -- sean finney <seanius at debian.org>  Fri, 21 Apr 2006 11:37:41 +0200
 
 webapps-common (0.4) UNRELEASED; urgency=low
 

Modified: trunk/debian/po/templates.pot
===================================================================
--- trunk/debian/po/templates.pot	2006-04-21 08:57:40 UTC (rev 74)
+++ trunk/debian/po/templates.pot	2006-04-21 09:45:24 UTC (rev 75)
@@ -16,7 +16,7 @@
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2005-08-17 18:15+0200\n"
+"POT-Creation-Date: 2006-04-10 17:42+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL at ADDRESS>\n"
 "Language-Team: LANGUAGE <LL at li.org>\n"
@@ -174,58 +174,83 @@
 #. Type: select
 #. Choices
 #: ../webapps-common.templates:79
-msgid "single, virtualhost"
+msgid "directory, virtualhost + directory, multiple instances"
 msgstr ""
 
 #. Type: select
 #. Description
 #: ../webapps-common.templates:80
-msgid "Select how ${pkg} should be installed for ${httpd}."
+msgid "How should ${pkg} be configured for web access?"
 msgstr ""
 
 #. Type: select
 #. Description
 #: ../webapps-common.templates:80
 msgid ""
-"Web server package configuration can be done as either 'single' installation "
-"or a 'virtualhost' configuration."
+"If you select \"directory\", then you will be simply prompted for the name "
+"of the directory on your web server from which you would like your "
+"application to be available."
 msgstr ""
 
 #. Type: select
 #. Description
 #: ../webapps-common.templates:80
 msgid ""
-"The former will enable the package for a standard web server installation. "
-"The latter will give you the ability to install multiple instances of of "
-"this package."
+"If you select \"virtualhost + directory\", you will also be given the choice "
+"of running your application under a new or pre-existing virtualhost."
 msgstr ""
 
+#. Type: select
+#. Description
+#: ../webapps-common.templates:80
+msgid ""
+"If you select \"multiple instances\", then you will be provided with the "
+"ability to configure multiple virtualhost + directory configurations. For "
+"some applications this may allow a single package to host many independant "
+"instances of itself, which is ideal for situations where you may wish to "
+"provide the same service to multiple groups of users."
+msgstr ""
+
 #. Type: string
 #. Description
-#: ../webapps-common.templates:90
+#: ../webapps-common.templates:97
 msgid "Please enter the name of a new virtualhost."
 msgstr ""
 
+#. Type: string
+#. Description
+#: ../webapps-common.templates:97
+msgid ""
+"Alternatively, for a global instance available over all virtual hosts, enter "
+"the name [default] (including the square brackets)."
+msgstr ""
+
+#. Type: select
+#. Description
+#: ../webapps-common.templates:104
+msgid "Please select the virtualhost with which to configure ${pkg}"
+msgstr ""
+
 #. Type: multiselect
 #. Choices
-#: ../webapps-common.templates:94
+#: ../webapps-common.templates:108
 msgid "${vhosts}"
 msgstr ""
 
 #. Type: multiselect
 #. Description
-#: ../webapps-common.templates:95
+#: ../webapps-common.templates:109
 msgid "Please select the virtualhosts with which to configure ${pkg}"
 msgstr ""
 
 #. Type: string
 #. Default
-#: ../webapps-common.templates:99
+#: ../webapps-common.templates:113
 msgid "${pkg}"
 msgstr ""
 
 #. Type: string
 #. Description
-#: ../webapps-common.templates:100
+#: ../webapps-common.templates:114
 msgid "Please provide the subdirectory for ${pkg} on \"${vhost}\""
 msgstr ""

Modified: trunk/debian/webapps-common.dirs
===================================================================
--- trunk/debian/webapps-common.dirs	2006-04-21 08:57:40 UTC (rev 74)
+++ trunk/debian/webapps-common.dirs	2006-04-21 09:45:24 UTC (rev 75)
@@ -1,4 +1,11 @@
 usr/share/webapps-common/internal
 usr/share/webapps-common/install
-etc/webapps-common/siteids.d
-etc/webapps-common/httpd.d
+etc/webapps-common/apps-available/apache
+etc/webapps-common/apps-available/apache2
+etc/webapps-common/apps-available/apache-ssl
+etc/webapps-common/apps-available/apache-perl
+etc/webapps-common/apps-enabled/apache
+etc/webapps-common/apps-enabled/apache2
+etc/webapps-common/apps-enabled/apache-ssl
+etc/webapps-common/apps-enabled/apache-perl
+etc/apache2/conf.d

Modified: trunk/debian/webapps-common.postinst
===================================================================
--- trunk/debian/webapps-common.postinst	2006-04-21 08:57:40 UTC (rev 74)
+++ trunk/debian/webapps-common.postinst	2006-04-21 09:45:24 UTC (rev 75)
@@ -3,10 +3,14 @@
 set -e
 . /usr/share/debconf/confmodule
 
+template_dir="/usr/share/webapps-common/templates"
+
 if [ "$1" = "configure" ] || [ "$1" = "reconfigure" ]; then
 	if [ ! -f /etc/webapps-common/virtualhosts.conf ]; then
-		ucf /usr/share/webapps-common/templates/virtualhosts.conf /etc/webapps-common/virtualhosts.conf
+		ucf ${template_dir}/virtualhosts.conf /etc/webapps-common/virtualhosts.conf
 	fi
+
+	ucf ${template_dir}/apache2-wc-master.conf /etc/apache2/conf.d/webapps-common.conf
 fi
 
 #DEBHELPER#

Modified: trunk/debian/webapps-common.postrm
===================================================================
--- trunk/debian/webapps-common.postrm	2006-04-21 08:57:40 UTC (rev 74)
+++ trunk/debian/webapps-common.postrm	2006-04-21 09:45:24 UTC (rev 75)
@@ -3,6 +3,8 @@
 if [ "$1" = "purge" ]; then
 	rm -f /etc/webapps-common/virtualhosts.conf
 	ucf --purge /etc/webapps-common/virtualhosts.conf
+	rm -f /etc/apache2/conf.d/webapps-common.conf
+	ucf --purge /etc/apache2/conf.d/webapps-common.conf
 fi
 
 #DEBHELPER#

Modified: trunk/debian/webapps-common.templates
===================================================================
--- trunk/debian/webapps-common.templates	2006-04-21 08:57:40 UTC (rev 74)
+++ trunk/debian/webapps-common.templates	2006-04-21 09:45:24 UTC (rev 75)
@@ -95,6 +95,8 @@
 Template: webapps-common/httpd/virtualhost_new
 Type: string
 _Description: Please enter the name of a new virtualhost.
+ Alternatively, for a global instance available over all virtual hosts,
+ enter the name [default] (including the square brackets).
 
 Template: webapps-common/httpd/virtualhost_single
 Type: select

Modified: trunk/dpkg/common
===================================================================
--- trunk/dpkg/common	2006-04-21 08:57:40 UTC (rev 74)
+++ trunk/dpkg/common	2006-04-21 09:45:24 UTC (rev 75)
@@ -10,6 +10,8 @@
 
 # get some internal helper functions, like _dbc_sanity_check
 . /usr/share/webapps-common/internal/common
+# and some httpd helper functions
+. /usr/share/webapps-common/internal/httpd
 
 # set various global variables used by the rest of webapps-common
 # (this is typically called by wc_go)
@@ -23,7 +25,7 @@
 	wc_confdir="/etc/webapps-common"
 	wc_globalconfig="$wc_confdir/config"
 	wc_vhostconfig="$wc_confdir/virtualhosts.conf"
-	wc_siteconf="$wc_confdir/siteids.d/${wc_package}.conf"
+	wc_pkgconfig="$wc_confdir/${wc_package}.conf"
 
 	# set a default directory for apache config files if not specified
 	if [ ! "$wc_package_confdir" ]; then
@@ -102,11 +104,12 @@
 ###
 ### dump package configuration to a config file
 ###
-wc_write_package_config(){
-	local tmpconf tmpconf2 output vhost dir httpds h clink do_conf reload_list
+wc_write_package_httpd_configs(){
+	local tmpconf tmpconf2 output vhost dir httpds h clink do_conf reload_file reload_list
 	_wc_debug "wc_write_package_config() $@"
 
 	tmpconf=`_wc_mktmp`
+	reload_file=`_wc_mktmp`
 
 	# detect what kind of install this is and copy/merge the correct file
 	case $wc_apache_conf_style in 
@@ -126,33 +129,43 @@
 	esac
 
 	# now perform some substitutions on the file into the output files
-	grep -vE '^[[:space:]]*(#|$)' "$wc_siteconf" | while read vhost dir httpds; do
+	grep -vE '^[[:space:]]*(#|$)' "$wc_pkgconfig" | while read vhost dir httpds; do
 		for h in `_wc_list_explode "$httpds"`; do
 			do_conf="yes"
 			tmpconf2=`_wc_mktmp`
 			sed -e "s,_WC_WEBSITE_SUBDIRECTORY_,$dir,g" -e "s,_WC_WEBSITE_DOCUMENTROOT_,$wc_website_documentroot,g" -e "s,_WC_WEBSITE_HOSTNAME_,$vhost,g" < "$tmpconf" > "$tmpconf2"
-			output="$wc_confdir/httpd.d/${wc_package}_${h}_${vhost}_${dir}.conf"
-
-			# check to see if the file exists but the symlink was removed
-			clink="/etc/$h/conf.d/${wc_package}_${h}_${vhost}_${dir}.conf"
-			if [ -f "$output" -a ! -h "$clink" ]; then
-				do_conf="no"
-			fi
+			output=`_wc_instance_cfg_file $vhost $dir $h`
 				
 			# and register it via ucf
 			ucf "$tmpconf2" "$output"
 
-			# if they've manually removed the symlink, keep it that way
-			if [ -f "$output" -a ! -e "$clink" -a "$do_conf" != "no" ]; then
-				ln -s "$output" "$clink"
-				reload_list=`_wc_list_add "$reload_list" "$h"`
+			# check to see if the file exists but the symlink was removed
+			clink=`_wc_instance_cfg_link $vhost $dir $h`
+			if [ -f "$output" -a ! -h "$clink" ]; then
+				# also make sure that there's nothing else where the
+				# symlink ought to be
+				if [ ! -e "$clink" ]; then
+					# create the link, note that the server needs to
+					# be reloaded.
+					ln -s "$output" "$clink"
+					reload_list=`_wc_list_add "$reload_list" "$h"`
+				fi
+				wc_httpd_create_vhost $vhost $h
 			fi
 
 			rm -f "$tmpconf2"
 		done
+		echo $reload_list > "$reload_file"
 	done
 	rm -f "$tmpconf"
-	echo need to reload "$reload_list"
+
+	# finally, detect the list of servers which need to be reloaded.
+	# we need to use a tmpfile because the value of reload_list from
+	# the above while loop is not preserved when the while loop exists.
+	reload_list=`cat $reload_file`
+	rm -f "$reload_file"
+	_wc_debug "the following servers need to be reloaded: ${reload_list}."
+    wc_httpd_invoke reload `wc_httpd_running $reload_list` || true
 }
 
 ###
@@ -162,51 +175,18 @@
 wc_purge_httpd_conf(){
 	local vhost dir httpds h cfile
 	_wc_debug "wc_purge_httpd_conf() $@"
-	grep -vE '^[[:space:]]*(#|$)' "$wc_siteconf" | while read vhost dir httpds; do
+	grep -vE '^[[:space:]]*(#|$)' "$wc_pkgconfig" | while read vhost dir httpds; do
 		for h in `_wc_list_explode "$httpds"`; do
 			cfile="/etc/webapps-common/httpd.d/${wc_package}_${h}_${vhost}_${dir}.conf"
 			rm -f "$cfile"
 			ucf --purge "$cfile"
 		done
 	done
-	ucf --purge "$wc_siteconf"
-	rm -f "$wc_siteconf"
+	ucf --purge "$wc_pkgconfig"
+	rm -f "$wc_pkgconfig"
 }
 
 ###
-### wc_unconfigure_httpds
-###	remove package configuration from all httpds
-###
-wc_unconfigure_httpds(){
-	local vhost dir httpds h cfile clink
-	_wc_debug "wc_unconfigure_httpds() $@"
-	grep -vE '^[[:space:]]*(#|$)' "$wc_siteconf" | while read vhost dir httpds; do
-		for h in `_wc_list_explode "$httpds"`; do
-			clink="/etc/$h/conf.d/${wc_package}_${h}_${vhost}_${dir}.conf"
-			if [ -L "$clink" ]; then
-				rm -f "$clink"
-			fi
-		done
-	done
-}
-
-###
-### wc_configure_httpds
-###	apply configurations to the selected webservers
-###
-#wc_configure_httpds(){
-#	local vhost dir httpds h cfile
-#	grep -vE '^[[:space:]]*(#|$)' "$wc_siteconf" | while read vhost dir httpds; do
-#		for h in `_wc_list_explode "$httpds"`; do
-#			cfile="$wc_confdir/httpd.d/${wc_package}_${h}_${vhost}_${dir}.conf"
-#			if [ -f "$cfile" ]; then
-#				ln -s "$cfile" "/etc/$h/conf.d/" || true
-#			fi
-#		done
-#	done
-#}
-
-###
 ### this function is responsible for reading in everything 
 ### with respect to the package's configuration and webapps-common.  
 ###
@@ -214,6 +194,7 @@
 	_wc_debug "wc_read_package_debconf() $@"
 	_wc_sanity_check package || wc_install_error
 	db_get $wc_package/httpd/website_subdirectory && wc_website_subdirectory="$RET"
+	db_get $wc_package/webapps_install && wc_install="$RET"
 }
 
 ##
@@ -315,18 +296,23 @@
 		debconf_dest="$wc_package/vhosts/$vhost_id"
 	fi
 
-	if ! db_get "$debconf_dest/$f/httpd/website_subdirectory"; then
+	if ! db_get "$debconf_dest/httpd/website_subdirectory"; then
 		for f in $wc_register_templates; do
 			db_register "webapps-common/$f" "$debconf_dest/$f"
 		done
-		# perform some basic customizing substitutions
+	fi
+
+	# perform some basic customizing substitutions
+	for f in $wc_register_templates; do
 		db_subst "$debconf_dest/$f" pkg "$wc_package"
 		if [ "$vhost_id" ]; then
 			db_subst "$debconf_dest/$f" vhost "$vhost_id"
 		fi
-	fi
+	done
 
 	# set some default values if this is a first-time installation
+	# for all other installations, we rely on the config -> debconf
+	# preseeding to load in the correct values.
 	if [ ! "$wc_oldversion" ]; then
 		db_set "$debconf_dest/httpd/website_subdirectory" "$wc_package"
 		db_set "$debconf_dest/httpd/select_httpd" "`wc_httpd_installed`"
@@ -345,22 +331,41 @@
 }
 
 ###
+### unregister all the registered debconf templates
+###
+wc_forget_debconf(){
+	local f v vhosts
+	_wc_debug "wc_forget_debconf() $@"
+	
+	db_get $wc_package/httpd/virtualhost && vhosts="$RET"
+	for f in $wc_register_templates; do
+		db_unregister $wc_package/$f
+		for v in `_wc_list_explode "$vhosts"`; do
+			db_unregister "$wc_package/vhosts/$v/$f"
+		done
+	done
+}
+
+###
 ### dump the vhost/dir combinations for a package to the config file
-###	this should only be called in the preinst i guess
+###	this should only be called in the postinst i guess
 ###
-wc_dump_debconf_siteids(){
+wc_dump_debconf_pkgconfig(){
 	local tmpconf vhosts v d httpds debconf_src
-	_wc_debug "wc_dump_debconf_siteids() $@"
+	_wc_debug "wc_dump_debconf_pkgconfig() $@"
 	tmpconf=`_wc_mktmp`
+
 	# get the list of selected virtualhosts
 	db_get $wc_package/httpd/virtualhost && vhosts="$RET"
+	# and for each one, dump their config
 	for v in `_wc_list_explode "$vhosts"`; do
 		debconf_src="$wc_package/vhosts/$v"
 		db_get $debconf_src/httpd/website_subdirectory && d="$RET"
 		db_get $debconf_src/httpd/select_httpd && httpds="$RET"
 		echo "$v	$d	$httpds" >> "$tmpconf"
 	done
-	ucf "$tmpconf" "$wc_siteconf"
+
+	ucf "$tmpconf" "$wc_pkgconfig"
 }
 
 ###
@@ -368,7 +373,7 @@
 ###	this should only be called in the config script, i guess
 ###
 wc_preseed_debconf(){
-	local v old_vhosts vhosts
+	local v old_vhosts vhosts vhost_count
 	_wc_debug "wc_preseed_debconf() $@"
 
 	# set the master control flag
@@ -377,26 +382,39 @@
 	fi
 
 	# get the list of virtualhosts for which this app is configured
-	if [ -f "$wc_siteconf" ]; then
-		vhosts=`grep -vE '^[[:space:]]*#' "$wc_siteconf" | cut -f1`
+	if [ -f "$wc_pkgconfig" ]; then
+		vhosts=`grep -vE '^[[:space:]]*#' "$wc_pkgconfig" | cut -f1`
 		vhosts=`_wc_list_create $vhosts`
+set -x
+		vhost_count=`grep -vcE '^[[:space:]]*#' "$wc_pkgconfig"` || true
+		# automatically fill in the right default choice for this question
+		if [ $vhost_count -eq 0 ]; then
+			db_set $wc_package/httpd/install_type "directory"
+		elif [ $vhost_count -eq 1 ]; then
+			db_set $wc_package/httpd/install_type "virtualhost + directory"
+		else
+			db_set $wc_package/httpd/install_type "multiple instances"
+		fi
+set +x
 	fi
 
-	# get any pre-existing vhosts from global configuration
+	# preseed each vhost debconf structure for this package.
+	for v in `_wc_list_explode "$vhosts"`; do
+		wc_register_debconf "$v"
+		wc_preseed_debconf_vhost "$v"
+	done
+
+	# now, get any pre-existing vhosts from global configuration
 	if [ -f "$wc_vhostconfig" ]; then
 		old_vhosts=`grep -vE '^[[:space:]]*#' "$wc_vhostconfig"` || true
 		old_vhosts=`_wc_list_create $old_vhosts`
 	fi
 	vhosts=`_wc_list_join "$old_vhosts" "$vhosts"`
 
-	# preseed each vhost debconf structure for this package.
-	for v in `_wc_list_explode "$vhosts"`; do
-		wc_register_debconf "$v"
-		wc_preseed_debconf_vhost "$v"
-	done
+	# and append the '[new vhost]' option
+	vhosts=`_wc_list_add "[new vhost]" "$vhosts"`
 
-	# and of course add the new vhost option
-	vhosts=`_wc_list_add "[new vhost]" "$vhosts"`
+	# finally, put the big list into the vhost options.
 	db_subst $wc_package/httpd/virtualhost vhosts "$vhosts"
 	db_subst $wc_package/httpd/virtualhost_single vhosts "$vhosts"
 }
@@ -410,56 +428,60 @@
 	local vhost vhost_grep vdir httpds debconf_dest
 	_wc_debug "wc_preseed_debconf_vhost() $@"
 
-	if [ ! -f "$wc_siteconf" ]; then return 0; fi
+	if [ ! -f "$wc_pkgconfig" ]; then return 0; fi
 
 	vhost="$1"
+	debconf_dest="$wc_package/vhosts/$vhost"
 
-	vhost_grep="grep -E ^$vhost[[:space:]] $wc_siteconf"
-	vdir=`$vhost_grep | cut -f2`
-	httpds=`$vhost_grep | cut -f3-`
+	# a quick bozo fix to prevent '[default]' from being interpreted
+	# as a regexp.
+	if [ "$vhost" = "[default]" ]; then 
+		vhost_expr="\\[default\\]"
+	else
+		vhost_expr="$vhost"
+	fi
+	vhost_expr="^$vhost_expr[[:space:]]"
 
-	debconf_dest="$wc_package/vhosts/$vhost"
+	# first, for new installs there will be nothing to preseed, but
+	# there are cases where we may wish to preseed something even
+	# though it doesn't exist.  so, if they're not in the config,
+	# set some default values
+	if ! grep -qE $vhost_expr $wc_pkgconfig; then
+		db_set $debconf_dest/httpd/website_subdirectory "$wc_package"
+		db_set $debconf_dest/httpd/select_httpd "`wc_httpd_installed`"
+		return 0
+	fi
+
+	vdir=`grep -E $vhost_expr $wc_pkgconfig | cut -f2`
+	httpds=`grep -E $vhost_expr $wc_pkgconfig | cut -f3-`
+
+	# and some sanity checking:
+	if [ ! "$vdir" ]; then
+		_wc_log "warning: instance '$vhost' missing directory name"
+	fi
+
 	db_set $debconf_dest/httpd/website_subdirectory "$vdir"
 	db_set $debconf_dest/httpd/select_httpd "$httpds"
-
-# XXX
-#	db_metaget $wc_package/httpd/virtualhost choices && choices="$RET"
-#	db_metaget webapps-common/httpd/virtualhost g_choices && g_choices="$RET"
-#	choices=`_wc_list_join "$g_choices" "$choices"`
-#	db_subst $wc_package/httpd/virtualhost vhosts `_wc_list_add "$choices" "$vhost"`
-#	db_subst webapps-common/httpd/virtualhost vhosts `_wc_list_add "$choices" "$vhost"`
-#	db_get $wc_package/httpd/virtualhost && vhost_list_d="$RET"
-#	vhost_list=`_wc_list_join "$vhost_list" "$vhost_list_d"`
-#	db_set $wc_package/httpd/virtualhost `_wc_list_add "$vhost_list" "$vhost"`
-
 }
 
 ###
-### make a temporary file
+###	output the name of a configuration file for a particular instance
+##
+##	usage: _wc_instance_cfg_file site dir httpd
 ###
-_wc_mktmp(){
-	local tmpconf
-	tmpconf=`mktemp -t`
-	if [ ! -f "$tmpconf" ]; then
-		echo "can't create temp file, error $?" >&2
-		return 1
-	else
-		echo "$tmpconf"
-	fi
+_wc_instance_cfg_file(){
+	echo "$wc_confdir/apps-available/${3}/${wc_package}_${1}_${2}.conf"
 }
 
 ###
-### logging messages
+###	output the name of where a symlink to the instance cfg file should be
+##
+##	usage: _wc_instance_cfg_link site dir httpd
 ###
-_wc_log(){
-	echo webapps-common: $@ >&2
+_wc_instance_cfg_link(){
+	echo "$wc_confdir/apps-enabled/${3}/${wc_package}_${1}_${2}.conf"
 }
 
 ###
-### debugging messages
 ###
-_wc_debug(){
-	if [ "$wc_debug" ]; then
-		_wc_log $@
-	fi
-}
+###

Modified: trunk/dpkg/config
===================================================================
--- trunk/dpkg/config	2006-04-21 08:57:40 UTC (rev 74)
+++ trunk/dpkg/config	2006-04-21 09:45:24 UTC (rev 75)
@@ -41,11 +41,13 @@
 	#	- if we're doing directory style install, then configure the
 	#	  the global instance
 	if [ "$installtype" = "directory" ]; then
-		wc_config_instance
+		wc_config_instance "[default]"
 	#	- otherwise configure each virtualhost instance
 	else
 		db_get $wc_package/httpd/virtualhost && vhosts_selected=$RET
 		for v in `_wc_list_explode "$vhosts_selected"`; do
+			wc_register_debconf "$v"
+			wc_preseed_debconf_vhost "$v"
 			wc_config_instance "$v"
 		done
 	fi
@@ -63,6 +65,8 @@
 	instype="$1"
 	case "$instype" in
 	"directory")
+		wc_register_debconf "[default]"
+		db_set $wc_package/httpd/virtualhost "[default]"
 		return 1;
 		;;
 	"virtualhost + directory")
@@ -114,6 +118,8 @@
 			db_set $wc_package/httpd/virtualhost_new ""
 			# copy over all the answers into a subtree just for this package
 			wc_register_debconf "$vhost_new"
+			# set the default directory
+			db_set $wc_package/vhosts/$vhost_new/website_subdirectory ""
 		fi
 		# at this point it's possible that they want to enter more
 		# vhosts, so we're not done yet

Modified: trunk/dpkg/postinst
===================================================================
--- trunk/dpkg/postinst	2006-04-21 08:57:40 UTC (rev 74)
+++ trunk/dpkg/postinst	2006-04-21 09:45:24 UTC (rev 75)
@@ -8,9 +8,12 @@
 	# read in debconf responses (which are seeded from the config)
 	wc_read_package_debconf $@
 	# sync them to disk
-	wc_dump_debconf_siteids
+	wc_dump_debconf_pkgconfig
 	wc_write_global_config
-	wc_write_package_config
+	# and finally, let's go out of our way to flush everything out
+	# of debconf's cache, to make sure we're not doing any evil
+	# "Debconf Is Not A Registry(tm)" stuff.
+	wc_forget_debconf
 
 	###
 	### begin main code execution
@@ -22,8 +25,9 @@
 		###
 
 		# do they want our help at all?  if so we'll quit
-		db_get $wc_package/webapps_install && wc_install="$RET"
 		if [ "$wc_install" != "true" ]; then return 0; fi
+
+		# write out all of the required httpd configuration files
+		wc_write_package_httpd_configs
 	fi
-	#wc_update_apache_siteconf
 }

Modified: trunk/dpkg/postrm
===================================================================
--- trunk/dpkg/postrm	2006-04-21 08:57:40 UTC (rev 74)
+++ trunk/dpkg/postrm	2006-04-21 09:45:24 UTC (rev 75)
@@ -8,22 +8,55 @@
 	wc_config $@
 
 	# remove symlinks at package removal if the file exists
-	if [ -f "$wc_package_confdir/apache.conf" ]; then
-		for h in `wc_httpd_installed`; do
-			if [ -L "/etc/$h/conf.d/$wc_package.conf" ]; then
-				deconfigured_httpds="$deconfigured_httpds $h"
-			fi
-		done
-	
-		if [ "$deconfigured_httpds" ]; then
-			wc_httpd_apache_uninclude "$wc_package_confdir/apache.conf" "$wc_package"
-			# reload the running web servers
-			wc_httpd_invoke reload `wc_httpd_running $deconfigured_httpds` || true
-		fi
+	# this also handles restarting the appropriate httpds
+	if [ "$wc_command" = "remove" ]; then
+		wc_postrm_disable_app
 	fi
 
 	# actually remove the files only in purge
 	if [ "$wc_command" = "purge" ]; then
-		wc_purge_httpd_conf
+		wc_postrm_purge_app
 	fi
 }
+
+wc_postrm_disable_app(){
+	local h vhost dir httpds app_link reload_list reload_file
+	_wc_debug "wc_postrm_disable_app() $@"
+
+	reload_file=`_wc_mktmp`
+
+	# for each configuration line in the file
+	grep -vE '^[[:space:]]*(#|$)' "$wc_pkgconfig" | while read vhost dir httpds; do
+		# update/merge the list of configured httpds
+		reload_list=`_wc_list_join "$reload_list" "$httpds"`
+		for h in `_wc_list_explode "$httpds"`; do
+			app_link=`_wc_instance_cfg_link $vhost $dir $h`
+			_wc_debug "disabling site config: $app_link"
+			rm -f "$app_link"
+		done
+		echo $reload_list > $reload_file
+	done
+
+	reload_list=`cat $reload_file`
+	rm -f "$reload_file"
+	_wc_debug "need to reload the following servers: ${reload_list}."
+
+	wc_httpd_invoke reload `wc_httpd_running $reload_list` || true
+}
+
+wc_postrm_purge_app(){
+	local h vhost dir httpds app_file
+	_wc_debug "wc_postrm_purge_app() $@"
+
+	# for each configuration line in the file
+	grep -vE '^[[:space:]]*(#|$)' "$wc_pkgconfig" | while read vhost dir httpds; do
+		# update/merge the list of configured httpds
+		for h in `_wc_list_explode "$httpds"`; do
+			app_file=`_wc_instance_cfg_file $vhost $dir $h`
+			ucf --purge "$app_file"
+			rm -f "$app_file"
+		done
+	done
+	ucf --purge "$wc_pkgconfig"
+	rm -f "$wc_pkgconfig"
+}

Modified: trunk/dpkg/prerm
===================================================================
--- trunk/dpkg/prerm	2006-04-21 08:57:40 UTC (rev 74)
+++ trunk/dpkg/prerm	2006-04-21 09:45:24 UTC (rev 75)
@@ -10,8 +10,7 @@
 		return 0
 	fi
 
-	wc_unconfigure_httpds
-
+	# XXX shouldn't this be in the postrm?
 	if [ "$wc_command" = "purge" ]; then
 		wc_unregister_templates
 	fi

Modified: trunk/internal/common
===================================================================
--- trunk/internal/common	2006-04-21 08:57:40 UTC (rev 74)
+++ trunk/internal/common	2006-04-21 09:45:24 UTC (rev 75)
@@ -1,8 +1,5 @@
 # common include files of internal "do-stuff" functions.
 
-# httpd-related stuff
-. /usr/share/webapps-common/internal/httpd
-
 ##
 ## internal sanity check for certain important variables
 ##
@@ -61,8 +58,10 @@
 _wc_list_is_member(){
 	local list query
 	list="$1"
-	query="$2"
 
+	# not that scary, just escapes square brackets in some cases :)
+	query=`echo $2 | sed -e 's,^\[\(.*\)\]$,\\\[\1\\\],'`
+
 	echo "$list" | grep -qw "$query"
 }
 
@@ -92,3 +91,35 @@
 	done
 	echo $list
 }
+
+
+###
+### logging messages
+###
+_wc_log(){
+	echo webapps-common: $@ >&2
+}
+
+###
+### debugging messages
+###
+_wc_debug(){
+	if [ "$wc_debug" ]; then
+		_wc_log $@
+	fi
+}
+
+###
+### make a temporary file
+###
+_wc_mktmp(){
+	local tmpconf
+	tmpconf=`mktemp -t`
+	if [ ! -f "$tmpconf" ]; then
+		echo "can't create temp file, error $?" >&2
+		return 1
+	else
+		echo "$tmpconf"
+	fi
+}
+

Modified: trunk/internal/httpd
===================================================================
--- trunk/internal/httpd	2006-04-21 08:57:40 UTC (rev 74)
+++ trunk/internal/httpd	2006-04-21 09:45:24 UTC (rev 75)
@@ -1,5 +1,8 @@
 # httpd-related functions
 
+# get some internal helper functions, like _dbc_sanity_check
+. /usr/share/webapps-common/internal/common
+
 wc_httpd_apaches="apache apache-ssl apache-perl apache2"
 
 # if they have not specified what they support, assume support for all
@@ -173,3 +176,34 @@
 	vhost_list=`_wc_list_create $vhost_list`
 	echo $vhost_list
 }
+
+###
+### wc_httpd_create_vhost: create a new vhost compatible with webapps-common
+##	usage: wc_httpd_create_vhost vhost httpd1[ httpd2...]
+###
+wc_httpd_create_vhost(){
+	local tmpfile vhost httpd httpds
+	_wc_debug "wc_httpd_create_vhost() $@"
+
+	vhost=$1
+	httpds=$*
+
+	for httpd in $httpds; do
+		tmpfile=`_wc_mktmp`
+		chmod 644 $tmpfile
+		case $httpd in
+		apache2)
+			cp /usr/share/webapps-common/templates/apache-virtualhost.conf $tmpfile
+			sed -i -e "s,_WC_VHOST_,$vhost,g" $tmpfile
+			sed -i -e "s,_WC_HTTPD_,apache2," $tmpfile
+			ucf $tmpfile /etc/apache2/sites-available/$vhost
+			a2ensite $vhost >/dev/null
+			;;
+		*)
+			# XXX
+			_wc_log "creating vhosts for $httpd is currently not supported"
+			;;
+		esac
+		rm -f $tmpfile
+	done
+}

Added: trunk/templates/apache-virtualhost.conf
===================================================================
--- trunk/templates/apache-virtualhost.conf	2006-04-21 08:57:40 UTC (rev 74)
+++ trunk/templates/apache-virtualhost.conf	2006-04-21 09:45:24 UTC (rev 75)
@@ -0,0 +1,3 @@
+<VirtualHost _WC_VHOST_>
+	Include /etc/webapps-common/apps-enabled/_WC_HTTPD_/_WC_VHOST_/*.conf
+</VirtualHost>

Added: trunk/templates/apache2-wc-master.conf
===================================================================
--- trunk/templates/apache2-wc-master.conf	2006-04-21 08:57:40 UTC (rev 74)
+++ trunk/templates/apache2-wc-master.conf	2006-04-21 09:45:24 UTC (rev 75)
@@ -0,0 +1,5 @@
+# master configuration file for webapps-common, apache2 flavor
+# this file is responsible for instructing apache2 to load all
+# application configuration files for packages configured via
+# webapps common.
+Include /etc/webapps-common/apps-enabled/apache2/*.conf




More information about the Webapps-common-discuss mailing list