Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagephp
titlebot-reboot-instances.php
<?php
// Programmed by Chun Kang (kurapa@kurapa.com) on Nov 2018

include_once "ssh_init.php";

$m_config->id = "<your user id>";
$m_config->password = "<user password>";
$m_config->server = "<server address>";
$m_config->port = 22;

function service_status($service_name, $message, $prc) {
		$message = str_replace( "/", "\\/", $message);
        if (eregpreg_match( "/{$message}/", $prc)) {
                echo "{$service_name} ok!\n";
                return 1;
        }
        else {
                echo "{$service_name} does not work!!\n";
                return 0;
        }
}

// collect process information by "ps" command
$prc=ssh2_run_cmd( "ps aux --sort=-pcpu");

if (strlen($prc)>0)
{
        echo "Process Status<br>\n";
        if (!service_status("httpd", "/usr/sbin/httpd -DFOREGROUND", $prc)) {
                ssh2_run_cmd( "/etc/init.d/httpd restart");
                echo  "httpd restared!\n";
        }
        if (!service_status("mysqld", "/usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql", $prc)) {
                ssh2_run_cmd( "/etc/init.d/mysqld restart");
                echo  "mysqld restarted!\n";
        }
        if (!service_status("qsok.com - confluence server", "/pub/qsok.com-confluence/jre//bin/java", $prc)) {
                ssh2_run_cmd( "/etc/init.d/confluence restart");
                echo  "qsok.com restarted!\n";
        }
        if (!service_status("enewtown.com - confluence server", "/pub/enewtown.com-confluence/jre//bin/java", $prc)) {
                ssh2_run_cmd( "/etc/init.d/confluence1 restart");
                echo  "enewtown.com restarted!\n";
        }
        if (!service_status("qsok.com - jira server", "/pub/qsok.com-jira/jre//bin/java", $prc)) {
                ssh2_run_cmd( "/etc/init.d/jira restart");
                echo  "qsok.com restarted!\n";
        }
        echo "<hr>";
}
?>

...