Esempio n. 1
0
function startWorker($id)
{
    $logFile = RUNTIME_PATH . getWorkerLogFile($id);
    $pidFile = RUNTIME_PATH . getWorkerPidFile($id);
    $command = "nohup /usr/bin/php " . WORKER_PATH . " > {$logFile} 2>&1 & echo \$! > {$pidFile}";
    pake_echo($command);
    pake_sh($command);
}
Esempio n. 2
0
function run_plugin_list($task, $args)
{
    pake_echo('Installed plugins:');
    $config = _pear_init();
    $registry = $config->getRegistry();
    $installed = $registry->packageInfo(null, null, null);
    foreach ($installed as $channel => $packages) {
        foreach ($packages as $package) {
            $pobj = $registry->getPackage(isset($package['package']) ? $package['package'] : $package['name'], $channel);
            pake_echo(sprintf(" %-40s %10s-%-6s %s", pakeColor::colorize($pobj->getPackage(), 'INFO'), $pobj->getVersion(), $pobj->getState() ? $pobj->getState() : null, pakeColor::colorize(sprintf('# %s (%s)', $channel, $registry->getChannel($channel)->getAlias()), 'COMMENT')));
        }
    }
}
<?php

ini_set('max_execution_time', 3600);
$appName = $argv[1];
define('CURRENT_DIR', realpath(dirname(__FILE__)));
define('_SUB_DIR', CURRENT_DIR . '/dns/');
require_once './create-po-config.php';
$poAccountName = $appName . '-cvc';
$vpoClient = new bsVideoPublisherServicesSoapClient($vpoBaseUrl, null, $poKey, 'Admin');
$response = $vpoClient->createCustomer($poAccountName);
$adminKey = new bsVideoPublisherKeyHelper($poKey);
$result = bsVideoPublisherCryptoHelper::aesDecryptData($response['CreateCustomerResult']['Data'], $adminKey->getPrivateKey(), $adminKey->getIvSalt());
$xml = @simplexml_load_string($result);
if (!$xml) {
    pake_error("Error creating po account for " . $appName);
}
$poCustomerId = (string) $xml->CustomerGuid;
$poCustomerKey = (string) $xml->ApiKey;
//TODO Store this in order to user with deployment
$info = array('po_customer_id' => $poCustomerId, 'po_customer_key' => $poCustomerKey);
pake_echo($appName . ' : ' . serialize($info));
addPillarInformation($appName, "po_customer_id", $poCustomerId);
addPillarInformation($appName, "po_customer_key", $poCustomerKey);
echo "\nDONE\n";
Esempio n. 4
0
 /**
  * Classifies all entries in git changelog as 4 types.
  * Each entry is returned starting with "- "
  * @return array the 1st-level elements are themselves matrixes, except for 'unmatchedEntries' which is a plain array
  */
 public static function extractChangelogEntriesFromRepo($rootpath, $previousrev)
 {
     if ($previousrev != '') {
         /// @todo check if given revision exists in git repo? We'll get an empty changelog if it does not...
         /// @todo replace with pakegit::log
         $git = escapeshellarg(pake_which('git'));
         $changelogArray = preg_split('/(\\r\\n|\\n\\r|\\r|\\n)/', pake_sh(self::getCdCmd($rootpath) . " && {$git} log --pretty=%s " . escapeshellarg($previousrev) . "..HEAD"));
         $changelogArray = array_map('trim', $changelogArray);
         foreach ($changelogArray as $i => $line) {
             if ($line == '') {
                 unset($changelogArray[$i]);
             }
         }
         $changelogText = implode("\n", $changelogArray);
         if ($changelogText == '') {
             pake_echo("Git log returns an empty string - generating an empty changelog file. Please check if there is any problem with {$rootpath}");
         }
         // Was: "extract and categorize issues using known patterns"
         // This proved not to be reliable!
         // We categorize all issues by looking at their type in the bug tracker instead
         /*preg_match_all( "/^[- ]?Fix(?:ed|ing)?(?: bug|issue|for ticket)? (EZP-[0-9]+):? (.*)$/mi", $changelogText, $bugfixesMatches, PREG_PATTERN_ORDER );
           preg_match_all( "/^[- ]?Implement(?:ed)?(?: enhancement|issue)? (EZP-[0-9]+):? (.*)$/mi", $changelogText, $enhancementsMatches, PREG_PATTERN_ORDER );*/
         preg_match_all("!^Merge pull request #0?([0-9]+):? ([^/]*)(?:/.*)?\$!mi", $changelogText, $pullreqsMatches, PREG_PATTERN_ORDER);
         // remove merge commits to get "unmatched" items
         $unmatchedEntries = array_diff($changelogArray, $pullreqsMatches[0]);
         /// if we identify an issue number, look up its type in jira to determine its type
         $issueTypes = array();
         foreach ($unmatchedEntries as $i => $entry) {
             if (preg_match('/(EZP-[0-9]+):? (.*)$/i', $entry, $matches)) {
                 if (isset($issueTypes[$matches[1]])) {
                     $type = $issueTypes[$matches[1]];
                 } else {
                     $type = self::findIssueType($matches[1]);
                     $issueTypes[$matches[1]] = $type;
                 }
                 switch ($type) {
                     case 'enhancement':
                         $enhancementsMatches[0][] = $matches[0];
                         $enhancementsMatches[1][] = $matches[1];
                         $enhancementsMatches[2][] = $matches[2];
                         unset($unmatchedEntries[$i]);
                         break;
                     case 'bugfix':
                         $bugfixesMatches[0][] = $matches[0];
                         $bugfixesMatches[1][] = $matches[1];
                         $bugfixesMatches[2][] = $matches[2];
                         unset($unmatchedEntries[$i]);
                         break;
                 }
             }
         }
         $unmatchedEntries = array_values(array_map(function ($item) {
             return substr($item, 0, 2) != "- " ? "- {$item}" : $item;
         }, $unmatchedEntries));
     } else {
         pake_echo('Can not determine the git tag of last version. Generating an empty changelog file');
         $bugfixesMatches = array(array());
         $enhancementsMatches = array(array());
         $pullreqsMatches = array(array());
         $unmatchedEntries = array();
     }
     return array('bugfixesMatches' => $bugfixesMatches, 'enhancementsMatches' => $enhancementsMatches, 'pullreqsMatches' => $pullreqsMatches, 'unmatchedEntries' => $unmatchedEntries);
 }
if ($result['status'] !== bsPlayerManagerApi::STATUS_SUCCESS) {
    pake_error("Error creating PM Account");
    exit(1);
}
$accountUid = $result['data']['guid'];
//pad name (can not exist if error on creation)
$url_pad = "";
if (array_key_exists('url_pad', $result['data'])) {
    $url_pad = $result['data']['url_pad'];
}
$playerManagerApi->userCreate($playerManagerSecretKey, $email, $firstname, $lastname, $accounts, $username, $plainPassword);
if ($result['status'] !== bsPlayerManagerApi::STATUS_SUCCESS) {
    bsLogger::err('Player Manager: Failed to create user with email ' . $email . ' and username ' . $username);
    return null;
}
$userUid = $result['data']['guid'];
if (!$userUid) {
    throw new sfException("Player manager create user account error : " . json_encode($result));
}
$pmUser = bsPlayerManager::userGet("guid", $userUid);
$tvPmUserUid = $pmUser['guid'];
$tvPmUserSecret = $pmUser['secret'];
//We have to store following informations :
$info = array('pad' => $url_pad, 'accountUid' => $accountUid, 'userUid' => $tvPmUserUid, 'userSecret' => $tvPmUserSecret);
pake_echo($appName . ' : ' . serialize($info));
addPillarInformation($appName, "pm_pad", $url_pad);
addPillarInformation($appName, "pm_account_uid", $accountUid);
addPillarInformation($appName, "pm_user_uid", $tvPmUserUid);
addPillarInformation($appName, "pm_user_secret", $tvPmUserSecret);
pake_echo("DONE");
Esempio n. 6
0
 private function runInteractiveSession()
 {
     pake_import('interactive');
     pake_echo("=================================================================================");
     pake_echo("Welcome to pake's interactive console. To get list of commands type \"?\" or \"help\"");
     pake_echo("type \"quit\" or press ^D to exit");
     pake_echo("=================================================================================");
     $this->showVersion();
     echo "\n";
     while (true) {
         $command = pakeInput::getString('pake> ', false);
         if (false === $command) {
             // Ctrl-D
             pakeInteractiveTask::run_quit_pake();
         }
         if ('' === $command) {
             continue;
         }
         $this->initAndRunTaskInSubprocess($command);
     }
 }
Esempio n. 7
0
function pake_echo_error($text)
{
    pake_echo(sprintf(pakeColor::colorize('   ! %s', 'ERROR'), $text));
}
Esempio n. 8
0
 protected static function getPreviousRevisions($repos, $opts)
 {
     $revisions = array();
     foreach ($repos as $repo) {
         $rootpath = self::getSourceDir($opts, $repo);
         if (isset($opts['version']['previous'][$repo]['git-revision'])) {
             $previousrev = $opts['version']['previous'][$repo]['git-revision'];
             pake_echo("\nGit revision of previous release for repo {$repo} taken from config file: {$previousrev}");
         } else {
             $prevname = self::previousVersionName($opts);
             pake_echo("\nGetting git revision of previous release from GIT or Jenkins for repo {$repo}");
             $previousrev = self::getPreviousRevision($prevname, $repo, $opts);
             if ($previousrev == "") {
                 throw new pakeException("Previous revision number of {$repo} not found in Git or Jenkins. Please set it manually in version:previous:{$repo}:git-revision");
             }
             pake_echo("Git revision number of previous release for repo {$repo} is: {$previousrev}");
         }
         $revisions[$repo] = $previousrev;
     }
     return $revisions;
 }
Esempio n. 9
0
 /**
  * show documentation; use "pake help taskname" to see detailed documentation on task
  *
  * @param string $task 
  * @param string $args 
  * @return bool
  * @author Alexey Zakhlestin
  */
 public static function run_help($task, $args)
 {
     if (count($args) == 0) {
         self::get_instance()->help();
         return;
     }
     $victim_name = $args[0];
     foreach (pakeTask::get_tasks() as $name => $task) {
         if ($victim_name == $name or $victim_name == pakeTask::get_mini_task_name($name)) {
             $victim = $task;
             break;
         }
     }
     $title = 'Documentation for "' . $victim_name . '" task';
     pake_echo($title);
     pake_echo(str_repeat('=', mb_strlen($title)));
     pake_echo($victim->get_comment() . "\n");
     pake_echo($victim->get_help());
 }
Esempio n. 10
0
 /**
  * show documentation; use "pake help taskname" to see detailed documentation on task
  *
  * @param string $task
  * @param string $args
  * @throws pakeException
  * @author Alexey Zakhlestin
  */
 public static function run_help($task, $args)
 {
     if (count($args) == 0) {
         self::get_instance()->help();
         return;
     }
     $victim_name = $args[0];
     $task_name = pakeTask::taskname_from_abbreviation($victim_name);
     $victim = null;
     foreach (pakeTask::get_tasks() as $name => $task) {
         if ($task_name == $name or $task_name == pakeTask::get_mini_task_name($name)) {
             $victim = $task;
             break;
         }
     }
     if (null === $victim) {
         throw new pakeException("Couldn't find documentation for {$task_name}");
     }
     $title = 'Documentation for "' . $task_name . '" task';
     pake_echo($title);
     pake_echo(str_repeat('=', mb_strlen($title)));
     pake_echo($victim->get_comment() . "\n");
     pake_echo($victim->get_help());
 }
Esempio n. 11
0
 /**
  * Converts an existing ant properties file in its corresponding yaml version
  *
  * Converts the .properties files used to hold configuration settings for old
  * versions of ezextensionbuilder (the ones based on ant) to a .yaml configuration
  * file that is suitable for this version of the script.
  * It is recommended to inspect by hand the generated .yaml file after executing
  * the conversion.
  */
 static function run_convert_configuration($task = null, $args = array(), $cliopts = array())
 {
     self::setConfigDir($cliopts);
     $extname = @$args[0];
     if ($extname == '') {
         $extname = dirname(__FILE__);
     }
     while (!is_file("ant/{$extname}.properties")) {
         $extname = pake_input('What is the name of the current extension?');
         if (!is_file("ant/{$extname}.properties")) {
             pake_echo("File ant/{$extname}.properties not found");
         }
     }
     self::convertPropertyFileToYamlFile("ant/{$extname}.properties", self::getConfigDir() . "/options-{$extname}.yaml", array($extname => '', 'external' => 'dependencies', 'dependency' => 'extensions', 'repository' => array('svn', 'url')), "extension:\n    name: {$extname}\n\n");
     foreach (array('files.to.parse.txt' => 'to_parse', 'files.to.exclude.txt' => 'to_exclude') as $file => $option) {
         $src = "ant/{$file}";
         if (file_exists($src)) {
             //$ok = !file_exists( $dst ) || ( pake_input( "Destionation file $dst exists. Overwrite? [y/n]", 'n' ) == 'y' );
             //$ok && pake_copy( $src, $dst, array( 'override' => true ) );
             if (count($in = file($src, FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES))) {
                 $in = "\n\nfiles:\n    {$option}: [" . implode(', ', $in) . "]\n";
                 file_put_contents(self::getConfigDir() . "options-{$extname}.yaml", $in, FILE_APPEND);
             }
         }
     }
 }
<?php

ini_set('max_execution_time', 3600);
$appName = $argv[1];
define('CURRENT_DIR', realpath(dirname(__FILE__)));
require_once "../utils.php";
$commands = array();
$mysqlUser = "******";
$mysqlDatabase = $mysqlUser;
$mysqlPassword = substr(md5(uniqid()), 0, 10);
//$mysqlHost = "10.0.0.7";
$mysqlHost = "127.0.0.1";
addPillarInformation($appName, "mysql_password", $mysqlPassword);
addPillarInformation($appName, "mysql_user", $mysqlUser);
addPillarInformation($appName, "mysql_database", $mysqlUser);
addPillarInformation($appName, "mysql_host", $mysqlHost);
$saltCommand = 'salt ' . $appName . '-node1 state.sls eztv.deploydatabase';
echo pake_echo($saltCommand);
passthru($saltCommand);
echo "\n";
for ($i = 2; $i <= $numberOfFront; $i++) {
    $command = "sudo php " . _SUB_DIR . "/reboot-vm.php " . escapeshellarg($appName) . " front " . $i . " ";
    $tasks[] = $command;
}
for ($i = 2; $i <= $numberOfNode; $i++) {
    $command = "sudo php " . _SUB_DIR . "/reboot-vm.php " . escapeshellarg($appName) . " node " . $i . " ";
    $tasks[] = $command;
}
doTasksOnMultithread($tasks, $numberOfThread);
$command = "php create-dam-account.php " . escapeshellarg($appName) . " " . $numberOfFront . " " . $numberOfNode;
//TODO : check if  PAD DNS is OK
$command = "sudo php " . _SUB_DIR . "create-dns-step2.php " . escapeshellarg($appName) . " " . $numberOfFront . " " . $numberOfNode;
pake_echo($command);
passthru($command);
$command = "sudo php " . _SUB_DIR . "create-mysql-account.php " . escapeshellarg($appName) . " " . $numberOfFront . " " . $numberOfNode;
pake_echo($command);
passthru($command);
//Deploy cvc code on front only
$tasks = array();
for ($i = 1; $i <= $numberOfFront; $i++) {
    $command = "sudo php " . _SUB_DIR . "/deploy-cvc.php " . escapeshellarg($appName) . " front " . $i . " ";
    $tasks[] = $command;
}
doTasksOnMultithread($tasks, $numberOfThread);
//TODO : Wait until PAD DNS is OK
$command = "sudo php " . _SUB_DIR . "create-dns-step2.php " . escapeshellarg($appName) . " " . $numberOfFront . " " . $numberOfNode;
pake_echo($command);
passthru($command);
//TODO Prevent galera cluster not started
//TODO : Mail the client about his VM
echo "DONE";
Esempio n. 14
0
 public static function run_test($task)
 {
     $php_cgi = '';
     $_php_cgi = self::_get_php_executable() . '-cgi';
     if (file_exists($_php_cgi)) {
         $php_cgi = ' ' . escapeshellarg('TEST_PHP_CGI_EXECUTABLE=' . $_php_cgi);
     }
     pake_echo_comment('Running test-suite. This can take awhile…');
     pake_sh('make test NO_INTERACTION=1' . $php_cgi);
     pake_echo_comment('Done');
     $path = dirname(pakeApp::get_instance()->getPakefilePath()) . '/tests';
     $files = pakeFinder::type('file')->ignore_version_control()->relative()->name('*.diff')->in($path);
     if (count($files) == 0) {
         pake_echo('   All tests PASSed!');
         return;
     }
     pake_echo_error('Following tests FAILed:');
     foreach ($files as $file) {
         $phpt_file = substr($file, 0, -4) . 'phpt';
         $_lines = file($path . '/' . $phpt_file);
         $description = $_lines[1];
         unset($_lines);
         pake_echo('     ' . $phpt_file . ' (' . rtrim($description) . ')');
     }
 }
Esempio n. 15
0
 /**
  * Generates a sample package.xml to allow creation of packaged extension
  *
  * NB: that file is to be completed by hand
  */
 static function run_generate_sample_package_xml($task = null, $args = array(), $cliopts = array())
 {
     pake_copy(self::getResourceDir() . '/package_master.xml', 'package.xml');
     // tokens not replaced here are replaced at build time
     // tokens in square brackets are supposed to be edited by the developer
     $tokens = array('$summary' => '[Summary]', '$description' => '[Description]', '$vendor' => '', '$maintainers' => '', '$documents' => '', '$changelog' => '', '$simple-files' => '', '$state' => '[State]', '$requires' => '');
     //$files = pakeFinder::type( 'file' )->name( 'package.xml' )->maxdepth( 0 )->in( '.' );
     pake_replace_tokens('package.xml', '.', '{', '}', $tokens);
     pake_echo("File package.xml generated. Please replace all tokens in square brackets in it (but do not replace values in curly brackets) then commit it to sources in the top dir of the extension");
 }
Esempio n. 16
0
 /**
  * Loads, caches and returns the config options for a given extension
  *
  * Too smart fo our own good: we accept
  * - (nothing: extension is figured out based on single existing config file, version from config file)
  * - extension (version taken from config file)
  * - version (extension is figured out based on single existing config file, version from cli)
  * - extension, version
  * @return array
  */
 static function getOpts($extname = '', $version = '', $cliopts = array())
 {
     self::setConfigDir($cliopts);
     if ($version == '' && self::isValidVersion($extname)) {
         // lazy user
         $version = $extname;
         $extname = '';
     }
     if ($version != '' && !self::isValidVersion($version)) {
         throw new PakeException("'{$version}' is not a valid version number");
     }
     if ($extname == '') {
         $extname = self::getDefaultExtName();
     }
     /// @bug we cache the options gotten from disk, but what if this function is invoked multiple times with different cli options?
     if (!isset(self::$options[$extname]) || !is_array(self::$options[$extname])) {
         // custom config file
         if (isset($cliopts['config-file'])) {
             $cfgfile = $cliopts['config-file'];
         } else {
             $cfgfile = self::getOptionsDir() . "/options-{$extname}.yaml";
         }
         // user-local config file
         if (isset($cliopts['user-config-file'])) {
             $usercfgfile = $cliopts['user-config-file'];
             if (!is_file($cliopts['user-config-file'])) {
                 throw new PakeException("Could not find user-configuration-file {$cliopts['user-config-file']}");
             }
         } else {
             $usercfgfile = self::getOptionsDir() . "/options-user.yaml";
         }
         // command-line config options
         foreach ($cliopts as $opt => $val) {
             if (substr($opt, 0, 7) == 'option.') {
                 unset($cliopts[$opt]);
                 // transform dotted notation in array structure
                 $work = array_reverse(explode('.', substr($opt, 7)));
                 $built = array(array_shift($work) => $val);
                 foreach ($work as $key) {
                     $built = array($key => $built);
                 }
                 self::recursivemerge($cliopts, $built);
             }
         }
         self::loadConfiguration($cfgfile, $extname, $version, $usercfgfile, $cliopts);
     }
     pake_echo("Building extension {$extname} ( " . self::$options[$extname]['extension']['name'] . " ) version " . self::$options[$extname]['version']['alias'] . self::$options[$extname]['releasenr']['separator'] . self::$options[$extname]['version']['release']);
     return self::$options[$extname];
 }
Esempio n. 17
0
#Reboot target host (= restart all services)
$command = 'timeout 10 salt -t 10 ' . $hostname . ' cmd.run reboot';
pake_echo($command);
passthru($command);
sleep(10);
//wait for host reboot
$time = null;
while ($time == null || $time > $initialUptime) {
    $time = getHostUptime($hostname);
    pake_echo("time:" . $time);
}
if ($hostType == "node") {
    pake_echo("wait for node syncronisation");
    $nodeIsSynced = false;
    while (!$nodeIsSynced) {
        $command = 'timeout 10 salt -t 10 ' . $hostname . ' cmd.run "/usr/bin/clustercheck"';
        pake_echo($command);
        $output = null;
        exec($command, $output);
        if (!empty($output)) {
            $tmp = implode(' ', $output);
            pake_echo($tmp);
            if (strpos($tmp, "is synced") !== false) {
                $nodeIsSynced = true;
            }
        }
        if (!$nodeIsSynced) {
            sleep(5);
        }
    }
}