Author: sandervanderburg
Date: Mon Dec 20 12:00:28 2010
New Revision: 25207
URL: https://svn.nixos.org/websvn/nix/?rev=25207&sc=1

Log:
Added postgresql-database type

Added:
   
disnix/disnix-activation-scripts/trunk/activation-scripts/postgresql-database.in
   
disnix/disnix-activation-scripts/trunk/tests/deployment/postgresql-database.nix
Modified:
   disnix/disnix-activation-scripts/trunk/activation-scripts/Makefile.am
   disnix/disnix-activation-scripts/trunk/configure.ac
   disnix/disnix-activation-scripts/trunk/release.nix

Modified: disnix/disnix-activation-scripts/trunk/activation-scripts/Makefile.am
==============================================================================
--- disnix/disnix-activation-scripts/trunk/activation-scripts/Makefile.am       
Mon Dec 20 10:32:22 2010        (r25206)
+++ disnix/disnix-activation-scripts/trunk/activation-scripts/Makefile.am       
Mon Dec 20 12:00:28 2010        (r25207)
@@ -16,6 +16,10 @@
     mysql_database = mysql-database
 endif
 
+if have_postgresql
+    postgresql_database = postgresql-database
+endif
+
 if have_tomcat
     tomcat_webapplication = tomcat-webapplication
 endif
@@ -23,6 +27,6 @@
 
 # Build settings
 
-libexec_SCRIPTS = echo process nixos-configuration wrapper 
$(apache_webapplication) $(axis2_webservice) $(ejabberd_dump) $(mysql_database) 
$(tomcat_webapplication)
+libexec_SCRIPTS = echo process nixos-configuration wrapper 
$(apache_webapplication) $(axis2_webservice) $(ejabberd_dump) $(mysql_database) 
$(tomcat_webapplication) $(postgresql_database)
 
-EXTRA_DIST = apache-webapplication axis2-webservice.in echo ejabberd-dump.in 
mysql-database.in process nixos-configuration tomcat-webapplication.in wrapper
+EXTRA_DIST = apache-webapplication axis2-webservice.in echo ejabberd-dump.in 
mysql-database.in process nixos-configuration tomcat-webapplication.in wrapper 
postgresql-database.in

Added: 
disnix/disnix-activation-scripts/trunk/activation-scripts/postgresql-database.in
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ 
disnix/disnix-activation-scripts/trunk/activation-scripts/postgresql-database.in
    Mon Dec 20 12:00:28 2010        (r25207)
@@ -0,0 +1,20 @@
+#!/bin/bash -e
+
+case "$1" in
+    activate)
+       # Initalize the given schema if the database does not exists
+       componentName=`basename $2`
+       dbName=${componentName:33}
+       
+       if [ "$(@psql@ -l | grep -x $dbName)" = "" ]
+       then
+           su $postgresqlUsername -c "@createdb@ $dbName"
+           su $postgresqlUsername -c "psql --file 
$2/postgresql-databases/*.sql $dbName"
+       fi
+        ;;
+    deactivate)
+       # A PostgreSQL database cannot be deactivated, we do not want to drop a 
database
+       # with all data in it, right?
+       echo
+       ;;
+esac

Modified: disnix/disnix-activation-scripts/trunk/configure.ac
==============================================================================
--- disnix/disnix-activation-scripts/trunk/configure.ac Mon Dec 20 10:32:22 
2010        (r25206)
+++ disnix/disnix-activation-scripts/trunk/configure.ac Mon Dec 20 12:00:28 
2010        (r25207)
@@ -12,6 +12,7 @@
 AC_ARG_WITH([axis2], AS_HELP_STRING([--with-axis2], [Enable Apache Axis2 
activation script. Also requires Tomcat enabled]))
 AC_ARG_WITH([ejabberd], AS_HELP_STRING([--without-ejabberd], [Ignore presence 
of ejabberd and disable it]))
 AC_ARG_WITH([mysql], AS_HELP_STRING([--without-mysql], [Ignore presence of 
MySQL and disable it]))
+AC_ARG_WITH([postgresql], AS_HELP_STRING([--without-postgresql], [Ignore 
presence of PostgreSQL and disable it]))
 AC_ARG_WITH([tomcat], AS_HELP_STRING([--with-tomcat], [Enable Apache Tomcat 
activation script and specifies location of the Apache Tomcat base directory]))
 
 # Define environment variable options
@@ -34,6 +35,12 @@
 AS_IF([test "x$with_mysql" != "xno"],
       [AC_PATH_PROG(mysql, mysql)])
 
+AS_IF([test "x$with_postgresql" != "xno"],
+      [AC_PATH_PROG(createdb, createdb)])
+
+AS_IF([test "x$with_postgresql" != "xno"],
+      [AC_PATH_PROG(psql, psql)])
+
 AS_IF([test "x$with_tomcat" != "x" && test "x$with_tomcat" != "xno" || test 
"x$CATALINA_HOME" != "x"],
       [have_tomcat=yes],
       [have_tomcat=no])
@@ -43,6 +50,7 @@
 AM_CONDITIONAL(have_axis2, [test x$have_axis2 != "xno"])
 AM_CONDITIONAL(have_ejabberd, [test x$ejabberdctl != "x"])
 AM_CONDITIONAL(have_mysql, [test x$mysql != "x"])
+AM_CONDITIONAL(have_postgresql, [test x$psql != "x"])
 AM_CONDITIONAL(have_tomcat, [test x$have_tomcat != "xno"])
 
 # CATALINA_BASE setting
@@ -61,6 +69,9 @@
 AS_IF([test "x$mysql" != "x"],
       [mysql_database=activation-scripts/mysql-database])
 
+AS_IF([test "x$psql" != "x"],
+      [postgresql_database=activation-scripts/postgresql-database])
+
 AS_IF([test "x$ejabberdctl" != "x"],
       [ejabberd_dump=activation-scripts/ejabberd-dump])
 
@@ -73,6 +84,7 @@
 $axis2_webservice
 $ejabberd_dump
 $mysql_database
+$postgresql_database
 $tomcat_webapplication
 ])
 AC_OUTPUT

Modified: disnix/disnix-activation-scripts/trunk/release.nix
==============================================================================
--- disnix/disnix-activation-scripts/trunk/release.nix  Mon Dec 20 10:32:22 
2010        (r25206)
+++ disnix/disnix-activation-scripts/trunk/release.nix  Mon Dec 20 12:00:28 
2010        (r25207)
@@ -25,6 +25,7 @@
       , enableAxis2WebService ? false
       , enableEjabberdDump ? false
       , enableMySQLDatabase ? false
+      , enablePostgreSQLDatabase ? false
       , enableTomcatWebApplication ? false
       , catalinaBaseDir ? "/var/tomcat"
       }:
@@ -46,12 +47,14 @@
            ${if enableAxis2WebService then "--with-axis2" else 
"--without-axis2"}
            ${if enableEjabberdDump then "--with-ejabberd" else 
"--without-ejabberd"}
            ${if enableMySQLDatabase then "--with-mysql" else "--without-mysql"}
+           ${if enablePostgreSQLDatabase then "--with-postgresql" else 
"--without-postgresql"}
            ${if enableTomcatWebApplication then 
"--with-tomcat=${catalinaBaseDir}" else "--without-tomcat"}
          '';
 
         buildInputs = []
                      ++ stdenv.lib.optional enableEjabberdDump ejabberd
-                     ++ stdenv.lib.optional enableMySQLDatabase mysql;
+                     ++ stdenv.lib.optional enableMySQLDatabase mysql
+                     ++ stdenv.lib.optional enablePostgreSQLDatabase 
postgresql;
       };
       
       tests = 
@@ -66,12 +69,17 @@
            enableAxis2WebService = true;
            enableEjabberdDump = true;
            enableMySQLDatabase = true;
+           enablePostgreSQLDatabase = true;
            enableTomcatWebApplication = true;
          };
          
          # Test services
          
-         testdb = import ./tests/deployment/mysql-database.nix {
+         mysql_database = import ./tests/deployment/mysql-database.nix {
+           inherit stdenv;
+         };
+         
+         postgresql_database = import 
./tests/deployment/postgresql-database.nix {
            inherit stdenv;
          };
          
@@ -112,6 +120,9 @@
                  enable = true;
                  rootPassword = pkgs.writeTextFile { name = "mysqlpw"; text = 
"verysecret"; };
                };
+               services.postgresql = {
+                 enable = true;
+               };
                services.ejabberd.enable = true;
                services.httpd = {
                  enable = true;
@@ -150,8 +161,10 @@
                # stopped. This test should succeed.
                
                
$machine->mustSucceed("${disnix_activation_scripts}/libexec/disnix/activation-scripts/process
 activate ${process}");
+               $machine->mustSucceed("sleep 5");
                $machine->mustSucceed("[ \"\$(pgrep -f ${process}/bin/loop)\" 
!= \"\" ]");
                
$machine->mustSucceed("${disnix_activation_scripts}/libexec/disnix/activation-scripts/process
 deactivate ${process}");
+               $machine->mustSucceed("sleep 5");
                $machine->mustSucceed("[ \"\$(pgrep -f ${process}/bin/loop)\" = 
\"\" ]");
                
                # Test Apache web application script. Here, we activate a small
@@ -170,7 +183,7 @@
                # we check whether it is created. This test should succeed.
                
                $machine->waitForJob("mysql");
-               $machine->mustSucceed("mysqlUsername=root 
mysqlPassword=verysecret 
${disnix_activation_scripts}/libexec/disnix/activation-scripts/mysql-database 
activate ${testdb}");
+               $machine->mustSucceed("mysqlUsername=root 
mysqlPassword=verysecret 
${disnix_activation_scripts}/libexec/disnix/activation-scripts/mysql-database 
activate ${mysql_database}");
                my $result = $machine->mustSucceed("echo 'select * from test' | 
mysql --user=root --password=verysecret -N testdb");
                
                if($result =~ /Hello world/) {
@@ -179,8 +192,23 @@
                    die "MySQL table should contain: Hello world!\n";
                }
                
-               $machine->mustSucceed("mysqlUsername=root 
mysqlPassword=verysecret 
${disnix_activation_scripts}/libexec/disnix/activation-scripts/mysql-database 
deactivate ${testdb}");
-                               
+               $machine->mustSucceed("mysqlUsername=root 
mysqlPassword=verysecret 
${disnix_activation_scripts}/libexec/disnix/activation-scripts/mysql-database 
deactivate ${mysql_database}");
+               
+               # Test PostgreSQL activation script. Here we activate a database
+               # and we check whether it is created. This test should succeed.
+               
+               $machine->waitForJob("postgresql");
+               $machine->mustSucceed("postgresqlUsername=root 
${disnix_activation_scripts}/libexec/disnix/activation-scripts/postgresql-database
 activate ${postgresql_database}");
+               my $result = $machine->mustSucceed("echo 'select * from test' | 
psql --file - testdb");         
+               
+               if($result =~ /Hello world/) {
+                   print "PostgreSQL query returns: Hello world!\n";
+               } else {
+                   die "PostgreSQL table should contain: Hello world!\n";
+               }
+               
+               $machine->mustSucceed("postgresqlUsername=root 
${disnix_activation_scripts}/libexec/disnix/activation-scripts/postgresql-database
 deactivate ${postgresql_database}");
+               
                # Test Tomcat web application script. Deploys a tomcat web
                # application, verifies whether it can be accessed and then
                # undeploys it again and checks whether it becomes inaccessible.

Added: 
disnix/disnix-activation-scripts/trunk/tests/deployment/postgresql-database.nix
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ 
disnix/disnix-activation-scripts/trunk/tests/deployment/postgresql-database.nix 
    Mon Dec 20 12:00:28 2010        (r25207)
@@ -0,0 +1,11 @@
+{stdenv}:
+
+stdenv.mkDerivation {
+  name = "testdb";
+  src = ../services/mysql-database;
+  buildCommand =
+  ''
+    ensureDir $out/postgresql-databases
+    cp $src/*.sql $out/postgresql-databases
+  '';
+}
_______________________________________________
nix-commits mailing list
[email protected]
http://mail.cs.uu.nl/mailman/listinfo/nix-commits

Reply via email to