Skip to content
Snippets Groups Projects
Select Git revision
  • c7650f356855deeb44554fe7dc9bdde2d5d6aecc
  • master default
  • renovate/golang.org-x-crypto-0.x
  • renovate/go-1.x
  • renovate/golang.org-x-sync-0.x
  • renovate/opentelemetry-go-monorepo
  • renovate/github.com-go-webauthn-webauthn-0.x
  • renovate/github.com-mattn-go-sqlite3-1.x
  • renovate/github.com-go-ldap-ldap-v3-3.x
  • renovate/github.com-prometheus-client_golang-1.x
  • renovate/github.com-google-go-cmp-0.x
  • renovate/github.com-lunixbochs-struc-digest
  • renovate/github.com-duo-labs-webauthn-digest
13 results

dialer.go

Blame
    • ale's avatar
      c165311f
      Let the configuration override connection and max request timeouts · c165311f
      ale authored
      Add the 'connect_timeout' and 'request_max_timeout' configuration
      fields, to control respectively the initial connection timeout, and
      the maximum time for each individual request. This allows fine-tuning
      of the expected performance of specific backends, for example to let
      optional backends fail fast.
      c165311f
      History
      Let the configuration override connection and max request timeouts
      ale authored
      Add the 'connect_timeout' and 'request_max_timeout' configuration
      fields, to control respectively the initial connection timeout, and
      the maximum time for each individual request. This allows fine-tuning
      of the expected performance of specific backends, for example to let
      optional backends fail fast.
    wp-nginx-map.php 2.09 KiB
    <?php
    
    // wp-nginx-map.php
    //
    // Stampa una mappa delle assegnazioni blog -> backend, per NGINX.
    // IP interno del master.
    $master_url = file_get_contents('/etc/noblogs/master');
    $noblogs_master = parse_url($master_url)['host'];
    
    // Load wordpress api.
    define('WP_CACHE',false);
    require_once(__DIR__ . '/wp-load.php');
    
    // Port that the noblogs apache2 instance is listening on (as a string).
    define('NOBLOGS_PORT','92');
    
    // Return all blogs.
    function get_blogs() {
      global $wpdb;
      $sql = "SELECT blog_id, domain FROM $wpdb->blogs WHERE deleted = 0 AND archived = '0' ORDER BY domain ASC";
      $result = $wpdb->get_results($sql);
      return ($result);
    }
    
    function printline($s) {
      echo $s . "\n";
    }
    
    function backend_to_http_endpoint($backend) {
      if (substr($backend, 0, 8) != 'backend_') {
        error_log('diamine, di questo backend non so che farmene: ' . $backend);
        return $noblogs_master . ':' . NOBLOGS_PORT;
      }
      $id = substr($backend, 8);
      return '172.16.1.' . $id . ':' . NOBLOGS_PORT;
    }
    
    // Print the blog -> backend map.
    function generate_backend_map($blogs) {
      global $wpdb;
      global $noblogs_master;
      $wpdb_hash = &$wpdb->hash_map;
    
      printline('map $http_host $backend_noblogs {');
      printline(' default http://' . $noblogs_master . ':' . NOBLOGS_PORT . ';');
      foreach ($blogs as $blog) {
        $blog_id = $blog->blog_id;
        if ($blog_id == 1)
          continue;
        $backend_id = $wpdb_hash->lookup($blog_id);
        $backend_http = backend_to_http_endpoint($backend_id);
        printline(' ' . $blog->domain . ' http://' . $backend_http . ';');
      }
      printline('}');
    }
    
    // Print the blog -> site map.
    // This is used to send apache the right site name for logging purposes.
    function generate_site_map($blogs) {
      printline('map $http_host $site_noblogs {');
      printline(' default noblogs.org;');
      foreach ($blogs as $blog) {
        $blog_id = $blog->blog_id;
        if ($blog_id == 1)
          continue;
        printline(' ' . $blog->domain . ' ' . $blog->domain . ';');
      }
      printline('}');
    }
    
    function generate_maps() {
      $all_blogs = get_blogs();
      generate_backend_map($all_blogs);
      generate_site_map($all_blogs);
    }
    
    generate_maps();