Changeset 238

Show
Ignore:
Timestamp:
04/16/07 12:34:00 (2 years ago)
Author:
ludo
Message:

do not sleep between retries: reschedule (from r4250)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/webmin/lsc/debian/changelog

    r229 r238  
    1 webmin-lsc (1.0.4) stable; urgency=low 
     1webmin-lsc (1.0.5) stable; urgency=low 
    22 
    33  * See SVN history 
  • trunk/webmin/lsc/include/command_launcher.inc.php

    r229 r238  
    563563                                        return 0; 
    564564                                } 
     565                                 
     566                                /* Check if next_attempt is not properly initialized (pre 1.0.3 transition) */ 
     567                                if ($this->command_on_host->next_launch_date == "0000-00-00 00:00:00" && 
     568                                    $this->command_on_host->start_date != "0000-00-00 00:00:00" ) { 
     569                                 
     570                                        lsc_command_on_host_set_next_launch_date($this->id_command_on_host, $this->command_on_host->start_date); 
     571                                        return(0); 
     572                                } 
     573                                 
    565574                                $this->session = new LSC_Session($mac, $this->command->username); 
    566575                                         
     
    577586                                                ); 
    578587                                                return 0; 
    579                                         } else { 
    580                                                 lsc_command_on_host_set_current_state( 
    581                                                         $this->id_command_on_host, 
    582                                                         "not_reachable" 
    583                                                 ); 
    584                                                 lsc_command_history_append( 
    585                                                         $this->id_command_on_host, 
    586                                                         date("Y-m-d H:i:s"), 
    587                                                         "not_reachable", 
    588                                                         $this->session->ssh_stderr, 
    589                                                         $this->session->msgerror 
    590                                                 ); 
    591                                                 return -1; 
    592588                                        } 
    593589                                } else { 
    594590                                        /* 
    595                                          * Wake on lan and retry 
     591                                         * Ping error: Wake on lan and retry 
    596592                                         */ 
    597593                                        if ($this->command->wake_on_lan_enable) { 
     
    611607                                                } 
    612608                                        } 
    613                                         /* 
    614                                          * Connection error ... 
    615                                          */ 
    616                                          
    617                                         lsc_command_on_host_set_current_state( 
    618                                                 $this->id_command_on_host, 
    619                                                 "not_reachable" 
    620                                         ); 
    621                                         lsc_command_history_append( 
    622                                                 $this->id_command_on_host, 
    623                                                 date("Y-m-d H:i:s"), 
    624                                                 "not_reachable", 
    625                                                 "", 
    626                                                 $this->session->msgerror 
    627                                         ); 
    628                  
    629                                         lsc_command_on_host_set_remains_connection_attempt( 
    630                                                 $this->id_command_on_host,  
    631                                                 --$remains_connection_attempt 
    632                                         ); 
    633                  
    634                                         lsc_command_on_host_set_next_attempt_date_time( 
    635                                                 $this->id_command_on_host, 
    636                                                 time() + ($this->command->next_connection_delay * 60) 
    637                                         ); 
    638                                          
    639                                         if ($remains_connection_attempt <= 0) return -1; 
    640                                          
    641                                         sleep($this->command->next_connection_delay * 60); 
    642                                 } 
     609                                } 
     610                                 
     611                                /* 
     612                                 * Connection error ... 
     613                                 */ 
     614 
     615                                lsc_command_on_host_set_current_state( 
     616                                        $this->id_command_on_host, 
     617                                        "not_reachable" 
     618                                ); 
     619                                lsc_command_history_append( 
     620                                        $this->id_command_on_host, 
     621                                        date("Y-m-d H:i:s"), 
     622                                        "not_reachable", 
     623                                        $this->session->ssh_stderr, 
     624                                        $this->session->msgerror 
     625                                ); 
     626 
     627                                /* decrement connection attempts */ 
     628                                lsc_command_on_host_set_remains_connection_attempt( 
     629                                        $this->id_command_on_host,  
     630                                        --$remains_connection_attempt 
     631                                ); 
     632                                 
     633                                /* re-schedule */ 
     634                                if ($this->command_on_host->next_launch_date == "0000-00-00 00:00:00") { 
     635                                        lsc_command_on_host_set_next_launch_date($this->id_command_on_host, date("Y-m-d H:i:s")); 
     636                                } 
     637 
     638                                lsc_command_on_host_adjust_next_launch_date( 
     639                                        $this->id_command_on_host, 
     640                                        "+ interval ".$this->command->next_connection_delay." minute" 
     641                                ); 
     642 
     643                                return -1;                                       
     644                                 
    643645                        } 
    644646                        return -1; 
  • trunk/webmin/lsc/include/commands.inc.php

    r229 r238  
    386386                                        $new_command_on_host->start_date = $this->start_date; 
    387387                                        $new_command_on_host->end_date = $this->end_date; 
     388                                        $new_command_on_host->next_launch_date = $this->start_date; 
    388389 
    389390                                        // Initialise field 
     
    394395                                        $new_command_on_host->current_pid = -1; 
    395396 
    396                                         $new_command_on_host->next_launch_date = "0000-00-00 00:00:00"; 
    397397                                         
    398398                                        $new_command_on_host->number_attempt_connection_remains = $this->max_connection_attempt; 
  • trunk/webmin/lsc/include/commands_on_host.inc.php

    r229 r238  
    378378                        $this->executed = $database->f("executed"); 
    379379                        $this->deleted = $database->f("deleted"); 
    380  
    381380                        $this->next_launch_date = $database->f("next_launch_date"); 
     381                         
    382382                } else if ($database->num_rows() == 0) { 
    383383                        return -1; 
     
    659659} 
    660660 
     661/** 
     662 * Set next launch date 
     663 * 
     664 * @param $id_command_on_host 
     665 * @param new next attempt date time value 
     666 * 
     667 */ 
     668function lsc_command_on_host_set_next_launch_date($id_command_on_host, $new_date_time) 
     669{ 
     670        global $database, $DEBUG; 
     671 
     672        if (!isset($database)) { 
     673                $database = new LSC_DB(); 
     674                if ($DEBUG >= 1) $database->Debug = true; 
     675        } 
     676 
     677        $query = sprintf( 
     678" 
     679        UPDATE 
     680                %s 
     681        SET 
     682                next_launch_date = '%s' 
     683        WHERE 
     684                id_command_on_host = \"%s\" 
     685", 
     686                COMMANDS_ON_HOST_TABLE, 
     687                $new_date_time, 
     688                $id_command_on_host 
     689        ); 
     690         
     691        $database->query($query); 
     692} 
     693 
     694/** 
     695 * Adjust next launch date 
     696 * 
     697 * @param $id_command_on_host 
     698 * @param new next attempt date time value 
     699 * 
     700 */ 
     701function lsc_command_on_host_adjust_next_launch_date($id_command_on_host, $new_date_time) 
     702{ 
     703        global $database, $DEBUG; 
     704 
     705        if (!isset($database)) { 
     706                $database = new LSC_DB(); 
     707                if ($DEBUG >= 1) $database->Debug = true; 
     708        } 
     709 
     710        $query = sprintf( 
     711" 
     712        UPDATE 
     713                %s 
     714        SET 
     715                next_launch_date = next_launch_date %s 
     716        WHERE 
     717                id_command_on_host = \"%s\" 
     718", 
     719                COMMANDS_ON_HOST_TABLE, 
     720                $new_date_time, 
     721                $id_command_on_host 
     722        ); 
     723         
     724        $database->query($query); 
     725} 
     726 
    661727function lsc_command_on_host_set_current_state($id_command_on_host, $new_state) 
    662728{ 
     
    686752        $database->query($query); 
    687753} 
     754 
    688755 
    689756/** 
  • trunk/webmin/lsc/include/scheduler.inc.php

    r229 r238  
    314314                        $query = sprintf(" 
    315315                                SELECT 
    316                                         A.id_command_on_host, A.start_date 
     316                                        A.id_command_on_host, A.next_launch_date 
    317317                                FROM 
    318318                                        %s A, 
     
    332332                                        NOT (A.current_state = \"inventory_failed\") and 
    333333                                        (A.number_attempt_connection_remains > 0) and 
    334                                         (A.current_pid = \"-1\") 
     334                                        (A.current_pid = \"-1\") and  
     335                                        (A.next_launch_date <= CURRENT_TIMESTAMP ) 
    335336                                ORDER BY 
    336337                                        B.date_created ASC 
     
    348349                                // Iterate all command to dispatch 
    349350                                while ( $database->next_record() ) { 
    350                                         /* 
    351                                          * Test if start_date < now < end_date 
    352                                          */ 
    353                                         if ($database->f("start_date") != "0000-00-00 00:00:00") { 
    354                                                 if (strtotime($database->f("start_date"))>time()) { 
    355                                                         debug(1, "Run start_date > now for ".$database->f("id_command_on_host")); 
    356                                                         continue; 
    357                                                 } 
    358                                         } 
    359351 
    360352                                        $start_command = "cd ".dirname(__FILE__)."/../;./phprun.sh \"./start_command_on_host.php -id_command_on_host ".$database->f("id_command_on_host")."\" > /dev/null & echo \$!"; 
  • trunk/webmin/lsc/module.info

    r229 r238  
    33desc_fr=LRS : Prise de Contrôle à Distance Sécurisé 
    44depends=1.030 lbs_common 
    5 version=1.0.4 
     5version=1.0.5