Beispiel #1
0
 public function load_cib()
 {
     $res = ShellExec::exec_cibadmin();
     if (count($res) < 2) {
         Logger::error('ha', "cib.class.php::get_cib() - An error has occured, please check permissions on ulteo-ovd.conf or if 'cibadmin -Q' work fine");
         return false;
     }
     $this->xml->loadXML(implode("", $res));
     $racine = $this->xml->documentElement;
     $this->get_gen_attribute();
     return true;
 }
Beispiel #2
0
 public static function exec_set_conf_file($content)
 {
     $cmd = 'set_conf_file ' . $content;
     return ShellExec::exec_cmd($cmd);
 }
Beispiel #3
0
unset($_POST["hostname"]);
if (isset($action)) {
    switch ($action) {
        case "register":
            if (isset($hostname) && isset($client_ip) && secure_insert($SQL, $table, $hostname, $client_ip)) {
                echo "ok";
            } else {
                echo "error";
            }
            break;
        case "enable":
            if (isset($hostname) && isset($client_ip) && isset($passwd)) {
                Logger::warning('ha', "Configuration files has been written!");
                set_response_xml(0, _("Host activation has been done successfully!"));
                $ret = ShellExec::exec_shell_cmd("register", $client_ip, $hostname, $passwd);
            } else {
                set_response_xml(1, _("An error occured in POST request activation!"));
            }
            break;
        case "disable":
            $ret = ShellExec::exec_shell_cmd("unregister", "0", "0", "0");
            set_response_xml(0, _("Deleting host has been done successfully!"));
            break;
        default:
            set_response_xml(1, _("Request is not well formatted!"));
            break;
    }
} else {
    set_response_xml(1, _("Request is not well formatted!"));
}
die;
Beispiel #4
0
function writeVarsToConfFile($vars)
{
    $content = "";
    foreach ($vars as $k => $v) {
        $content .= $k . "=" . $v . ":";
    }
    $ret = ShellExec::exec_set_conf_file($content);
}
Beispiel #5
0
function action_to_hosts($action, $host)
{
    Logger::warning('ha', "status.php::action to host requested standby='" . $action . "' to host '" . $host . "'");
    $ret = ShellExec::exec_action_to_host($action, $host);
}
Beispiel #6
0
 /**
  * [runTask 运行任务]
  * @param  [type] $taskId  [description]
  * @param  [type] $ipList  [description]
  * @param  [type] $cmd     [description]
  * @param  [type] $timeout [description]
  * @return [array]          [ip:ok, failed, overtime]
  */
 public function runTask($taskId, $ipList, $cmd, $timeout = null)
 {
     $this->logger->info("START RUN TASK:{$taskId}");
     if (empty($timeout)) {
         $timeout = $this->timeout;
     }
     //执行命令
     $shellCmd = 'mkdir -p /tmp/pkg_tools_v3/;' . 'rsync -a #rsyncd_svr#::pkg_home/pkg_tools/ /tmp/pkg_tools_v3/;' . 'cd /tmp/pkg_tools_v3/;' . "{$cmd};" . 'cd scan_pkg;' . './scan_packages_info.sh >/dev/null 2>&1 & ';
     $this->logger->info("command:{$shellCmd}");
     $shellRun = new ShellExec();
     $taskList = $shellRun->runCmd($shellCmd, $ipList);
     $this->logger->info('TASK LIST:' . json_encode($taskList));
     //初始化任务状态 已启动
     foreach ($taskList as $shellTaskId => $taskInfo) {
         foreach ($taskInfo['ip_status'] as $ip => $info) {
             $status = 'started';
             $msg = 'task type:' . $taskInfo['type'] . ';' . 'shell taskid:' . $shellTaskId;
             $this->logger->info("ip:{$ip}, msg:{$msg}, status:{$status}");
             $this->updateStatus($ip, $taskId, $status, $msg, $msg);
         }
     }
     $startTime = time();
     $ipStatus = array();
     $done = array();
     $overtime = false;
     while (true) {
         $useTime = time() - $startTime;
         if ($useTime >= $timeout) {
             $overtime = true;
             break;
         }
         //获取任务执行情况
         $taskList = $shellRun->getTaskInfo($taskList);
         $this->logger->info("taskList info" . json_encode($taskList));
         $finished = true;
         foreach ($taskList as $shellTaskId => $taskInfo) {
             if ($taskInfo['status'] != 'ok') {
                 $finished = false;
             }
             foreach ($taskInfo['ip_status'] as $ip => $info) {
                 if (array_key_exists($ip, $done) && $done[$ip] == true) {
                     continue;
                 }
                 if (strpos($info['status'], 'fail') !== false) {
                     //失败的
                     $done[$ip] = true;
                     $status = 'failed';
                     $msg = $info['msg'];
                     $this->logger->info("ip:{$ip}, taskid:{$taskId}, status:{$status}, msg:{$msg}");
                     $this->updateStatus($ip, $taskId, $status, $msg, $msg);
                 } elseif ($info['status'] == 'ok') {
                     //成功的则获取命令输出并更新到数据库
                     $done[$ip] = true;
                     //匹配成功的输出 两种:result 或 resultLine
                     $matchCount = preg_match_all('/result%%(\\w+)%%(.*)%%/', $info['msg'], $matches);
                     if ($matchCount > 0) {
                         $result = end($matches[1]);
                         $msg = end($matches[2]);
                     }
                     if ($result == 'success') {
                         $status = 'ok';
                     } else {
                         $status = 'failed';
                     }
                     $matchCount = preg_match_all('/%%resultLine%%([^%]*)%%([^%]*)%%([^%]*)%%([^%]*)%%([^%]*)%%([^%]*)%%([^%]*)%%/', $info['msg'], $matches);
                     if ($matchCount > 0) {
                         $result = end($matches[6]);
                         $start = end($matches[7]);
                         if ($result == 'success') {
                             if (empty($start)) {
                                 $status = 'ok';
                             } else {
                                 $status = 'failed';
                                 $msg = $start;
                             }
                         } else {
                             $status = 'failed';
                         }
                     }
                     $this->logger->info("ip:{$ip}, taskid:{$taskId}, status:{$status}, msg:{$msg}");
                     $this->updateStatus($ip, $taskId, $status, $msg, $info['msg']);
                 }
             }
         }
         if ($finished == true) {
             break;
         }
         sleep(3);
     }
     $this->logger->info('task list:' . json_encode($taskList));
     $resultArray = array();
     //因为超时退出时, 将未结束的ip设置为fail
     if ($overtime == true) {
         $this->logger->info('overtime, set undone ip failed');
         foreach ($ipList as $ip) {
             $toSelect = array('task_id' => $taskId, 'ip' => $ip);
             $dbRes = $this->database->selectValue($toSelect, Conf::get('mysqlTaskResultTableName'));
             $status = 'ok';
             foreach ($dbRes as $index => $ipTaskInfo) {
                 if ($ipTaskInfo['status'] != 'ok' && $ipTaskInfo['status'] != 'failed') {
                     $ip = $ipTaskInfo['ip'];
                     $status = 'failed';
                     $msg = 'shell run timeout';
                     $resultArray[$ip] = 'overtime';
                     $this->logger->info("ip:{$ip}, taskid:{$taskId}, status:{$status}, msg:{$msg}");
                     $this->updateStatus($ip, $taskId, $status, $msg, $msg);
                 } else {
                     $resultArray[$ip] = $ipTaskInfo['status'];
                 }
             }
         }
     }
     $this->updateTaskStatus($taskId);
     return $resultArray;
 }
Beispiel #7
0
        $res = ShellExec::exec_clean_logs();
    }
}
if (isset($_GET["warn"])) {
    $severity[] = "WARN";
    $warn = 1;
}
if (isset($_GET["info"])) {
    $severity[] = "info";
    $info = 1;
}
page_header();
echo '<div>';
echo '<h1>' . _('High Availability logs') . '</h1>';
echo '<link rel="stylesheet" type="text/css" href="media/style/media-ha.css" />';
$res = ShellExec::exec_view_logs($severity);
echo '<table cellpadding="0" cellspacing="3" border="0"><tr><td>';
echo '<form name="mod_ha_logs" action="logs.php" method="get">';
if ($warn) {
    echo '<input type="checkbox" name="warn" value="1" checked="checked" /> ' . _('Show alerts') . ' ';
} else {
    echo '<input type="checkbox" name="warn" value="1" /> ' . _('Show alerts') . ' ';
}
if ($info) {
    echo '<input type="checkbox" name="info" value="1" checked="checked" /> ' . _('Show information') . ' ';
} else {
    echo '<input type="checkbox" name="info" value="1" /> ' . _('Show informations') . ' ';
}
echo '<input type="submit" value="reload" /> ';
echo '</form></td><td>';
echo '<form name="mod_ha_logs" action="logs.php" method="post">';