Exemplo n.º 1
0
/**
 * Check if slaves fingerprint has changed
 *
 * @param array $slaves Array of slaves with EC2 instance ID as array key
 * @param string $fileLocation Location of file storing slaves fingerprint
 * @return boolean
 */
function hasSlavesChanged($slaves, $fileLocation)
{
    $old = getSavedSlaves($fileLocation);
    sort($old);
    sort($slaves);
    if ($old == $slaves) {
        return false;
    }
    return true;
}
Exemplo n.º 2
0
if (!hasSlavesChanged($slavesIDs, $APP_CONF['data_dir'] . 'slaves')) {
    echo "No changes in slaves.\n";
    keepLsyncdAlive($APP_CONF);
    exit;
}
echo "There are changes in slaves.\n";
$toRun = null;
if (isset($APP_CONF['remote_script']['enabled']) && $APP_CONF['remote_script']['enabled']) {
    $scriptConfig = $APP_CONF['remote_script'];
    echo "Remote script execution is enabled.\n";
    if (!is_readable($scriptConfig['local_path'])) {
        trigger_error('Remote script is not present or readable at ' . $scriptConfig['local_path']);
    }
    $toRun = $slavesIDs;
    if ($APP_CONF['remote_script']['run_script_on_all_slaves'] === false) {
        $oldSlaves = getSavedSlaves($APP_CONF['data_dir'] . 'slaves');
        $toRun = array_diff($slavesIDs, $oldSlaves);
    }
}
saveSlaves($slavesIDs, $APP_CONF['data_dir'] . 'slaves');
$ec2Client = $aws->get('Ec2');
$ec2Instances = $ec2Client->describeInstances(array('InstanceIds' => $slavesIDs));
if (empty($ec2Instances)) {
    trigger_error('Unable to obtain description of slave EC2 instances.', E_USER_ERROR);
}
$slaves = array();
foreach ($ec2Instances['Reservations'] as $reservation) {
    $instances = $reservation['Instances'];
    foreach ($instances as $instance) {
        $slaves[] = array('instance_id' => $instance['InstanceId'], 'private_ip_address' => $instance['PrivateIpAddress']);
    }