Oups, there was a missing return code.

This is the correct patch. Until next one ;-)

Regards,

Olivier.


Le vendredi 4 décembre 2009 15:58:57 Olivier LAHAYE, vous avez écrit :
> 
> Hi,
> 
> I've made some patch to oda so it doesn't start database multiple times in 
> multiple ways.
> 
> 1) Database.pm.svnpatch make start_database_service more robust and allows 
> different databases engin to be handeled.
>  for now, just a last small stuff needs  rework and configManager:read_config 
> does not collect DB_TYPE which contains mysql.
> 
> 2) bootstrap.pm.svnpatch from ODA. This patches cleans up the code, adds some 
> hardenning and removes a db daemon start that is useless.
> 
> 3) oda.svnpatch added code to remove mysql hardcodding.
> 
> 4) prepare_oda.svnpatch: cleanup and comments
> 
> 5) set_global_oscar_values.svnpatch: this patch can be ommitted. I did a 
> set_install_mode('systemimager-rsync',...) so that the database and the 
> system status reflects what the GUI displays at step 6.
> 
> Best regards,
> 
> Olivier.
> 
> 

-- 
        Olivier LAHAYE
        CEA Saclay
        DRT-LIST-DETECS-SSTM
Index: Database.pm
===================================================================
--- Database.pm	(révision 9116)
+++ Database.pm	(copie de travail)
@@ -78,6 +78,9 @@
 use OSCAR::ConfigManager;
 use OSCAR::ODA_Defs;
 use OSCAR::Utils;
+use OSCAR::SystemServices;
+use OSCAR::SystemServicesDefs;
+use OSCAR::OCA::OS_Settings;
 use Data::Dumper;
 
 # oda may or may not be installed and initialized
@@ -102,7 +105,6 @@
               database_connect
               database_disconnect
               start_database_service
-
               delete_package
               delete_node
               delete_group_packages
@@ -1354,7 +1356,7 @@
 }
 
 
-# Return: 1 if success, 0 else.
+# Return: 1 if success, 0 else. 
 # TODO: this function has to been extended for the case where we do not use a
 #       real db but configuration files.
 sub update_node ($$$$) {
@@ -2792,47 +2794,112 @@
 # Starts the appropriate database service.                                     #
 #                                                                              #
 # Input: None.                                                                 #
-# Return: None.                                                                #
+# Return: 0 if success, -1 else.                                               #
 ################################################################################
 sub start_database_service {
-    my $db_service_name = "";
-    my ($db_type, $chk) = split(':', $ENV{OSCAR_DB});
-    if( $db_type eq "mysql" || $db_type eq "" ){
-        # find the name of the mysql service and start the mysql server,
-        # and make sure it is run on every system reboot
-        my ($server_distrib, $server_distrib_version) = which_distro_server();
-        $db_service_name = which_mysql_name($server_distrib,
-                                            $server_distrib_version);
-    } elsif( $db_type eq "pgsql" ) {
-        $db_service_name = "postgresql";
+    # We get the configuration from the OSCAR configuration file.
+    my $oscar_configurator = OSCAR::ConfigManager->new();
+    if ( ! defined ($oscar_configurator) ) {
+        print "ERROR: [$0] start_database_service:Impossible to get the OSCAR configuration\n";
+        exit 1;
     }
+    my $config = $oscar_configurator->get_config();
+    # TODO: integrate DB_TYPE into config object.
+    # right now: $config->db_type = $config->get('ODA_TYPE');
+    # but there is no variable that stores $config->get('DB_TYPE');
+    # Thus we need some hardening here that could be avoided.
+    if ( !defined($config) ) {
+        carp "ERROR: [$0] Unable to read oscar.conf";
+        return -1;
+    }
 
-    my $command="/etc/init.d/$db_service_name status";
-    my @command_output = `$command`;
-    my $status = $?;
-    chomp @command_output;
-    if ( ! grep( /is\ running/, @command_output ) || ! $status ) {
-        print "Starting the $db_service_name database server ...\n";
-        my $command = "/etc/init.d/$db_service_name start";
-        print "$command\n";
-        if ( system( $command ) ) {
-        my @error_strings = ();
-        OSCAR::oda::oda_disconnect( \%options, undef );
-        warn shift @error_strings while @error_strings;
-        die "DB_DEBUG>$0:\n====> cannot start the $db_service_name database ".
-            "server!";
+    if ($config->{'db_type'} eq "file") { # test ODA_TYPE db|file
+        oscar_log_subsection (">$0: Not using a real database, connection done");
+        return 0;
+    }
+
+    # my $db_engine = $config->get('DB_TYPE'); # Does not work we realy need to have that
+                                               # into OSCAR::ConfigManager::load_oscar_config
+    # Let's harcode for the moment.
+    my $db_engine = "mysql"; # to be replaced by $db_engine = $config->{'db_engine'}
+
+    if ( !defined($db_engine) || ($db_engine eq "")) {
+        carp "ERROR: [$0] DB_TYPE not set in oscar.conf";
+        return -1;
+    }
+
+    if ($db_engine eq "file") { # test DB_TYPE=file
+        oscar_log_subsection (">$0: Not using a real database, connection done");
+        return 0;
+    }
+
+    # TODO: (OSCAR 6.2+) handle more logicaly DB_TYPE and ODA_TYPE.
+    # One variable to state if we're using files or daemon
+    # One variable to state the engine
+    # we could have: (file,db3) (file,access) (daemon,access) (daemon,mysql) (file,sqlite)...
+    # Better names would be: DB_TYPE=(file|daemon|plugin) DB_ENGINE=(mysq|pgsql|access|sqlite...)
+    if (defined ($db_engine) && ($db_engine ne "")) { # DB_TYPE=(mysql|pgsql|...)
+        my $db_daemon=OSCAR::OCA::OS_Settings::getitem($db_engine."_daemon");
+        if (defined($db_daemon) && ($db_daemon ne "")) {
+            # Enable database server start at each boot (Should not be here, but was in previous code...)
+            if (enable_system_services($db_daemon)) {
+                print "WARNING: [$0] start_database_service: Unable to enable ".$db_daemon." service at each boot.\n";
+                # It's not an dramatic error if we are still able to start the DB. (so no return)
+            }
+            # Start the database service.
+            if (system_service($db_engine, OSCAR::SystemServicesDefs::START())) { # Start the database daemon
+                carp "ERROR: [$0] start_database_service: Unable to start ".$db_daemon." service.";
+                return -1;
+            }
+        } else {
+            carp "ERROR: [$0] Unknown DB_TYPE=".$db_daemon."\n".
+                 "supported values are: mysql. (pgsql,sqlite,db,file,... not yet supported)";
+            return -1;
         }
-        sleep 2; # The database deamon may be starting in background. We wait
-                 # 2 seconds to make sure the deamon is up (do not ask me why
-                 # 2s and not more or less).
+    } else {
+        carp "ERROR: [$0] unsing ODA_TYPE=db, but DB_TYPE not set in oscar.conf (mysql, pgsql, ...)";
+        return -1;
     }
-    print "Making sure that the $db_service_name database server starts on ".   
-          "subsequent boots ...\n";
-    $command = "chkconfig $db_service_name on";
-    print "$command\n";
-    warn "DB_DEBUG>$0:\n====> WARNING: the $db_service_name database service ".
-         "may not start on subsequent reboots"
-        if system( $command );
+    return 0;
+
+#    my $db_service_name = "";
+#    my ($db_type, $chk) = split(':', $ENV{OSCAR_DB});
+#    if( $db_type eq "mysql" || $db_type eq "" ){
+#        # find the name of the mysql service and start the mysql server,
+#        # and make sure it is run on every system reboot
+#        my ($server_distrib, $server_distrib_version) = which_distro_server();
+#        $db_service_name = which_mysql_name($server_distrib,
+#                                            $server_distrib_version);
+#    } elsif( $db_type eq "pgsql" ) {
+#        $db_service_name = "postgresql";
+#    }
+#
+#    my $command="/etc/init.d/$db_service_name status";
+#    my @command_output = `$command`;
+#    my $status = $?;
+#    chomp @command_output;
+#    if ( ! grep( /is\ running/, @command_output ) || ! $status ) {
+#        print "Starting the $db_service_name database server ...\n";
+#        my $command = "/etc/init.d/$db_service_name start";
+#        print "$command\n";
+#        if ( system( $command ) ) {
+#        my @error_strings = ();
+#        OSCAR::oda::oda_disconnect( \%options, undef );
+#        warn shift @error_strings while @error_strings;
+#        die "DB_DEBUG>$0:\n====> cannot start the $db_service_name database ".
+#            "server!";
+#        }
+#        sleep 2; # The database deamon may be starting in background. We wait
+#                 # 2 seconds to make sure the deamon is up (do not ask me why
+#                 # 2s and not more or less).
+#    }
+#    print "Making sure that the $db_service_name database server starts on ".   
+#          "subsequent boots ...\n";
+#    $command = "chkconfig $db_service_name on";
+#    print "$command\n";
+#    warn "DB_DEBUG>$0:\n====> WARNING: the $db_service_name database service ".
+#         "may not start on subsequent reboots"
+#        if system( $command );
 }
 
 ################################################################################
@@ -2846,7 +2913,7 @@
 # Input: - options: reference to a hash representing the options.              #
 #        - error_strings: reference to an array representing the error strings #
 #                         (???).                                               #
-# Return: 0 if success, -1 else.                                               #
+# Return: 0 if success,                                                        #
 ################################################################################
 sub create_database_tables ($$) {
     my ($options, $error_strings) = @_;
@@ -2866,6 +2933,7 @@
               "((( All the OSCAR tables are created )))".
               "===========================\n"
             if $options{debug} || $options{verbose};
+        return 0;
     }
 }
 
------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing. 
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
Oscar-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/oscar-devel

Reply via email to