Server management
774609
def servers
      @servers ||= begin
        dsn_list = ::JSON.parse(request.cookies['genghis_rb_servers'] || '[]')
        servers  = default_servers.merge(init_servers(dsn_list))
        servers.empty? ? init_servers(['localhost']) : servers # fall back to 'localhost'
      end
    end
626219
function gracefulShutdown(){
  console.log('About to exit, closing servers.');

  servers.forEach(function(server, index){
    server.close();
  });

  process.exit();
}
831352
function Server(configs) {
  var dirs = {};
  var app = express();

  // Check environment vars
  var env = process.env.NODE_ENV || 'development';
  var production = (env === 'production');

  // Merge custom config to default configs.
  var settings = _.extend(_.clone(defaults), configs || {});

  // Check database configs
  if (settings.database) {
    // Check if databse uri is a mongdob uri.
    var database = settings.database = databases.mongodb.isMongodbUri(settings.database) ? 
        databases.mongodb.parseMongodbUri(settings.database) : 
        settings.database;

    // Check if we are going to persist sessions in mongodb
    if (database.type === 'mongodb' && settings.session.store && dependencies['connect-mongo'] && dependencies['express-session']) {
      var storeOptions = {
        db: database.name,
        host: database.host || 'localhost',
        port: database.port || 27017,
        username: settings.database.options.user || '',
        password: settings.database.options.pass || ''
      };

      // Create a mongo session store.
      var mongoStore = dependencies['connect-mongo']({ 
        session: dependencies['express-session']
      });

      // Replace store with a instance.
      settings.session.store = new mongoStore(storeOptions);
    }
  }

  // Find `views` and `public` absolute path
  dirs.views = finder(configs, 'views');
  dirs.publics = finder(configs, 'publics');
  dirs.uploads = finder(configs, 'uploads');

  // Setup express settings
  app.set('env', env);
  app.set('views', dirs.views);
  app.set('view engine', settings['view engine']);
  app.set('port', process.env.PORT || 3000);

  // Disable view chche in dev mode
  if (!production) 
    app.set('view cache', false);

  // Logger handler
  app.use(logger(production ? settings.logformat : 'dev'));

  // Compression handler
  if (dependencies.compression)
    app.use(dependencies.compression());

  // Request body parser
  // Parse `application/x-www-form-urlencoded`
  app.use(bodyParser.urlencoded({ extended: false }));
  // Parse `application/json`
  app.use(bodyParser.json());

  // Upload handler
  if (dependencies.multer)
    app.use(dependencies.multer({ dest: dirs.uploads }));

  if (dependencies['method-override'])
    app.use(dependencies['method-override'](settings['method-override'] || {}));

  app.use(cookieParser(settings.secret || settings.session.secret));

  // Session middleware
  if (dependencies['express-session'])
    app.use(dependencies['express-session'](settings.session));

  // Less and Sass middleware
  if (dependencies['less-middleware'])
    app.use(dependencies['less-middleware'](dirs.publics));
  if (dependencies['node-sass-middleware'])
    app.use(dependencies['node-sass-middleware']({ src: dirs.publics }));

  // Serve static files
  app.use(express.static(dirs.publics));

  // Expose locals to template engine
  app.locals.ENGINE = pkg;
  app.locals.SITE = settings;
  app.locals.SETTINGS = settings;
  app.locals.URL = production ? 
    (settings.url || settings.uri || 'http://127.0.0.1') :
    'http://127.0.0.1:' + app.get('port');
  app.locals.URI = app.locals.URL;

  this.app = app;
  this.deps = new depender();
  this.deps.define('debug', debug(settings.name));
  this.deps.define('express', express);
  this.deps.define('middlewares', middlewares);

  this.settings = settings;

  if (settings.session.store)
    this.deps.define('mongoStore', settings.session.store);

  return this;
}
828402
private void updateServerInfo() {
		ServerInfo serverInfo = loadBalance.getServerInfo();
		if (serverInfo == null)
			throw new RuntimeException("'serverInfo' is null !");
		setServerHost(serverInfo.getHost());
		setServerPort(serverInfo.getPort());
		log.debug("Update server info . ({})", serverInfo.toString());
	}
482796
public final void server() {
    String port = parsedArguments.getString("port");
    String model = parsedArguments.getString(MODEL);
    String lexer = parsedArguments.getString("lexer");
    String dictTag = parsedArguments.getString("dictTag");
    String dictPath = parsedArguments.getString("dictPath");
    String clearFeatures = parsedArguments.getString("clearFeatures");
    String outputFormat = parsedArguments.getString("outputFormat");
    String lang = parsedArguments.getString("language");
    Properties serverproperties = setNameServerProperties(port, model, lang,
        lexer, dictTag, dictPath, clearFeatures, outputFormat);
    new NERTaggerServer(serverproperties);
  }
527984
def resque_server
      u = self
      servers = Jobtracker.deploy_servers
      server_i = u.name.to_md5.gsub(/[^0-9]/,'').to_i % servers.length
      servers[server_i]
    end
127515
def servers(self):
        """"""
        self.__init()
        items = []
        for k,v in self._json_dict.items():
            if k == "servers":
                for s in v:
                    if 'id' in s:
                        url = "%s/%s" % (self.root, s['id'])
                        items.append(
                            self.Server(url=url,
                                        securityHandler=self._securityHandler,
                                        proxy_url=self._proxy_url,
                                        proxy_port=self._proxy_port))
            del k,v
        return items
776336
def serve_forever(self):
        """"""
        # Set the server login/password (if -P/--password tag)
        if self.args.password != "":
            self.add_user(self.args.username, self.args.password)
        # Serve forever
        self.server.serve_forever()
298870
def Inventory(cls):
        
        l = ServerSet()
        rs = cls.find()
        for server in rs:
            l.append(server)
        return l
82296
def create_server(self, *args, **kwargs):
        
        # hpcloud's management console stuffs all of its tags in a "tags" tag.
        # populate it with the stack and role values here only at server
        # creation time.  what users do with it after server creation is up to
        # them.
        tags = kwargs['tags']
        tags[A.tags.TAGS] = ','.join([
                tags.get(A.tags.STACK, ''),
                tags.get(A.tags.ROLE, ''),
                ])
        # Don't create an explicit floating IP; gets one 
        # automatically
        if 'floating_ip' not in kwargs:
            kwargs['floating_ip'] = False
        s = super(HPNova, self).create_server(*args, **kwargs)
        return fix_hp_addrs(s)
1318650
public final void server() {

    // load parameters into a properties
    String port = parsedArguments.getString("port");
    String model = parsedArguments.getString("model");
    String lemmatizerModel = parsedArguments.getString("lemmatizerModel");
    final String allMorphology = Boolean.toString(this.parsedArguments.getBoolean("allMorphology"));
    final String multiwords = Boolean.toString(this.parsedArguments
        .getBoolean("multiwords"));
    final String dictag = Boolean.toString(this.parsedArguments
        .getBoolean("dictag"));
    String outputFormat = parsedArguments.getString("outputFormat");
    // language parameter
    String lang = parsedArguments.getString("language");
    Properties serverproperties = setServerProperties(port, model, lemmatizerModel, lang, multiwords, dictag, outputFormat, allMorphology);
    new StatisticalTaggerServer(serverproperties);
  }
1158771
def cli(env, identifier, sortby, cpu, domain, hostname, memory, tag, columns):
    """"""

    mgr = SoftLayer.DedicatedHostManager(env.client)
    guests = mgr.list_guests(host_id=identifier,
                             cpus=cpu,
                             hostname=hostname,
                             domain=domain,
                             memory=memory,
                             tags=tag,
                             mask=columns.mask())

    table = formatting.Table(columns.columns)
    table.sortby = sortby

    for guest in guests:
        table.add_row([value or formatting.blank()
                       for value in columns.row(guest)])

    env.fout(table)
806321
public static void main(String[] args) {
        ServerSchemaGenCommand util = new ServerSchemaGenCommand();
        int rc = util.generateServerSchema(args);
        System.exit(rc);
    }
330684
protected synchronized void refreshServers() {
        StringBuilder refreshResult = new StringBuilder();
        Set<Server> availableReadServers = new HashSet<>();
        Server[] newReadServers;

        if (writeServer == null || !writeServer.isAvailable()) {
            logger.debug("[refreshServers] write server is null or not available");

            for (Server server : SERVERS) {
                if (server.isAvailable() && server.isMaster()) {
                    writeServer = server;
                    logger.debug("[refreshServers] new writeServer: id = {}, uri = {}", writeServer.getId(), writeServer.getManagementUri());
                }
            }

            if (writeServer == null) {
                readServers = new Server[0];
                return;
            }
        }

        for (Server server : SERVERS) {
            logger.debug("[refreshServers] server: id = {}, isAvailable = {}", server.getId(), server.isAvailable());

            if (!server.getId().equals(writeServer.getId()) && server.isAvailable()) {
                logger.debug("[refreshServers] add read server");
                availableReadServers.add(server);
            }
        }

        if (availableReadServers.size() == 0) {
            logger.debug("[refreshServers] available read servers = 0");

            newReadServers = new Server[1];
            newReadServers[0] = writeServer;

            refreshResult
                    .append("refreshServers: read servers = ")
                    .append(writeServer.getId())
                    .append("=>")
                    .append(writeServer.getManagementUri())
                    .append(", write servers = ")
                    .append(writeServer.getId())
                    .append("=>")
                    .append(writeServer.getManagementUri());
        }
        else {
            logger.debug("[refreshServers] available read servers = {}", availableReadServers.size());

            newReadServers = new Server[availableReadServers.size()];
            int i = 0;

            refreshResult.append("refreshServers: read servers = [");

            for (Server server : availableReadServers) {
                newReadServers[i++] = server;

                refreshResult
                        .append(server.getId())
                        .append("=>")
                        .append(server.getManagementUri())
                        .append(" ");
            }

            refreshResult
                    .append(", write servers = ")
                    .append(writeServer.getId())
                    .append("=>")
                    .append(writeServer.getManagementUri())
                    .append("]");
        }

        readServers = newReadServers;

        logger.debug("[refreshServers] {}", refreshResult.toString());
    }
247030
def serveInBackground(port, serverName, prefix='/status/'):
  """"""
  import flask, threading
  from wsgiref.simple_server import make_server
  app = flask.Flask(__name__)
  registerStatsHandler(app, serverName, prefix)
  server = threading.Thread(target=make_server('', port, app).serve_forever)
  server.daemon = True
  server.start()
  return server
383768
private void configureServer(ServerBartender server)
  {
    // XXX: mixing server/client
    
    ServerNetwork serverNet = _serverMap.get(server.getId());
    
    if (serverNet == null) {
      serverNet = new ServerNetwork(_system, server);
      
      configServer(serverNet, server);

      serverNet.init();
      
      _serverMap.put(server.getId(), serverNet);
    }
  }
1174425
def set_server(self, server_pos, key, value):
        """"""
        self.servers.set_server(server_pos, key, value)