예제 #1
0
 /**
  * Runs upgrade process
  *
  * @return bool Returns true if all updates completed successfully, false otherwise
  */
 public function run()
 {
     if (!self::checkPid()) {
         $this->console->warning("Cannot start a new process because another one has already been started.");
         return false;
     }
     register_shutdown_function('Scalr\\Upgrade\\UpgradeHandler::removePid');
     //Loads updates
     $successful = $this->loadUpdates();
     if (isset($this->opt->cmd) && $this->opt->cmd == self::CMD_RUN_SPECIFIC) {
         $pending = [];
         if (!isset($this->updates[$this->opt->uuid])) {
             $this->console->warning("Could not find specified update %s", $this->opt->uuid);
             exit(1);
         }
         $pending[] = $this->updates[$this->opt->uuid];
     } else {
         $dt = new \DateTime($this->getLastDate(), new \DateTimeZone('UTC'));
         $pending = $this->updates->getPendingUpdates($dt->getTimestamp());
     }
     if (count($pending) == 0) {
         $this->console->out('Scalr is up-to-date');
         return $successful;
     }
     $this->console->success('Starting Scalr upgrade');
     //Applies updates
     foreach ($pending as $update) {
         $update->console->interactive = $this->console->interactive;
         $successful = $this->applyUpdate($update) && $successful;
     }
     $this->console->success('Done');
     return $successful;
 }
예제 #2
0
 /**
  * Runs upgrade process
  */
 public function run()
 {
     //Loads updates
     $this->loadUpdates();
     if (isset($this->opt->cmd) && $this->opt->cmd == self::CMD_RUN_SPECIFIC) {
         $pending = array();
         if (!isset($this->updates[$this->opt->uuid])) {
             $this->console->warning("Could not find specified update %s", $this->opt->uuid);
             exit;
         }
         $pending[] = $this->updates[$this->opt->uuid];
     } else {
         $dt = new \DateTime($this->getLastDate(), new \DateTimeZone('UTC'));
         $pending = $this->updates->getPendingUpdates($dt->getTimestamp());
     }
     //Applies updates
     foreach ($pending as $update) {
         $this->applyUpdate($update);
     }
 }
예제 #3
0
파일: upgrade.php 프로젝트: scalr/scalr
/**
 * Scalr automatic upgrade script
 *
 * @author   Vitaliy Demidov   <*****@*****.**>
 * @since    4.5.0 (10.10.2013)
 */
require_once __DIR__ . '/../src/prepend.inc.php';
use Scalr\Upgrade\UpgradeHandler;
use Scalr\Upgrade\Console;
use Scalr\Util\PhpTemplate;
set_time_limit(0);
define('SCALR_UPGRADE_VERSION', '1.1');
$shortopts = "hinvr:";
$longopts = array("help", "new", "force");
$opt = getopt($shortopts, $longopts);
$console = new Console();
$console->timeformat = null;
$console->keeplog = false;
$showusage = function () use($console) {
    $console->out("Scalr upgrade Ver %s php-%s", SCALR_UPGRADE_VERSION, phpversion());
    $console->out("");
    $console->out("Usage: upgrade [OPTIONS]");
    $console->out("  -h, --help          Display this help end exit.");
    $console->out("  -n, --new           Generate a new update class to implement.");
    $console->out("  -r uuid             Run only specified update. UUID is unique identifier.");
    $console->out("  -v                  Turn on verbosity.");
    $console->out("  -i                  Turn on interactive mode for upgrades which rely on it.");
    $console->out("  --force             Run forcefully ignoring pid.");
    $console->out("");
    exit;
};
예제 #4
0
 /**
  * {@inheritdoc}
  * @see \Scalr\System\Pcntl\ProcessInterface::OnStartForking()
  */
 public function OnStartForking()
 {
     $db = \Scalr::getDb();
     $sevenDaysAgo = date('Y-m-d H:i:s', strtotime('-7 days'));
     $tenDaysAgo = date('Y-m-d H:i:s', strtotime('-10 days'));
     $twentyDaysAgo = date('Y-m-d H:i:s', strtotime('-20 days'));
     $monthAgo = date('Y-m-d H:i:s', strtotime('-1 months'));
     $twoMonthAgo = date('Y-m-d H:i:s', strtotime('-2 months'));
     $twoWeeksAgo = date('Y-m-d H:i:s', strtotime('-14 days'));
     $this->console->out("%s (UTC) Start RotateLogsProcess", gmdate('Y-m-d'));
     $this->console->out("Rotating logentries table");
     $this->rotateTable("DELETE FROM `logentries` WHERE `time` < ?", [strtotime('-10 days')]);
     $this->console->out("Rotating scripting_log table");
     $this->rotateTable("DELETE FROM `scripting_log` WHERE `dtadded` < ?", array($sevenDaysAgo));
     $this->console->out("Rotating events table");
     $this->rotateTable("DELETE FROM `events` WHERE `dtadded` < ?", array($twoMonthAgo));
     $this->console->out("Rotating messages table");
     $this->rotateTable("DELETE FROM messages WHERE type='out' AND status='1' AND `dtlasthandleattempt` < ?", array($tenDaysAgo));
     $this->rotateTable("DELETE FROM messages WHERE type='out' AND status='3' AND `dtlasthandleattempt` < ?", array($tenDaysAgo));
     $this->rotateTable("DELETE FROM messages WHERE type='in' AND status='1' AND `dtlasthandleattempt` <  ?", array($tenDaysAgo));
     $this->console->out('Rotating webhook_history table');
     $this->rotateTable("DELETE FROM webhook_history WHERE `created` < ?", array($twoWeeksAgo));
     $this->console->out("Rotating farm_role_scripts table");
     $year = date('Y');
     $month = date('m', strtotime('-1 months'));
     $this->rotateTable("\n            DELETE FROM `farm_role_scripts`\n            WHERE ismenuitem='0' AND event_name LIKE 'CustomEvent-{$year}{$month}%'\n        ");
     $this->rotateTable("\n            DELETE FROM `farm_role_scripts`\n            WHERE ismenuitem='0' AND event_name LIKE 'APIEvent-{$year}{$month}%'\n        ");
     $this->console->out('Calculating number of the records in the syslog table');
     if ($db->GetOne("SELECT COUNT(*) FROM `syslog`") > 1000000) {
         $this->console->out("Rotating syslog table");
         $dtstamp = date("HdmY");
         try {
             if ($db->GetOne("SHOW TABLES LIKE ?", ['syslog_tmp'])) {
                 $db->Execute("DROP TABLE `syslog_tmp`");
             }
             $db->Execute("CREATE TABLE `syslog_tmp` LIKE `syslog`");
             $db->Execute("RENAME TABLE `syslog` TO `syslog_" . $dtstamp . "`, `syslog_tmp` TO `syslog`");
             $db->Execute("TRUNCATE TABLE syslog_metadata");
             $db->Execute("OPTIMIZE TABLE syslog");
             $db->Execute("OPTIMIZE TABLE syslog_metadata");
         } catch (Exception $e) {
             $this->console->error($e->getMessage());
         }
         $this->Logger->debug("Log rotated. New table 'syslog_{$dtstamp}' created.");
         $this->rotateBackup('^syslog_[0-9]{8,10}$');
     }
     //Rotate aws_statistics
     $this->console->out("Rotating AWS Statistics");
     StatisticsPlugin::rotate();
     //Rotate cost analytics data
     if (Scalr::getContainer()->analytics->enabled) {
         $this->console->out("Rotating analytics.poller_sessions table");
         $before = (new DateTime('-7 days', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
         $this->rotateTable("DELETE FROM `poller_sessions` WHERE `dtime` < ?", [$before], 'cadb');
         $this->console->out("Rotating analytics.usage_h table");
         $before = (new DateTime('-14 days', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
         $this->rotateTable("DELETE FROM `usage_h` WHERE `dtime` < ?", [$before], 'cadb');
         $this->console->out("Rotating analytics.nm_usage_h table");
         $this->rotateTable("DELETE FROM `nm_usage_h` WHERE `dtime` < ?", [$before], 'cadb');
     }
     $this->console->out('Done');
 }