<commit_before>{argv} = require 'optimist'

KONFIG = require argv.c?.trim()
{webserver, mongo, mq, projectRoot, kites, uploads, basicAuth} = KONFIG

webPort = argv.p ? webserver.port

cluster = require 'cluster'

if cluster.isMaster
  cluster.fork() for i in [0...webserver.clusterSize]
  cluster.on "exit", (worker, code, signal) ->
    cluster.fork()
else

  processMonitor = (require 'processes-monitor').start
    name : "webServer on port #{webPort}"
    stats_id: "webserver." + process.pid
    interval : 30000
    limit_hard  :
      memory   : 300
      callback : ->
        console.log "[WEBSERVER #{webPort}] Using excessive memory, exiting."
        process.exit()
    die :
      after: "non-overlapping, random, 3 digits prime-number of minutes"
      middleware : (name,callback) -> koding.disconnect callback
      middlewareTimeout : 5000
    librato: KONFIG.librato
  
  {extend} = require 'underscore'
  express = require 'express'
  Broker = require 'broker'
  fs = require 'fs'
  hat = require 'hat'<commit_msg>Track services<commit_after>{argv} = require 'optimist'

KONFIG = require argv.c?.trim()
{webserver, mongo, mq, projectRoot, kites, uploads, basicAuth} = KONFIG

webPort = argv.p ? webserver.port

cluster = require 'cluster'

if cluster.isMaster
  cluster.fork() for i in [0...webserver.clusterSize]
  cluster.on "exit", (worker, code, signal) ->
    cluster.fork()
else

  processMonitor = (require 'processes-monitor').start
    name : "webServer on port #{webPort}"
    stats_id: "webserver." + process.pid
    interval : 30000
    limit_hard  :
      memory   : 300
      callback : ->
        console.log "[WEBSERVER #{webPort}] Using excessive memory, exiting."
        process.exit()
    die :
      after: "non-overlapping, random, 3 digits prime-number of minutes"
      middleware : (name,callback) -> koding.disconnect callback
      middlewareTimeout : 5000
    librato: KONFIG.librato

  # Services
  services = 
    webserver: 0
    worker_auth: 0
    worker_social: 0
    kite_webterm: 0
    kite_sharedhosting: 0
    kite_databases: 0
    kite_applications: 0

  # Presences
  koding = require './bongo'
  koding.connect ->
    koding.monitorPresence
      join: (serviceKey) ->
        if serviceKey.indexOf('webterm') > -1
          services.kite_webterm++
        else if serviceKey.indexOf('auth') > -1
          services.worker_auth++
        else if serviceKey.indexOf('kite-sharedHosting') > -1
          services.kite_sharedhosting++
        else if serviceKey.indexOf('kite-application') > -1
          services.kite_applications++
        else if serviceKey.indexOf('kite-database') > -1
          services.kite_databases++
        else if serviceKey.indexOf('web') > -1
          services.webserver++
        else if serviceKey.indexOf('social') > -1
          services.worker_social++
      leave: (serviceKey) ->
        if serviceKey.indexOf('webterm') > -1
          services.kite_webterm--
        else if serviceKey.indexOf('auth') > -1
          services.worker_auth--
        else if serviceKey.indexOf('kite-sharedHosting') > -1
          services.kite_sharedhosting--
        else if serviceKey.indexOf('kite-application') > -1
          services.kite_applications--
        else if serviceKey.indexOf('kite-database') > -1
          services.kite_databases--
        else if serviceKey.indexOf('web') > -1
          services.webserver--
        else if serviceKey.indexOf('social') > -1
          services.worker_social--

  {extend} = require 'underscore'
  express = require 'express'
  Broker = require 'broker'
  fs = require 'fs'
  hat = require 'hat'
{'fraction_non_alphanumeric': 0.1177281499862145, 'fraction_numerical': 0.013509787703336091, 'mean_word_length': 2.721025641025641, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5192163', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1110, 'n_words': 276}