From d35688296af64ca2627c3a90cfa920242dfcdae6 Mon Sep 17 00:00:00 2001 From: erickson Date: Wed, 16 Feb 2005 17:15:23 +0000 Subject: [PATCH] moved to new config settings git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@65 9efc2488-bf62-4759-914b-345cdb29e865 --- src/perlmods/OpenSRF/System.pm | 183 ++++++++++++++++++++++----------- 1 file changed, 122 insertions(+), 61 deletions(-) diff --git a/src/perlmods/OpenSRF/System.pm b/src/perlmods/OpenSRF/System.pm index 452c5fe..7015428 100644 --- a/src/perlmods/OpenSRF/System.pm +++ b/src/perlmods/OpenSRF/System.pm @@ -11,8 +11,16 @@ use OpenSRF::DOM; use OpenSRF::EX qw/:try/; use POSIX ":sys_wait_h"; use OpenSRF::Utils::Config; +use OpenSRF::Utils::SettingsParser; +use OpenSRF::Utils::SettingsClient; use strict; +my $bootstrap_config_file; +sub import { + my( $self, $config ) = @_; + $bootstrap_config_file = $config; +} + =head2 Name/Description OpenSRF::System @@ -38,8 +46,6 @@ returned on subsequent calls to new(). $| = 1; -sub APPS { return qw( opac ); } #circ cat storage ); } - sub DESTROY {} # ---------------------------------------------- @@ -48,38 +54,8 @@ $SIG{INT} = sub { instance()->killall(); }; $SIG{HUP} = sub{ instance()->hupall(); }; -$SIG{CHLD} = \&process_automation; - - -# Go ahead and set the config - -set_config(); - -# ---------------------------------------------- -# Set config options -sub set_config { - - my $config = OpenSRF::Utils::Config->load( - config_file => "/pines/conf/opensrf.conf" ); - - if( ! $config ) { throw OpenSRF::EX::Config "System could not load config"; } - - my $tran = $config->transport->implementation; - - eval "use $tran;"; - if( $@ ) { - throw OpenSRF::EX::PANIC ("Cannot find transport implementation: $@" ); - } - - OpenSRF::Transport->message_envelope( $tran->get_msg_envelope ); - OpenSRF::Transport::PeerHandle->set_peer_client( $tran->get_peer_client ); - OpenSRF::Transport::Listener->set_listener( $tran->get_listener ); - - -} - +#$SIG{CHLD} = \&process_automation; -# ---------------------------------------------- { # --- @@ -107,7 +83,7 @@ sub set_config { sub _unixserver { my( $app ) = @_; - return "OpenSRF::UnixServer->new( '$app' )->serve()"; + return "OpenSRF::UnixServer->new( '$app')->serve()"; } sub _listener { @@ -115,22 +91,75 @@ sub _listener { return "OpenSRF::Transport::Listener->new( '$app' )->initialize()->listen()"; } -#sub _shell { return "OpenSRF::Shell->listen()"; } - # ---------------------------------------------- # Boot up the system +sub load_bootstrap_config { + + if(OpenSRF::Utils::Config->current) { + return; + } + + warn "Loading $bootstrap_config_file\n"; + if(!$bootstrap_config_file) { + die "Please provide a bootstrap config file to OpenSRF::System!\n" . + "use OpenSRF::System qw(/path/to/bootstrap_config);"; + } + + OpenSRF::Utils::Config->load( config_file => $bootstrap_config_file ); + + OpenSRF::Transport->message_envelope( "OpenSRF::Transport::SlimJabber::MessageWrapper" ); + OpenSRF::Transport::PeerHandle->set_peer_client( "OpenSRF::Transport::SlimJabber::PeerConnection" ); + OpenSRF::Transport::Listener->set_listener( "OpenSRF::Transport::SlimJabber::Inbound" ); +} + sub bootstrap { my $self = __PACKAGE__->instance(); + load_bootstrap_config(); + OpenSRF::Utils::Logger::set_config(); + my $bsconfig = OpenSRF::Utils::Config->current; - my $config = OpenSRF::Utils::Config->current; + # Start a process group and make me the captain + setpgrp( 0, 0 ); + $0 = "System"; - my $apps = $config->system->apps; - my $server_type = $config->system->server_type; + # ----------------------------------------------- + # Launch the settings sever if necessary... + my $are_settings_server = 0; + if( (my $cfile = $bsconfig->bootstrap->settings_config) ) { + my $parser = OpenSRF::Utils::SettingsParser->new(); + + # since we're (probably) the settings server, we can go ahead and load the real config file + $parser->initialize( $cfile ); + $OpenSRF::Utils::SettingsClient::host_config = + $parser->get_server_config($bsconfig->env->hostname); + + my $client = OpenSRF::Utils::SettingsClient->new(); + my $apps = $client->config_value("activeapps", "appname"); + if(!ref($apps) eq "ARRAY") { $apps = [$apps]; } + + for my $app (@$apps) { + # verify we are a settings server and launch + if( $app eq "settings" ) { + $are_settings_server = 1; + $self->launch_settings(); + sleep 1; + $self->launch_settings_listener(); + last; + } + } + } + + # Launch everything else + my $client = OpenSRF::Utils::SettingsClient->new(); + my $apps = $client->config_value("activeapps", "appname" ); + if(!ref($apps)) { $apps = [$apps]; } + my $server_type = $client->config_value("server_type"); $server_type ||= "basic"; + if( $server_type eq "prefork" ) { $server_type = "Net::Server::PreFork"; } else { @@ -148,11 +177,6 @@ sub bootstrap { push @OpenSRF::UnixServer::ISA, $server_type; _log( " * System boostrap" ); - - # Start a process group and make me the captain - setpgrp( 0, 0 ); - - $0 = "System"; # --- Boot the Unix servers $self->launch_unix($apps); @@ -164,25 +188,13 @@ sub bootstrap { _sleep(); - # --- Start the system shell -#if ($config->system->shell) { -# eval " -# use OpenSRF::Shell; -# $self->launch_shell() if ($config->system->shell); -# "; -# -# if ($@) { -# warn "ARRRGGG! Can't start the shell..."; -# } -# } - - # --- Now we wait for our brood to perish _log( " * System is ready..." ); + while( 1 ) { sleep; } exit; } - - + + # ---------------------------------------------- # Bootstraps a single client connection. @@ -190,7 +202,8 @@ sub bootstrap { sub bootstrap_client { my $self = __PACKAGE__->instance(); - my $config = OpenSRF::Utils::Config->current; + load_bootstrap_config(); + OpenSRF::Utils::Logger::set_config(); my $client_type = shift; my $app; @@ -244,6 +257,50 @@ sub process_automation { } + +sub launch_settings { + + # XXX the $self like this and pid automation will not work with this setup.... + my($self) = @_; + use Net::Server::Single; + @OpenSRF::UnixServer::ISA = qw(OpenSRF Net::Server::Single); + + my $pid = OpenSRF::Utils::safe_fork(); + if( $pid ) { + $self->pid_hash( $pid , "launch_settings()" ); + } + else { + my $apname = "settings"; + $apname =~ tr/[a-z]/[A-Z]/; + $0 = "OpenSRF App ($apname)"; + eval _unixserver( "settings" ); + if($@) { die "$@\n"; } + exit; + } + + @OpenSRF::UnixServer::ISA = qw(OpenSRF); + +} + + +sub launch_settings_listener { + + my $self = shift; + my $app = "settings"; + my $pid = OpenSRF::Utils::safe_fork(); + if ( $pid ) { + $self->pid_hash( $pid , _listener( $app ) ); + } + else { + my $apname = $app; + $apname =~ tr/[a-z]/[A-Z]/; + $0 = "Listener ($apname)"; + eval _listener( $app ); + exit; + } + +} + # ---------------------------------------------- # Launch the Unix Servers @@ -252,6 +309,8 @@ sub launch_unix { foreach my $app ( @$apps ) { + if( $app eq "settings" ) { next; } + _log( " * Starting UnixServer for $app..." ); my $pid = OpenSRF::Utils::safe_fork(); @@ -277,6 +336,8 @@ sub launch_listener { foreach my $app ( @$apps ) { + if( $app eq "settings" ) { next; } + _log( " * Starting Listener for $app..." ); my $pid = OpenSRF::Utils::safe_fork(); @@ -355,7 +416,7 @@ sub hupall { sub _log { my $string = shift; - OpenSRF::Utils::Logger->debug( $string, DEBUG ); + OpenSRF::Utils::Logger->debug( $string, INFO ); print $string . "\n"; } -- 2.43.2