[Webapps-common-discuss] [commit] r117 - in webapps-common/trunk: . debian debian/po doc dpkg examples/webapp-apache-dbapp-example examples/webapp-apache-dbapp-example/debian internal templates

seanius at alioth.debian.org seanius at alioth.debian.org
Sun Jul 8 22:09:25 UTC 2007


Author: seanius
Date: 2007-07-08 22:09:25 +0000 (Sun, 08 Jul 2007)
New Revision: 117

Added:
   webapps-common/trunk/templates/apache-global.conf
   webapps-common/trunk/templates/appconfig.php
Removed:
   webapps-common/trunk/templates/apache2-wc-master.conf
Modified:
   webapps-common/trunk/TODO
   webapps-common/trunk/debian/changelog
   webapps-common/trunk/debian/control
   webapps-common/trunk/debian/po/templates.pot
   webapps-common/trunk/debian/webapps-common.dirs
   webapps-common/trunk/debian/webapps-common.postinst
   webapps-common/trunk/debian/webapps-common.templates
   webapps-common/trunk/doc/webapps-common.sgml
   webapps-common/trunk/dpkg/common
   webapps-common/trunk/dpkg/config
   webapps-common/trunk/dpkg/postinst
   webapps-common/trunk/dpkg/postrm
   webapps-common/trunk/dpkg/prerm
   webapps-common/trunk/examples/webapp-apache-dbapp-example/apache_template.conf
   webapps-common/trunk/examples/webapp-apache-dbapp-example/debian/postinst
   webapps-common/trunk/examples/webapp-apache-dbapp-example/debian/postrm
   webapps-common/trunk/examples/webapp-apache-dbapp-example/debian/rules
   webapps-common/trunk/examples/webapp-apache-dbapp-example/index.php
   webapps-common/trunk/examples/webapp-apache-dbapp-example/settings.php
   webapps-common/trunk/internal/httpd
   webapps-common/trunk/templates/apache-virtualhost.conf
Log:
big ol' chunka work from some offline travelling this weekend.


Modified: webapps-common/trunk/TODO
===================================================================
--- webapps-common/trunk/TODO	2007-06-22 16:02:19 UTC (rev 116)
+++ webapps-common/trunk/TODO	2007-07-08 22:09:25 UTC (rev 117)
@@ -2,21 +2,40 @@
 
 - handling pre-existing virtualhosts.  currently we end up with duplicate
   configs...
+  - probably best thing to do is to catch when this happens, and offer to
+    update the configuration.  but by default we couldn't touch the config.
+- migration paths for previously existing packages which used other
+  methods for configuration, other configuration file locations, etc.
 
+- automatic setup of various support dirs for multi-instance apps.  i.e.
+  /var/lib/$pkg/wc/$siteid, /var/cache/$pkg/wc/$siteid, etc
+
 - finish dbconfig-common integration:
   - currently the package has to set dbc_dbtype in each maintainer
     script, which is a bit sub-optimal imo.
   - multi-instance support is still a little rough around the edges
+    - need to fix the "package name" as shown by the dbconfig common prompts
+	- user gets prompted for admin password N*M times, for N instances of M 
+	  packages being configured.
   - newer versions of dbconfig-common have changed behaviour in a way that
     automagic batch configuration isn't so automagic anymore (you have to
 	answer yes to "reinstall this db" which is kinda annoying
-  - dbc doesn't remember the admin password between goes.
+  - dbc needs dbc_packagetitle support to make things a little more 
+    friendly to the admin doing the configuration.
 
-- migration paths for previously existing packages which used other
-  methods for configuration.
-
 further ahead:
 
-- there are some tasks which would probably do best to be abstracted into
-  actual cmdline programs, like wc-newsite foobar.com or something, which
-  could then be used as a general purpose tool.
+- a general purpose admin tool.  ideas:
+	- create/enable/disable/delete virtualhosts
+		wcadmin vhost new foobar.com
+		wcadmin vhost enable foobar.com
+		wcadmin vhost disable foobar.com
+		wcadmin vhost del foobar.com
+	- create/enable/disable/delete webapp instances 
+		wcadmin appinst new package vhost subdir
+		wcadmin appinst enable package vhost subdir
+		wcadmin appinst disable package vhost subdir
+		wcadmin appinst del package vhost subdir
+	- query vhost/webapp info
+		wcadmin ls vhost
+		wcadmin ls app

Modified: webapps-common/trunk/debian/changelog
===================================================================
--- webapps-common/trunk/debian/changelog	2007-06-22 16:02:19 UTC (rev 116)
+++ webapps-common/trunk/debian/changelog	2007-07-08 22:09:25 UTC (rev 117)
@@ -7,9 +7,13 @@
     support on a per-instance basis.  requires a versioned dependency on
     dbconfig-common.  still a little rough around the edges...
   * related to the above, support per-instance config-file generation.
-    XXX still need to finalize document this.
+    XXX still need to finalize and document this.
   * updates to the templated virtualhost configuration, including a fix
     from Jan-Pascal van Best.
+  * replace usage of =global= with __global__, because it tab-completes
+    better and is still outside the namespace of valid hostnames.
+  * various documentation updates.
+  * TODO look for the XXX's.  gotta catch em all!
 
  -- sean finney <seanius at debian.org>  Mon, 14 May 2007 01:21:56 +0200
 

Modified: webapps-common/trunk/debian/control
===================================================================
--- webapps-common/trunk/debian/control	2007-06-22 16:02:19 UTC (rev 116)
+++ webapps-common/trunk/debian/control	2007-07-08 22:09:25 UTC (rev 117)
@@ -7,7 +7,7 @@
 
 Package: webapps-common
 Architecture: all
-Depends: ${misc:Depends}, dbconfig-common (>= 1.8.33)
+Depends: ${misc:Depends}, dbconfig-common (>= 1.8.36)
 Description: common framework for packaging web applications
  webapps-common presents a policy and implementation for various
  aspects of involved in developing and managing web applications in

Modified: webapps-common/trunk/debian/po/templates.pot
===================================================================
--- webapps-common/trunk/debian/po/templates.pot	2007-06-22 16:02:19 UTC (rev 116)
+++ webapps-common/trunk/debian/po/templates.pot	2007-07-08 22:09:25 UTC (rev 117)
@@ -176,7 +176,7 @@
 #. Type: select
 #. Choices
 #: ../webapps-common.templates:7001
-msgid "=global=, new vhost, ${virtualhosts}"
+msgid "__global__, new vhost, ${virtualhosts}"
 msgstr ""
 
 #. Type: select
@@ -190,7 +190,7 @@
 #: ../webapps-common.templates:7002
 msgid ""
 "If you want to configure this application for the default site available "
-"from your webserver, you should select \"=global=\".  If you wish to "
+"from your webserver, you should select \"__global__\".  If you wish to "
 "configure the application to run on a virtualhost that does not appear in "
 "the list of choices, you can select \"new vhost\"."
 msgstr ""

Modified: webapps-common/trunk/debian/webapps-common.dirs
===================================================================
--- webapps-common/trunk/debian/webapps-common.dirs	2007-06-22 16:02:19 UTC (rev 116)
+++ webapps-common/trunk/debian/webapps-common.dirs	2007-07-08 22:09:25 UTC (rev 117)
@@ -1,13 +1,17 @@
 usr/share/webapps-common/internal
 usr/share/webapps-common/install
-etc/webapps-common/apps-available/apache/=global=
-etc/webapps-common/apps-available/apache2/=global=
-etc/webapps-common/apps-available/apache-ssl/=global=
-etc/webapps-common/apps-available/apache-perl/=global=
-etc/webapps-common/apps-enabled/apache/=global=
-etc/webapps-common/apps-enabled/apache2/=global=
-etc/webapps-common/apps-enabled/apache-ssl/=global=
-etc/webapps-common/apps-enabled/apache-perl/=global=
+etc/webapps-common/apps-available/apache/__global__
+etc/webapps-common/apps-available/apache2/__global__
+etc/webapps-common/apps-available/apache-ssl/__global__
+etc/webapps-common/apps-available/apache-perl/__global__
+etc/webapps-common/apps-enabled/apache/__global__
+etc/webapps-common/apps-enabled/apache2/__global__
+etc/webapps-common/apps-enabled/apache-ssl/__global__
+etc/webapps-common/apps-enabled/apache-perl/__global__
+etc/webapps-common/custom-templates/apache
+etc/webapps-common/custom-templates/apache-ssl
+etc/webapps-common/custom-templates/apache-perl
+etc/webapps-common/custom-templates/apache2
 etc/apache2/conf.d
 etc/apache/conf.d
 etc/apache-ssl/conf.d

Modified: webapps-common/trunk/debian/webapps-common.postinst
===================================================================
--- webapps-common/trunk/debian/webapps-common.postinst	2007-06-22 16:02:19 UTC (rev 116)
+++ webapps-common/trunk/debian/webapps-common.postinst	2007-07-08 22:09:25 UTC (rev 117)
@@ -14,11 +14,14 @@
 
 	tfile=`mktemp -t`
 	for httpd in apache apache2 apache-ssl apache-perl; do
-		sed -e "s,HTTPD,$httpd,g" < ${template_dir}/apache2-wc-master.conf > $tfile
+		sed -e "s,HTTPD,$httpd,g" < ${template_dir}/apache-global.conf > $tfile
 		ucf $tfile /etc/$httpd/conf.d/webapps-common.conf
 		# XXX should probably respect permissions here
 		chown root:www-data /etc/$httpd/conf.d/webapps-common.conf
-		# XXX should probably reload the servers here?
+		sed -e "s,HTTPD,$httpd,g" < ${template_dir}/apache-virtualhost.conf > $tfile
+		ucf $tfile /etc/webapps-common/custom-templates/$httpd/virtualhost.conf
+		# XXX should probably respect permissions here
+		chown root:www-data /etc/$httpd/conf.d/webapps-common.conf
 	done
 	rm -f $tfile
 fi

Modified: webapps-common/trunk/debian/webapps-common.templates
===================================================================
--- webapps-common/trunk/debian/webapps-common.templates	2007-06-22 16:02:19 UTC (rev 116)
+++ webapps-common/trunk/debian/webapps-common.templates	2007-07-08 22:09:25 UTC (rev 117)
@@ -80,10 +80,10 @@
 
 Template: webapps-common/httpd/virtualhost
 Type: select
-_Choices: =global=, new vhost, ${virtualhosts}
+_Choices: __global__, new vhost, ${virtualhosts}
 _Description: Please select a virtualhost with which to configure ${pkg}
  If you want to configure this application for the default site available
- from your webserver, you should select "=global=".  If you wish to
+ from your webserver, you should select "__global__".  If you wish to
  configure the application to run on a virtualhost that does not appear
  in the list of choices, you can select "new vhost".
 

Modified: webapps-common/trunk/doc/webapps-common.sgml
===================================================================
--- webapps-common/trunk/doc/webapps-common.sgml	2007-06-22 16:02:19 UTC (rev 116)
+++ webapps-common/trunk/doc/webapps-common.sgml	2007-07-08 22:09:25 UTC (rev 117)
@@ -12,7 +12,7 @@
 	with an easy, reliable, and consistant method for managing
 	issues related to web applications.  
 <copyright>
-	Copyright © 2005 sean finney <email>seanius at debian.org</email>.
+	Copyright © 2005-2007 sean finney <email>seanius at debian.org</email>.
 <toc sect1>
 <chapt id="intro">Introduction
 	<p>
@@ -31,16 +31,13 @@
 	<item>support the entire family of apache based webservers
 	<item>support "subdirectory" and "virtualhost" style configurations
 	      for web servers
-	<item>generate web server configuration files automatically
-	<item>include maintainer-specified directives in autogenerated 
-	      configurations files
-	<item>alternatively generate web server configuration by using 
-	      variable substitution into maintainer-supplied templates
-	<item>integrated support for database applications 
-	      via dbconfig-common (XXX: for "single instance" installs only,
-		  currently)
+	<item>support multiple "instances" of an installed application, so that
+	      one installed package can be used for any number of installed sites.
+	<item>generate template-based web server configuration files automatically,
+	      customizable by both the packager and the local admin.
+	<item>generate template-based web application configuration files.
+	<item>integrated support for database applications
 	<item>prompt users with a set of normalized, pre-translated questions
-	<item>NOTYET: handle failures gracefully, with an option to retry.
 	<item>work for package maintainers with little effort on their part
 	<item>do all the hard work automatically
 	<item>work for local admins with little effort on their part
@@ -87,8 +84,16 @@
 			# this file will be included as-is, with the exception that
 			# certain substitutions will occur with the result
 
-			_WC_DOCROOT_DIRECTIVE_ /usr/share/foo/www
-			&lt;Directory /usr/share/foo/www&gt;
+			# this macro expands to either a DocumentRoot or an Alias 
+			# directive, depending on whether this app is configured to
+			# run as a top level (i.e. www.foobar.com) or a subdirectory
+			# based configuration respectively.  
+			_WC_DOCROOT_DIRECTIVE_
+
+			# it is important to use Location instead of Directory
+			# for the webapps-common based config if you have an application
+			# that supports multiple instances
+			&lt;Location _WC_WEBSITE_SUBDIRECTORY_&gt;
 				# other settings here that relate to your application
 				# for example, if your app ships with its own php libraries:
 				php_value include_path ".:/usr/share/foo/lib"
@@ -115,9 +120,13 @@
 			The following example illustrates how this would be done in
 			the config maintainance script.
 			<example>
-			. /usr/share/debconf/confmodule
-			. /usr/share/webapps-common/dpkg/config
-			wc_go PACKAGE $@
+			if [ -f "/usr/share/debconf/confmodule" ]; then
+				. /usr/share/debconf/confmodule
+			fi
+			if [ -f "/usr/share/webapps-common/dpkg/config" ]; then
+				. /usr/share/webapps-common/dpkg/config
+				wc_go PACKAGE $@
+			fi
 			</example>
 			<p>
 			you must place these hooks into your
@@ -136,9 +145,95 @@
 		the included buildpackages.sh script to generate them.
 
 <chapt id="advanced">Advanced Techniques and Concepts
+	<sect id="genconfig">Automatic Configuration Generation
+	<p>
+	It's quite possible, that your application will need to access some
+	configuration details at run-time, via an included configuration file.
+	for example, it might need to know the name of the virtualhost on which
+	it resides, or perhaps the root subdirectory from which it is being 
+	accessed.  This can easily be done by setting the variable 
+	<var>wc_generate_include</var>, in your <var>postinst</var> and
+	<var>postrm</var> scripts before calling <var>wc_go</var>.  The format
+	of this variable is <var>mode</var>:<var>src</var>:<var>dest</var>:
+	<taglist>
+	<tag>mode
+	<item>the language format in question.  for example, "php".
+	<tag>src
+	<item>your provided config template.  this file will look generally
+	      how you expect your application's configure to look, only it
+		  can contain various substXXX
+	<tag>dest
+	<item>
+	</taglist>
+
+	<sect id="dbapp">Database Applications
+	<p>
+	Some web applications require an underlying database.  This can be
+	done by setting the hint variable <var>wc_dbtype</var> (in the case that
+	your app supports only one database type) or <var>wc_dbtypes</var> (in
+	the case that your app supports multiple database types).  Note that this
+	must be done in <em>each</em> of your maintainer scripts that
+	call <var>wc_go</var> (<var>config</var>, <var>postinst</var>, 
+	<var>prerm</var>, and <var>postrm</var>). These variables
+	will be used to influence and invoke <package>dbconfig-common</package>'s
+	database configuration support.  Various other 
+	<package>dbconfig-common</package> hint variables can also be used to 
+	customize how your package handles database configuration; for more 
+	information, see the 
+	<url id="http://people.debian.org/~seanius/policy/dbconfig-common.html" name="dbconfig-common Documentation">
+	<p>
+	Note that due to the needs of multi-instance support, it is not currently possible to 
+	override the names for the database or database user name (dbc_dbuser and dbc_dbname).
+
+	<sect id="multiinst">Multiple Instance Support
+	<p>
+	Some web applications support (or can be easily extended to support)
+	the concept of "multi instance" installations, where a single set of files
+	can be used to serve up multiple versions of an application.  For example,
+	it might be desirable for a webserver providing multiple virtualhosts to
+	provide a seperate instance of a webmail application on each virtualhost.
+	Alternatively (or additionally) the ability to provide different instances
+	of the same application under different subdirectories of the same 
+	virtulhost might be desirable.
+
+	<p>
+	webapps-common provides drop-in support for such applications, including
+	support for generating unique configuration files for each instance (to
+	allow for different passwords, different database configurations, etc).
+	To take advantage of this feature, you need to simply hint webapps-common
+	in your <var>config</var> script by setting the variable 
+	<var>wc_multiple_instances="yes"</var>.  example:
+	<example>
+	if [ -f /usr/share/debconf/confmodule ]; then
+		. /usr/share/debconf/confmodule
+	fi
+	if [ -f /usr/share/webapps-common/dpkg/config ]; then
+		. /usr/share/webapps-common/dpkg/config
+		wc_multiple_instances="yes"
+		wc_go mypackage "$@"
+	fi
+	</example>
+	<p>
+	Additionally, if you use the <var>wc_generate_include</var> feature for
+	generating your configuration files, you will not need to worry about
+	setting per-instance-configuration--this will be taken care of for you.
+
+	<p>
+	however, it is still the responsibility of the application (and by extension,
+	you the package maintainer) to ensure that the application can function 
+	properly when having multiple instances configured in parallel.  for example,
+	if your web application requires a daemon running in the background for each
+	instance, or a dedicated filesystem directory for each instance, that is currently
+	outside the scope of webapps-common.  <em>note</em>: this will probably change
+	in the future, after getting feedback from some maintainers.  and in the meantime
+	you can probably hack in whatever support you need yourself using some of the
+	webapps-common variable substitutions when generating your config.
+
+	<sect id="multidbapp">Multiple Instances <em>and</em> Database Support
 	<p> TODO
 
 <chapt id="architecture">For the curious: architecture of webapps-common.
+	XXX finish this.
 	<p>
 	the following is a quick reference outline of files and directories
 	that play a part in the functioning of webapps-common.

Modified: webapps-common/trunk/dpkg/common
===================================================================
--- webapps-common/trunk/dpkg/common	2007-06-22 16:02:19 UTC (rev 116)
+++ webapps-common/trunk/dpkg/common	2007-07-08 22:09:25 UTC (rev 117)
@@ -79,24 +79,57 @@
 	#db_metaget $wc_package/httpd/virtualhost virtualhosts && vhost_list="$RET"
 	# XXX so we do it this way instead which works as long as config was dumped
 	vhost_list=`grep -v '^[[:space:]]*#' $wc_pkgconfig | cut -sf1 | cut -d / -f1`
-	vhost_list=`_wc_list_remove "$vhost_list" '=global='`
+	vhost_list=`_wc_list_remove "$vhost_list" '__global__'`
 	for v in `_wc_list_explode "$vhost_list"`; do
 		if ! _wc_list_is_member "$old_vhost_list" "$v"; then
 			echo $v >> "$tfile"
 		fi
 	done
-	# XXX nyeh... the wc_list_remove isn't removing =global= for some reason...
-	sed -i -e '/^=global=/d' "$tfile"
+	# XXX nyeh... the wc_list_remove isn't removing __global__ for some reason...
+	sed -i -e '/^__global__/d' "$tfile"
 	ucf "$tfile" "$wc_vhostconfig"
 	rm -f "$tfile"
 }
 
 ###
+### wc_subst: perform some simple template subsitutions on a file
+###
+##	usage: wc_subst instance
+###
+wc_subst(){
+	local site siteid dir docroot_directive env_stmt
+
+	site=`echo $1 | cut -d/ -f1`
+	dir="/`echo $1 | cut -sd/ -f2- | sed -e 's,^/,,'`"
+
+	if [ "$dir" = "/" ]; then
+		docroot_directive="DocumentRoot $wc_website_documentroot"
+	else
+		docroot_directive="Alias $dir $wc_website_documentroot"
+	fi
+
+	siteid=`wc_debian_siteid $i`
+	if [ "$site" = "__global__" ]; then
+		env_stmt="\tSetEnvIf X_DEBIAN_SITEID \"^$\" X_DEBIAN_SITEID=$siteid"
+		env_stmt="$env_stmt\n\tSetEnvIf X_DEBIAN_SUBDIR \"^$\" X_DEBIAN_SUBDIR=$dir"
+	else
+		env_stmt="\tSetEnvIf Host \"^$site\$\" X_DEBIAN_SITEID=$siteid"
+		env_stmt="$env_stmt\n\tSetEnvIf Host \"^$site\$\" X_DEBIAN_SUBDIR=$dir"
+	fi
+
+	sed -e "s,_WC_WEBSITE_SUBDIRECTORY_,$dir,g" \
+	    -e "s,_WC_WEBSITE_DOCUMENTROOT_,$wc_website_documentroot,g" \
+	    -e "s,_WC_WEBSITE_HOSTNAME_,$site,g" \
+	    -e "s,_WC_DEBIAN_SITEID_DIRECTIVE_,$env_stmt,g" \
+	    -e "s,_WC_DOCROOT_DIRECTIVE_,$docroot_directive\n<Location $dir>\n$env_stmt\n</Location>,g"
+}
+
+###
 ### dump package configuration to a config file
 ###
 wc_write_package_httpd_configs(){
-	local srcfile tmpconf instances i site dir httpds h output clink reload_list docroot_directive
-	_wc_debug "wc_write_package_httpd_config() $@"
+	local srcfile tmpconf instances i site httpds h output clink reload_list 
+	_wc_debug "wc_write_package_httpd_configs() $@"
 
 	tmpconf=`_wc_mktmp`
 
@@ -112,22 +145,11 @@
 	for i in `_wc_list_explode "$instances"`; do
 		site=`echo $i | cut -d/ -f1`
 		selected_sites=`_wc_list_add "$selected_sites" "$site"`
-		dir="/`echo $i | cut -sd/ -f2- | sed -e 's,^/,,'`"
 
-		if [ "$dir" = "/" ]; then
-			docroot_directive="DocumentRoot $wc_website_documentroot"
-		else
-			docroot_directive="Alias $dir $wc_website_documentroot"
-		fi
-
 		db_get $wc_package/sites/$i/httpd/select_httpd && httpds="$RET"
 
 		for h in `_wc_list_explode "$httpds"`; do
-			sed -e "s,_WC_WEBSITE_SUBDIRECTORY_,$dir,g" \
-			    -e "s,_WC_WEBSITE_DOCUMENTROOT_,$wc_website_documentroot,g" \
-			    -e "s,_WC_WEBSITE_HOSTNAME_,$site,g" \
-				-e "s,_WC_DEBIAN_SITEID_,`wc_debian_siteid $i`," \
-			    -e "s,_WC_DOCROOT_DIRECTIVE_,$docroot_directive,g" < "$srcfile" > "$tmpconf"
+			wc_subst "$i" < "$srcfile" > "$tmpconf"
 			output=`_wc_instance_cfg_file "$i" "$h"`
 			mkdir -p `dirname "$output"`
 				
@@ -150,7 +172,7 @@
 					ln -s "$output" "$clink"
 					reload_list=`_wc_list_add "$reload_list" "$h"`
 				fi
-				if [ ! "$site" = "=global=" ]; then
+				if [ ! "$site" = "__global__" ]; then
 					wc_httpd_create_vhost $site $h
 				fi
 			fi
@@ -450,7 +472,7 @@
 		ext=".$ext"
 	fi
 	siteid=`wc_debian_siteid $instance`
-	echo "${mode}:${based}/${basef}${siteid}${ext}"
+	echo "${mode}:${based}/${basef}-${siteid}${ext}"
 }
 
 

Modified: webapps-common/trunk/dpkg/config
===================================================================
--- webapps-common/trunk/dpkg/config	2007-06-22 16:02:19 UTC (rev 116)
+++ webapps-common/trunk/dpkg/config	2007-07-08 22:09:25 UTC (rev 117)
@@ -45,6 +45,7 @@
 		for i in `_wc_list_explode "$instances"`; do
 			_wc_debug "  $i"
 			dbc_package="${wc_package}_`wc_debian_siteid $i`"
+            dbc_packagetitle="${wc_package} ($i)"
 			dbc_dbuser="`wc_gen_unique_user $wc_package $i`"
 			dbc_dbname="`wc_gen_unique_db $wc_package $i`"
 			if [ "$wc_dbtype" ]; then

Modified: webapps-common/trunk/dpkg/postinst
===================================================================
--- webapps-common/trunk/dpkg/postinst	2007-06-22 16:02:19 UTC (rev 116)
+++ webapps-common/trunk/dpkg/postinst	2007-07-08 22:09:25 UTC (rev 117)
@@ -30,6 +30,7 @@
 		# "Debconf Is Not A Registry(tm)" stuff.
 		wc_forget_debconf
 		wc_postinst_dbapp_support $@
+		wc_postinst_genconfig
 	fi
 }
 
@@ -56,8 +57,8 @@
 }
 
 wc_postinst_dbapp_support(){
-	local includefile
-	if [ "$wc_dbtype" ] || [ "$wc_dbtypes" ]; then
+	local includefile instances i realpackage
+	if [ "${wc_dbtype}${wc_dbtypes}" ]; then
 		_wc_debug "postinst configuring database(s): "
 		instances=`grep -vE '^[[:space:]]*#' "$wc_pkgconfig" | cut -sf1` 2>/dev/null || true	
 		realpackage=$wc_package
@@ -69,14 +70,56 @@
 				dbc_dbtypes="$wc_dbtypes"
 				. /usr/share/dbconfig-common/dpkg/postinst
 			fi
-			if [ "$wc_generate_include" ]; then
-				dbc_generate_include=`wc_to_dbc_generate_include $i`
-				_wc_debug "dbc_generate_include: $dbc_generate_include"
-			fi
 			dbc_package="${wc_package}_`wc_debian_siteid $i`"
+			dbc_packagetitle="${wc_package} ($i)"
 			_wc_debug dbc_go $dbc_package $wc_command $wc_oldversion
 			dbc_go $dbc_package $wc_command $wc_oldversion
 		done
 	fi
 }
 
+wc_postinst_genconfig(){
+	local instances i mode src dest configbase configext tfile dbc_cfg dest_p siteid
+	_wc_debug "postinst generating webapp configuration file(s): "
+
+	if [ "$wc_generate_include" ]; then
+		# wc_generate_include format:
+		# 	mode:src:dest
+		tfile=`_wc_mktmp`
+		mode=`echo $wc_generate_include | cut -d: -f1`
+		src=`echo $wc_generate_include | cut -d: -f2`
+		dest=`echo $wc_generate_include | cut -d: -f3`
+		configbase=`echo $dest | sed -e 's,\(.*\)\(\.[^\.]*\)$,\1,'`
+		case $mode in
+		php)
+			configext=".php"
+			;;
+		esac
+		sed -e "s|CONFIGBASE|$configbase|g" \
+			-e "s|CONFIGEXT|$configext|g" \
+			< ${wc_share}/templates/appconfig.${mode} > $tfile
+		ucf $tfile $dest
+		# XXX preserve ownership/perms...
+		chown root:www-data $dest
+		chmod 640 $dest
+
+		instances=`grep -vE '^[[:space:]]*#' "$wc_pkgconfig" | cut -sf1` 2>/dev/null || true	
+		for i in $instances; do
+			_wc_debug "   $i"
+			siteid=`wc_debian_siteid "$i"`
+			dest_p="${configbase}-${siteid}${configext}"
+			wc_subst "$i" < $src > $tfile
+			if [ "${wc_dbtype}${wc_dbtypes}" ]; then
+				dbc_cfg="/etc/dbconfig-common/${wc_package}_${siteid}.conf"
+				# XXX perms/owner
+				dbconfig-generate-include -U -O root:www-data -m 640 -f template -o "template_infile=$src" "$dbc_cfg" "$dest_p"
+			else
+				ucf $tfile $dest_p
+				# XXX perms/owner
+				chown root:www-data "$dest_p"
+				chmod 640 "$dest_p"
+			fi
+		done
+		rm -f $tfile
+	fi
+}

Modified: webapps-common/trunk/dpkg/postrm
===================================================================
--- webapps-common/trunk/dpkg/postrm	2007-06-22 16:02:19 UTC (rev 116)
+++ webapps-common/trunk/dpkg/postrm	2007-07-08 22:09:25 UTC (rev 117)
@@ -15,7 +15,7 @@
 
 	# run the dbconig support here, before we delete the files we
 	# need to run the dbconfig support
-	if [ "$wc_dbtype" ] || [ "$wc_dbtypes" ]; then
+	if [ "${wc_dbtype}${wc_dbtypes}" ]; then
 		_wc_debug "postrm deconfiguring database(s): "
 		instances=`grep -vE '^[[:space:]]*#' "$wc_pkgconfig" | cut -sf1` 2>/dev/null || true
 		for i in $instances; do
@@ -27,12 +27,14 @@
 				. /usr/share/dbconfig-common/dpkg/postrm
 			fi
 			dbc_package="${wc_package}_`wc_debian_siteid $i`"
+			dbc_packagetitle="${wc_package} ($i)"
 			dbc_go $dbc_package $wc_command $wc_oldversion
 		done
 	fi
 
 	# actually remove the files only in purge
 	if [ "$wc_command" = "purge" ]; then
+		wc_postrm_purge_app_gencfg
 		wc_postrm_purge_app
 	fi
 }
@@ -72,3 +74,34 @@
 	ucf --purge "$wc_pkgconfig"
 	rm -f "$wc_pkgconfig"
 }
+
+wc_postrm_purge_app_gencfg(){
+	local i instances mode src dest dest_p configbase configext siteid dbc_cfg
+	if [ "$wc_generate_include" ]; then
+		_wc_debug "postrm purging autogenerated app config(s)"
+		mode=`echo $wc_generate_include | cut -d: -f1`
+		src=`echo $wc_generate_include | cut -d: -f2`
+		dest=`echo $wc_generate_include | cut -d: -f3`
+		configbase=`echo $dest | sed -e 's,\(.*\)\(\.[^\.]*\)$,\1,'`
+		case $mode in
+		php)
+			configext=".php"
+			;;
+		esac
+		ucf --purge "$dest" || true
+		rm -f "$dest"
+		instances=`grep -vE '^[[:space:]]*#' "$wc_pkgconfig" | cut -sf1` 2>/dev/null || true
+		for i in $instances; do
+			_wc_debug "	$i"
+			siteid=`wc_debian_siteid "$i"`
+			dest_p="${configbase}-${siteid}${configext}"
+			ucf --purge "$dest_p" || true
+			rm -f "$dest_p"
+			if [ "${wc_dbtype}${wc_dbtypes}" ]; then
+				dbc_cfg="/etc/dbconfig-common/${wc_package}_${siteid}.conf"
+				ucf --purge "$dbc_cfg" || true
+				rm -f "$dbc_cfg"
+			fi
+		done
+	fi
+}

Modified: webapps-common/trunk/dpkg/prerm
===================================================================
--- webapps-common/trunk/dpkg/prerm	2007-06-22 16:02:19 UTC (rev 116)
+++ webapps-common/trunk/dpkg/prerm	2007-07-08 22:09:25 UTC (rev 117)
@@ -19,6 +19,7 @@
 					. /usr/share/dbconfig-common/dpkg/prerm
 				fi
 				dbc_package="${wc_package}_`wc_debian_siteid $i`"
+				dbc_packagetitle="${wc_package} ($i)"
 				dbc_go $dbc_package $wc_command $wc_oldversion
 			done
 		fi

Modified: webapps-common/trunk/examples/webapp-apache-dbapp-example/apache_template.conf
===================================================================
--- webapps-common/trunk/examples/webapp-apache-dbapp-example/apache_template.conf	2007-06-22 16:02:19 UTC (rev 116)
+++ webapps-common/trunk/examples/webapp-apache-dbapp-example/apache_template.conf	2007-07-08 22:09:25 UTC (rev 117)
@@ -11,9 +11,7 @@
 #	Where foo is the 
 _WC_DOCROOT_DIRECTIVE_
 
-<Directory /usr/share/webapp-apache-dbapp-example/www>
-	# the following line is required for multi-instance supporting apps.
-	# otherwise, you could omit it.
-	SetEnv X_DEBIAN_SITEID _WC_DEBIAN_SITEID_
-	# other stuff could be done here...
+# you can have your application-specific settings like so
+<Directory _WC_WEBSITE_DOCUMENTROOT_>
+	# stuff goes here
 </Directory>

Modified: webapps-common/trunk/examples/webapp-apache-dbapp-example/debian/postinst
===================================================================
--- webapps-common/trunk/examples/webapp-apache-dbapp-example/debian/postinst	2007-06-22 16:02:19 UTC (rev 116)
+++ webapps-common/trunk/examples/webapp-apache-dbapp-example/debian/postinst	2007-07-08 22:09:25 UTC (rev 117)
@@ -5,8 +5,7 @@
 . /usr/share/debconf/confmodule
 . /usr/share/webapps-common/dpkg/postinst
 wc_dbtype="mysql"
-wc_generate_include="php:/etc/webapp-apache-dbapp-example/site-:php"
-dbc_generate_include_args="-O root:www-data -m 640"
+wc_generate_include="php:/usr/share/webapp-apache-dbapp-example/settings.php:/etc/webapp-apache-dbapp-example/settings.php"
 wc_go webapp-apache-dbapp-example $@
 
 #DEBHELPER#

Modified: webapps-common/trunk/examples/webapp-apache-dbapp-example/debian/postrm
===================================================================
--- webapps-common/trunk/examples/webapp-apache-dbapp-example/debian/postrm	2007-06-22 16:02:19 UTC (rev 116)
+++ webapps-common/trunk/examples/webapp-apache-dbapp-example/debian/postrm	2007-07-08 22:09:25 UTC (rev 117)
@@ -5,15 +5,7 @@
 . /usr/share/debconf/confmodule
 . /usr/share/webapps-common/dpkg/postrm
 wc_dbtype="mysql"
+wc_generate_include="php:/usr/share/webapp-apache-dbapp-example/settings.php:/etc/webapp-apache-dbapp-example/settings.php"
 wc_go webapp-apache-dbapp-example $@
 
-if [ "$1" = "purge" ]; then
-	rm -f /etc/webapp-apache-dbapp-example/settings.php
-	ucf --purge /etc/webapp-apache-dbapp-example/settings.php || true
-	for f in /etc/webapp-apache-dbapp-example/site-*.php; do
-		rm -f $f
-		ucf --purge $f || true
-	done
-fi
-
 #DEBHELPER#

Modified: webapps-common/trunk/examples/webapp-apache-dbapp-example/debian/rules
===================================================================
--- webapps-common/trunk/examples/webapp-apache-dbapp-example/debian/rules	2007-06-22 16:02:19 UTC (rev 116)
+++ webapps-common/trunk/examples/webapp-apache-dbapp-example/debian/rules	2007-07-08 22:09:25 UTC (rev 117)
@@ -14,6 +14,7 @@
 ptmp:=debian/$p
 INSTDIR:=${ptmp}/usr/share/webapps-common/install/$p/httpd
 DBINSTDIR:=${ptmp}/usr/share/dbconfig-common/data/$p/install
+SHRDIR:=${ptmp}/usr/share/$p
 WEBDOCDIR:=${ptmp}/usr/share/$p/www
 
 configure: configure-stamp
@@ -42,7 +43,7 @@
 	dh_installdirs
 #	debian/credit-xlators > ${DOC}/TRANSLATORS
 	cp apache_template.conf ${INSTDIR}/apache_template
-	cp settings.php ${ptmp}/etc/$p/settings.php
+	cp settings.php ${SHRDIR}/settings.php
 	cp bootstrap.sql ${DBINSTDIR}/mysql
 	cp index.php ${WEBDOCDIR}
 

Modified: webapps-common/trunk/examples/webapp-apache-dbapp-example/index.php
===================================================================
--- webapps-common/trunk/examples/webapp-apache-dbapp-example/index.php	2007-06-22 16:02:19 UTC (rev 116)
+++ webapps-common/trunk/examples/webapp-apache-dbapp-example/index.php	2007-07-08 22:09:25 UTC (rev 117)
@@ -13,10 +13,18 @@
 // config file generated by dbc_generate_include setting in postinst
 require_once("/etc/webapp-apache-dbapp-example/settings.php");
 
+print "<p>X_DEBIAN_SITEID: " . apache_getenv("X_DEBIAN_SITEID") . "</p>";
+print "<p>X_DEBIAN_HOST: " . apache_getenv("X_DEBIAN_HOST") . "</p>";
+print "<p>X_DEBIAN_SUBDIR: " . apache_getenv("X_DEBIAN_SUBDIR") . "</p>";
+
+// let's pretend that this automatically generated config contains
+// some interesting settings in a $config array:
+global $config;
+
 // doing some random stuff to show it works :)
-$dbh = mysql_connect($dbserver, $dbuser, $dbpass);
+$dbh = mysql_connect($config['dbserver'], $config['dbuser'], $config['dbpass']);
 if (!$dbh) { die("couldn't connect to database server: " . mysql_error()); }
-$res = mysql_select_db($dbname);
+$res = mysql_select_db($config['dbname']);
 if(!$res) { die("couldn't connect to database: " . mysql_error()); }
 echo '<p>connected successfullyto database</p>';
 

Modified: webapps-common/trunk/examples/webapp-apache-dbapp-example/settings.php
===================================================================
--- webapps-common/trunk/examples/webapp-apache-dbapp-example/settings.php	2007-06-22 16:02:19 UTC (rev 116)
+++ webapps-common/trunk/examples/webapp-apache-dbapp-example/settings.php	2007-07-08 22:09:25 UTC (rev 117)
@@ -1,5 +1,22 @@
 <?php
 
-require_once "/etc/webapp-apache-dbapp-example/site-$_SERVER[X_DEBIAN_SITEID].php";
+// this is a sample settings file taht you might hack your package to use.
+// it can contain any kind of config options you'd normally put in a config
+// file, and can also be customized on a per-instance/per-configuration
+// basis by using some rather simple and intuitive template-based substitution.
 
+// for a full list of available substitutions, please consult the
+// webapps-common documentation.
+
+$config['hostname']="_WC_WEBSITE_HOSTNAME_";
+$config['subdir']="_WC_WEBSITE_SUBDIRECTORY_";
+
+// also, if you are using the integrated database configuration support,
+// you can reference the dbconfig-common parameter substitutions as well
+
+$config['dbuser']="_DBC_DBUSER_";
+$config['dbpass']="_DBC_DBPASS_";
+$config['dbname']="_DBC_DBNAME_";
+$config['dbserver']="_DBC_DBSERVER_";
+
 ?>

Modified: webapps-common/trunk/internal/httpd
===================================================================
--- webapps-common/trunk/internal/httpd	2007-06-22 16:02:19 UTC (rev 116)
+++ webapps-common/trunk/internal/httpd	2007-07-08 22:09:25 UTC (rev 117)
@@ -192,11 +192,11 @@
 	for httpd in $httpds; do
 		tmpfile=`_wc_mktmp`
 		chmod 644 $tmpfile
+		cp /etc/webapps-common/custom-templates/$httpd/virtualhost.conf $tmpfile
+		sed -i -e "s,_WC_VHOST_,$vhost,g" $tmpfile
+		sed -i -e "s,_WC_HTTPD_,apache2," $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
 			;;

Copied: webapps-common/trunk/templates/apache-global.conf (from rev 112, webapps-common/trunk/templates/apache2-wc-master.conf)
===================================================================
--- webapps-common/trunk/templates/apache-global.conf	                        (rev 0)
+++ webapps-common/trunk/templates/apache-global.conf	2007-07-08 22:09:25 UTC (rev 117)
@@ -0,0 +1,8 @@
+# global configuration file for webapps-common, HTTPD flavor.
+# this file is responsible for instructing HTTPD to load all
+# application configuration files for non-virtualhost configured
+# settings for packages configured via webapps-common.
+#
+# for virtualhost-specific app settings you should look in
+# /etc/webapps-common/apps-available/HTTPD/yourvhostname/*.conf
+Include /etc/webapps-common/apps-enabled/HTTPD/__global__/*.conf

Modified: webapps-common/trunk/templates/apache-virtualhost.conf
===================================================================
--- webapps-common/trunk/templates/apache-virtualhost.conf	2007-06-22 16:02:19 UTC (rev 116)
+++ webapps-common/trunk/templates/apache-virtualhost.conf	2007-07-08 22:09:25 UTC (rev 117)
@@ -1,5 +1,6 @@
 NameVirtualHost _WC_VHOST_
 <VirtualHost _WC_VHOST_>
 	ServerName _WC_VHOST_
+	SetEnv X_DEBIAN_HOST _WC_VHOST_
 	Include /etc/webapps-common/apps-enabled/_WC_HTTPD_/_WC_VHOST_/*.conf
 </VirtualHost>

Deleted: webapps-common/trunk/templates/apache2-wc-master.conf
===================================================================
--- webapps-common/trunk/templates/apache2-wc-master.conf	2007-06-22 16:02:19 UTC (rev 116)
+++ webapps-common/trunk/templates/apache2-wc-master.conf	2007-07-08 22:09:25 UTC (rev 117)
@@ -1,5 +0,0 @@
-# master configuration file for webapps-common, HTTPD flavor.
-# this file is responsible for instructing HTTPD to load all
-# application configuration files for packages configured via
-# webapps-common.
-Include /etc/webapps-common/apps-enabled/HTTPD/=global=/*.conf

Added: webapps-common/trunk/templates/appconfig.php
===================================================================
--- webapps-common/trunk/templates/appconfig.php	                        (rev 0)
+++ webapps-common/trunk/templates/appconfig.php	2007-07-08 22:09:25 UTC (rev 117)
@@ -0,0 +1,4 @@
+<?php
+// php-based configuration file for your web application
+ at require_once("CONFIGBASE-".apache_getenv("X_DEBIAN_SITEID")."CONFIGEXT");
+?>




More information about the Webapps-common-discuss mailing list