[Bps-public-commit] r16289 - in Pushmi/trunk: . Pushmi-Admin/etc Pushmi-Admin/lib/Pushmi/Admin Pushmi-Admin/lib/Pushmi/Admin/Action

alexmv at bestpractical.com alexmv at bestpractical.com
Tue Oct 14 17:13:33 EDT 2008


Author: alexmv
Date: Tue Oct 14 17:13:29 2008
New Revision: 16289

Added:
   Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Action/Configure.pm
Modified:
   Pushmi/trunk/   (props changed)
   Pushmi/trunk/Pushmi-Admin/etc/config.yml
   Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin.pm
   Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Dispatcher.pm
   Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/View.pm

Log:
 r38186 at kohr-ah:  chmrr | 2008-10-14 17:13:22 -0400
  * Add rules for configuration on first run


Modified: Pushmi/trunk/Pushmi-Admin/etc/config.yml
==============================================================================
--- Pushmi/trunk/Pushmi-Admin/etc/config.yml	(original)
+++ Pushmi/trunk/Pushmi-Admin/etc/config.yml	Tue Oct 14 17:13:29 2008
@@ -59,6 +59,8 @@
   time_zone: EST
   data_root: %var/data%
   pushmi_bin: /usr/bin/pushmi
+  configured: ~
+  htpasswd: ~
   apache:
     root: http://localhost/
     document_root: ~

Modified: Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin.pm
==============================================================================
--- Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin.pm	(original)
+++ Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin.pm	Tue Oct 14 17:13:29 2008
@@ -6,12 +6,33 @@
 use SVK::Util 'str2time';
 use File::Copy qw//;
 
+# Reload configuration files when they're changed -- but do it in the
+# parent process, before the fork, so it happens only once per change.
+sub Jifty::Server::Fork::NetServer::pre_fork_hook {
+    my @files = grep {defined and -e $_} (
+        $ENV{'JIFTY_CONFIG'} || Jifty::Util->app_root . '/etc/config.yml',
+        Jifty::Util->absolute_path(
+            Jifty->config->framework('VendorConfig') || $ENV{'JIFTY_VENDOR_CONFIG'}
+        ),
+        Jifty::Util->absolute_path(
+            Jifty->config->framework('SiteConfig') || $ENV{'JIFTY_SITE_CONFIG'}
+        ),
+    );
+    if (grep {(stat($_))[9] > Jifty->config->{load}} @files) {
+        Jifty->config(Jifty::Config->new);
+        Jifty->config->{load} = time;
+    }
+}
+
 sub start {
     my $class = shift;
     Jifty->web->add_javascript(qw(
         jquery.progressbar.js
         pushmi_progress.js
     ));
+
+    # Grab the load time for later use
+    Jifty->config->{load} = time;
 }
 
 sub svn_auth_open {
@@ -19,7 +40,6 @@
     my ($url, $user, $password) = @_;
     my $auth = sub {
         my ($cred) = @_;
-        warn "Doing >$user<  >$password<  $url auth\n";
         $cred->username($user);
         $cred->password($password);
         $cred->may_save(0);

Added: Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Action/Configure.pm
==============================================================================
--- (empty file)
+++ Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Action/Configure.pm	Tue Oct 14 17:13:29 2008
@@ -0,0 +1,66 @@
+use strict;
+use warnings;
+
+=head1 NAME
+
+Pushmi::Admin::Action::Configure
+
+=cut
+
+package Pushmi::Admin::Action::Configure;
+use base qw/Pushmi::Admin::Action Jifty::Action/;
+
+use Jifty::Param::Schema;
+use Jifty::Action schema {
+
+    param hostname =>
+        type is 'text',
+        default is lazy {
+            URI->new(Jifty->config->framework('Web')->{BaseURL})->host
+        };
+
+    param password =>
+        type is 'text',
+        render as 'password';
+
+};
+
+sub take_action {
+    my $self = shift;
+
+    # Update hostnames in SiteConfig file
+    my $sitepath = Jifty::Util->absolute_path(
+        Jifty->config->framework('SiteConfig') );
+
+    my $site = Jifty->config->load_file( $sitepath );
+    $site->{framework}{Web}{BaseURL}   = $self->update_host(
+        $site->{framework}{Web}{BaseURL},
+        $self->argument_value("hostname")
+    );
+    $site->{application}{apache}{root} = $self->update_host(
+        $site->{application}{apache}{root},
+        $self->argument_value("hostname")
+    );
+
+    Jifty::YAML::DumpFile( $sitepath, $site )
+          or $self->result->error("Can't write site configuration $sitepath: $!");
+
+    Jifty->config(Jifty::Config->new); # Reload the config;
+
+    # Write a new .htpasswd if we know where it lives
+    if ($self->argument_value("password") and Jifty->config->app("htpasswd")) {
+        my @htpasswd = Jifty->config->app("htpasswd");
+        @htpasswd = @{$htpasswd[0]} if ref $htpasswd[0] and @htpasswd == 1;
+        system(@htpasswd, $self->argument_value("password"));
+    }
+}
+
+sub update_host {
+    my $self = shift;
+    my ($uri, $newhost) = @_;
+    $uri = URI->new($uri);
+    $uri->host($newhost);
+    return $uri->canonical->as_string;
+}
+
+1;

Modified: Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Dispatcher.pm
==============================================================================
--- Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Dispatcher.pm	(original)
+++ Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Dispatcher.pm	Tue Oct 14 17:13:29 2008
@@ -4,19 +4,42 @@
 package Pushmi::Admin::Dispatcher;
 use Jifty::Dispatcher -base;
 
-before qr{^/(?!static|errors|__jifty|=|favicon.ico|firstrun)(/|$)} => run {
+before qr{^/(?!static|errors|__jifty|=|favicon.ico)(/|$)} => run {
     # Check that we have a running memcached, or things get sad
     my $memcached = $Jifty::DBI::Record::Memcached::MEMCACHED;
     redirect '/errors/memcached' unless $memcached->get_sock("");
+};
+
+
+# Navigation
+before '**' => set 'navigation' => ['home'];
+before qr{/(index.html)?$} => set 'navigation' => [];
+
 
+# First run configuration
+before qr{^/(?!static|errors|__jifty|=|favicon.ico|firstrun)(/|$)} => run {
     # Check that we have a hostname and password
     my $root = URI->new(Jifty->config->app('apache')->{root});
     redirect "/firstrun" if $root->host eq "localhost";
 };
-
-# Navigation
-before '**' => set 'navigation' => ['home'];
-before qr{/(index.html|firstrun)?$} => set 'navigation' => [];
+on '/firstrun' => run {
+    set navigation => [];
+    my $root = URI->new(Jifty->config->app('apache')->{root});
+    return if $root->host eq "localhost";
+    # If we're configured now, redirect to the internal URL
+    redirect Jifty->web->url;
+}
+after '/firstrun' => run {
+    my $root = URI->new(Jifty->config->app('apache')->{root});
+    return if $root->host eq "localhost";
+    return unless Jifty->config->app('configured');
+    return unless -x Jifty->config->app('configured');
+    # Once we're configured, call the configuration executable
+    warn "Going to run 'configured' callback: ".Jifty->config->app('configured');
+    if (fork) {
+        exec(Jifty->config->app('configured')) or die "Configured call failed: $@";
+    }
+}
 
 # Redirect to the created replica
 on '/created' => run {

Modified: Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/View.pm
==============================================================================
--- Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/View.pm	(original)
+++ Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/View.pm	Tue Oct 14 17:13:29 2008
@@ -529,6 +529,30 @@
     div {
         { class is "roundbox" };
         h2 { "Pushmi configuration!" };
+
+        form {
+            p {
+                "There are a couple things we need to set up before your Pushmi "
+                    . "server will be all set.  First, we need to know the full "
+                    . "hostname that you use to access this machine, so we can "
+                    . "correctly construct links to it:"
+            };
+            my $conf = Jifty->web->new_action(
+                class   => "Configure",
+                moniker => "config",
+            );
+            render_param( $conf => "hostname" );
+
+            if (Jifty->config->app('htpasswd')) {
+                p {
+                    "You should also set a password to protect the administrative "
+                  . "interface:"
+                };
+                render_param( $conf => "password" );
+            }
+
+            form_submit( label => "Save" );
+        }
     }
 };
 



More information about the Bps-public-commit mailing list