Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[doc] Added docco docs

  • Loading branch information...
commit 7b981aa3ebf13f316d2ed04435192da9e3ba2d7e 1 parent 9c7c6ec
Charlie Robbins indexzero authored
194 docs/docco.css
View
@@ -0,0 +1,194 @@
+/*--------------------- Layout and Typography ----------------------------*/
+body {
+ font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
+ font-size: 15px;
+ line-height: 22px;
+ color: #252519;
+ margin: 0; padding: 0;
+}
+a {
+ color: #261a3b;
+}
+ a:visited {
+ color: #261a3b;
+ }
+p {
+ margin: 0 0 15px 0;
+}
+h4, h5, h6 {
+ color: #333;
+ margin: 6px 0 6px 0;
+ font-size: 13px;
+}
+ h2, h3 {
+ margin-bottom: 0;
+ color: #000;
+ }
+ h1 {
+ margin-top: 40px;
+ margin-bottom: 15px;
+ color: #000;
+ }
+#container {
+ position: relative;
+}
+#background {
+ position: fixed;
+ top: 0; left: 525px; right: 0; bottom: 0;
+ background: #f5f5ff;
+ border-left: 1px solid #e5e5ee;
+ z-index: -1;
+}
+#jump_to, #jump_page {
+ background: white;
+ -webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
+ -webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px;
+ font: 10px Arial;
+ text-transform: uppercase;
+ cursor: pointer;
+ text-align: right;
+}
+#jump_to, #jump_wrapper {
+ position: fixed;
+ right: 0; top: 0;
+ padding: 5px 10px;
+}
+ #jump_wrapper {
+ padding: 0;
+ display: none;
+ }
+ #jump_to:hover #jump_wrapper {
+ display: block;
+ }
+ #jump_page {
+ padding: 5px 0 3px;
+ margin: 0 0 25px 25px;
+ }
+ #jump_page .source {
+ display: block;
+ padding: 5px 10px;
+ text-decoration: none;
+ border-top: 1px solid #eee;
+ }
+ #jump_page .source:hover {
+ background: #f5f5ff;
+ }
+ #jump_page .source:first-child {
+ }
+table td {
+ border: 0;
+ outline: 0;
+}
+ td.docs, th.docs {
+ max-width: 450px;
+ min-width: 450px;
+ min-height: 5px;
+ padding: 10px 25px 1px 50px;
+ overflow-x: hidden;
+ vertical-align: top;
+ text-align: left;
+ }
+ .docs pre {
+ margin: 15px 0 15px;
+ padding-left: 15px;
+ }
+ .docs p tt, .docs p code {
+ background: #f8f8ff;
+ border: 1px solid #dedede;
+ font-size: 12px;
+ padding: 0 0.2em;
+ }
+ .pilwrap {
+ position: relative;
+ }
+ .pilcrow {
+ font: 12px Arial;
+ text-decoration: none;
+ color: #454545;
+ position: absolute;
+ top: 3px; left: -20px;
+ padding: 1px 2px;
+ opacity: 0;
+ -webkit-transition: opacity 0.2s linear;
+ }
+ td.docs:hover .pilcrow {
+ opacity: 1;
+ }
+ td.code, th.code {
+ padding: 14px 15px 16px 25px;
+ width: 100%;
+ vertical-align: top;
+ background: #f5f5ff;
+ border-left: 1px solid #e5e5ee;
+ }
+ pre, tt, code {
+ font-size: 12px; line-height: 18px;
+ font-family: Menlo, Monaco, Consolas, "Lucida Console", monospace;
+ margin: 0; padding: 0;
+ }
+
+
+/*---------------------- Syntax Highlighting -----------------------------*/
+td.linenos { background-color: #f0f0f0; padding-right: 10px; }
+span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
+body .hll { background-color: #ffffcc }
+body .c { color: #408080; font-style: italic } /* Comment */
+body .err { border: 1px solid #FF0000 } /* Error */
+body .k { color: #954121 } /* Keyword */
+body .o { color: #666666 } /* Operator */
+body .cm { color: #408080; font-style: italic } /* Comment.Multiline */
+body .cp { color: #BC7A00 } /* Comment.Preproc */
+body .c1 { color: #408080; font-style: italic } /* Comment.Single */
+body .cs { color: #408080; font-style: italic } /* Comment.Special */
+body .gd { color: #A00000 } /* Generic.Deleted */
+body .ge { font-style: italic } /* Generic.Emph */
+body .gr { color: #FF0000 } /* Generic.Error */
+body .gh { color: #000080; font-weight: bold } /* Generic.Heading */
+body .gi { color: #00A000 } /* Generic.Inserted */
+body .go { color: #808080 } /* Generic.Output */
+body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
+body .gs { font-weight: bold } /* Generic.Strong */
+body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
+body .gt { color: #0040D0 } /* Generic.Traceback */
+body .kc { color: #954121 } /* Keyword.Constant */
+body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */
+body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */
+body .kp { color: #954121 } /* Keyword.Pseudo */
+body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */
+body .kt { color: #B00040 } /* Keyword.Type */
+body .m { color: #666666 } /* Literal.Number */
+body .s { color: #219161 } /* Literal.String */
+body .na { color: #7D9029 } /* Name.Attribute */
+body .nb { color: #954121 } /* Name.Builtin */
+body .nc { color: #0000FF; font-weight: bold } /* Name.Class */
+body .no { color: #880000 } /* Name.Constant */
+body .nd { color: #AA22FF } /* Name.Decorator */
+body .ni { color: #999999; font-weight: bold } /* Name.Entity */
+body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
+body .nf { color: #0000FF } /* Name.Function */
+body .nl { color: #A0A000 } /* Name.Label */
+body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
+body .nt { color: #954121; font-weight: bold } /* Name.Tag */
+body .nv { color: #19469D } /* Name.Variable */
+body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
+body .w { color: #bbbbbb } /* Text.Whitespace */
+body .mf { color: #666666 } /* Literal.Number.Float */
+body .mh { color: #666666 } /* Literal.Number.Hex */
+body .mi { color: #666666 } /* Literal.Number.Integer */
+body .mo { color: #666666 } /* Literal.Number.Oct */
+body .sb { color: #219161 } /* Literal.String.Backtick */
+body .sc { color: #219161 } /* Literal.String.Char */
+body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */
+body .s2 { color: #219161 } /* Literal.String.Double */
+body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
+body .sh { color: #219161 } /* Literal.String.Heredoc */
+body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
+body .sx { color: #954121 } /* Literal.String.Other */
+body .sr { color: #BB6688 } /* Literal.String.Regex */
+body .s1 { color: #219161 } /* Literal.String.Single */
+body .ss { color: #19469D } /* Literal.String.Symbol */
+body .bp { color: #954121 } /* Name.Builtin.Pseudo */
+body .vc { color: #19469D } /* Name.Variable.Class */
+body .vg { color: #19469D } /* Name.Variable.Global */
+body .vi { color: #19469D } /* Name.Variable.Instance */
+body .il { color: #666666 } /* Literal.Number.Integer.Long */
54 docs/haibu.html
View
@@ -0,0 +1,54 @@
+<!DOCTYPE html> <html> <head> <title>haibu.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="haibu/balancer/balancer.html"> haibu/balancer/balancer.html </a> <a class="source" href="haibu/balancer/index.html"> haibu/balancer/index.html </a> <a class="source" href="haibu/core/config.html"> haibu/core/config.html </a> <a class="source" href="haibu/core/process-store.html"> haibu/core/process-store.html </a> <a class="source" href="haibu/core/spawner.html"> haibu/core/spawner.html </a> <a class="source" href="haibu/drone/client.html"> haibu/drone/client.html </a> <a class="source" href="haibu/drone/drone.html"> haibu/drone/drone.html </a> <a class="source" href="haibu/drone/index.html"> haibu/drone/index.html </a> <a class="source" href="haibu/drone/service.html"> haibu/drone/service.html </a> <a class="source" href="haibu/plugins/changelog.html"> haibu/plugins/changelog.html </a> <a class="source" href="haibu/plugins/chroot.html"> haibu/plugins/chroot.html </a> <a class="source" href="haibu/plugins/logger.html"> haibu/plugins/logger.html </a> <a class="source" href="haibu/repositories/git.html"> haibu/repositories/git.html </a> <a class="source" href="haibu/repositories/index.html"> haibu/repositories/index.html </a> <a class="source" href="haibu/repositories/local-file.html"> haibu/repositories/local-file.html </a> <a class="source" href="haibu/repositories/npm.html"> haibu/repositories/npm.html </a> <a class="source" href="haibu/repositories/remote-file.html"> haibu/repositories/remote-file.html </a> <a class="source" href="haibu/repositories/repository.html"> haibu/repositories/repository.html </a> <a class="source" href="haibu/repositories/tar.html"> haibu/repositories/tar.html </a> <a class="source" href="haibu/repositories/zip.html"> haibu/repositories/zip.html </a> <a class="source" href="haibu/utils/base64.html"> haibu/utils/base64.html </a> <a class="source" href="haibu/utils/bin.html"> haibu/utils/bin.html </a> <a class="source" href="haibu/utils/index.html"> haibu/utils/index.html </a> <a class="source" href="haibu.html"> haibu.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> haibu.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
+<span class="cm"> * haibu.js: Top level include for the haibu module</span>
+<span class="cm"> *</span>
+<span class="cm"> * (C) 2010, Nodejitsu Inc.</span>
+<span class="cm"> *</span>
+<span class="cm"> */</span>
+
+<span class="kd">var</span> <span class="nx">fs</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;fs&#39;</span><span class="p">),</span>
+ <span class="nx">events</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;events&#39;</span><span class="p">);</span>
+
+<span class="nx">require</span><span class="p">.</span><span class="nx">paths</span><span class="p">.</span><span class="nx">unshift</span><span class="p">(</span><span class="nx">__dirname</span><span class="p">);</span>
+
+<span class="kd">var</span> <span class="nx">haibu</span> <span class="o">=</span> <span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">events</span><span class="p">.</span><span class="nx">EventEmitter</span><span class="p">();</span>
+
+<span class="nx">haibu</span><span class="p">.</span><span class="nx">config</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;haibu/core/config&#39;</span><span class="p">);</span>
+<span class="nx">haibu</span><span class="p">.</span><span class="nx">utils</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;haibu/utils&#39;</span><span class="p">);</span>
+<span class="nx">haibu</span><span class="p">.</span><span class="nx">Spawner</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;haibu/core/spawner&#39;</span><span class="p">).</span><span class="nx">Spawner</span><span class="p">;</span>
+<span class="nx">haibu</span><span class="p">.</span><span class="nx">ProcessStore</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;haibu/core/process-store&#39;</span><span class="p">).</span><span class="nx">ProcessStore</span><span class="p">;</span>
+<span class="nx">haibu</span><span class="p">.</span><span class="nx">repository</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;haibu/repositories&#39;</span><span class="p">);</span>
+<span class="nx">haibu</span><span class="p">.</span><span class="nx">drone</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;haibu/drone&#39;</span><span class="p">);</span>
+<span class="nx">haibu</span><span class="p">.</span><span class="nx">balancer</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;haibu/balancer&#39;</span><span class="p">);</span>
+<span class="nx">haibu</span><span class="p">.</span><span class="nx">initialized</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
+<span class="nx">haibu</span><span class="p">.</span><span class="nx">plugins</span> <span class="o">=</span> <span class="p">{};</span>
+<span class="nx">haibu</span><span class="p">.</span><span class="nx">_plugins</span> <span class="o">=</span> <span class="p">{};</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>function init (options, callback)
+Initializes haibu directories and models</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">haibu</span><span class="p">.</span><span class="nx">init</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">haibu</span><span class="p">.</span><span class="nx">initialized</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">callback</span><span class="p">();</span>
+ <span class="p">}</span>
+
+ <span class="nx">haibu</span><span class="p">.</span><span class="nx">config</span><span class="p">.</span><span class="nx">load</span><span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">haibu</span><span class="p">.</span><span class="nx">utils</span><span class="p">.</span><span class="nx">initDirectories</span><span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="nx">haibu</span><span class="p">.</span><span class="nx">initialized</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="nx">callback</span><span class="p">();</span>
+ <span class="p">});</span>
+ <span class="p">});</span>
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <h3>function use (plugin)</h3>
+
+<h4>@plugin {Object} Instance of a plugin from <code>haibu.plugins</code></h4>
+
+<p>Adds the specified <code>plugin</code> to the set of active plugins used by haibu.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">haibu</span><span class="p">.</span><span class="nx">use</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">plugin</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">args</span> <span class="o">=</span> <span class="nb">Array</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">slice</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">arguments</span><span class="p">),</span>
+ <span class="nx">callback</span> <span class="o">=</span> <span class="k">typeof</span> <span class="nx">args</span><span class="p">[</span><span class="nx">args</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">===</span> <span class="s1">&#39;function&#39;</span> <span class="o">&amp;&amp;</span> <span class="nx">args</span><span class="p">.</span><span class="nx">pop</span><span class="p">(),</span>
+ <span class="nx">options</span> <span class="o">=</span> <span class="nx">args</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="o">&amp;&amp;</span> <span class="nx">args</span><span class="p">.</span><span class="nx">pop</span><span class="p">();</span>
+
+ <span class="nx">haibu</span><span class="p">.</span><span class="nx">_plugins</span><span class="p">[</span><span class="nx">plugin</span><span class="p">.</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="nx">plugin</span><span class="p">;</span>
+ <span class="nx">plugin</span><span class="p">.</span><span class="nx">init</span><span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Define each of our plugins as a lazy loaded <code>require</code> statement</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">fs</span><span class="p">.</span><span class="nx">readdirSync</span><span class="p">(</span><span class="nx">__dirname</span> <span class="o">+</span> <span class="s1">&#39;/haibu/plugins&#39;</span><span class="p">).</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">plugin</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">plugin</span> <span class="o">=</span> <span class="nx">plugin</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="s1">&#39;.js&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">);</span>
+ <span class="nx">haibu</span><span class="p">.</span><span class="nx">plugins</span><span class="p">.</span><span class="nx">__defineGetter__</span><span class="p">(</span><span class="nx">plugin</span><span class="p">,</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./haibu/plugins/&#39;</span> <span class="o">+</span> <span class="nx">plugin</span><span class="p">);</span>
+ <span class="p">});</span>
+<span class="p">});</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
227 docs/haibu/balancer/balancer.html
View
@@ -0,0 +1,227 @@
+<!DOCTYPE html> <html> <head> <title>balancer.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="../../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="../..//haibu/balancer/balancer.html"> haibu/balancer/balancer.html </a> <a class="source" href="../..//haibu/balancer/index.html"> haibu/balancer/index.html </a> <a class="source" href="../..//haibu/core/config.html"> haibu/core/config.html </a> <a class="source" href="../..//haibu/core/process-store.html"> haibu/core/process-store.html </a> <a class="source" href="../..//haibu/core/spawner.html"> haibu/core/spawner.html </a> <a class="source" href="../..//haibu/drone/client.html"> haibu/drone/client.html </a> <a class="source" href="../..//haibu/drone/drone.html"> haibu/drone/drone.html </a> <a class="source" href="../..//haibu/drone/index.html"> haibu/drone/index.html </a> <a class="source" href="../..//haibu/drone/service.html"> haibu/drone/service.html </a> <a class="source" href="../..//haibu/plugins/changelog.html"> haibu/plugins/changelog.html </a> <a class="source" href="../..//haibu/plugins/chroot.html"> haibu/plugins/chroot.html </a> <a class="source" href="../..//haibu/plugins/logger.html"> haibu/plugins/logger.html </a> <a class="source" href="../..//haibu/repositories/git.html"> haibu/repositories/git.html </a> <a class="source" href="../..//haibu/repositories/index.html"> haibu/repositories/index.html </a> <a class="source" href="../..//haibu/repositories/local-file.html"> haibu/repositories/local-file.html </a> <a class="source" href="../..//haibu/repositories/npm.html"> haibu/repositories/npm.html </a> <a class="source" href="../..//haibu/repositories/remote-file.html"> haibu/repositories/remote-file.html </a> <a class="source" href="../..//haibu/repositories/repository.html"> haibu/repositories/repository.html </a> <a class="source" href="../..//haibu/repositories/tar.html"> haibu/repositories/tar.html </a> <a class="source" href="../..//haibu/repositories/zip.html"> haibu/repositories/zip.html </a> <a class="source" href="../..//haibu/utils/base64.html"> haibu/utils/base64.html </a> <a class="source" href="../..//haibu/utils/bin.html"> haibu/utils/bin.html </a> <a class="source" href="../..//haibu/utils/index.html"> haibu/utils/index.html </a> <a class="source" href="../..//haibu.html"> haibu.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> balancer.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
+<span class="cm"> * proxy.js: Responsible for proxying across all applications available to haibu.</span>
+<span class="cm"> *</span>
+<span class="cm"> * (C) 2010, Nodejitsu Inc.</span>
+<span class="cm"> *</span>
+<span class="cm"> */</span>
+
+<span class="kd">var</span> <span class="nx">util</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;util&#39;</span><span class="p">),</span>
+ <span class="nx">path</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;path&#39;</span><span class="p">),</span>
+ <span class="nx">fs</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;fs&#39;</span><span class="p">),</span>
+ <span class="nx">events</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;events&#39;</span><span class="p">),</span>
+ <span class="nx">async</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;async&#39;</span><span class="p">),</span>
+ <span class="nx">colors</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;colors&#39;</span><span class="p">),</span>
+ <span class="nx">qs</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;querystring&#39;</span><span class="p">),</span>
+ <span class="nx">httpProxy</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;http-proxy&#39;</span><span class="p">),</span>
+ <span class="nx">haibu</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;haibu&#39;</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <h3>@matchers</h3>
+
+<p>Regular expression parsers for handling different
+persistent storage files used by <code>haibu</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">matchers</span> <span class="o">=</span> <span class="p">{</span>
+ <span class="nx">app</span><span class="o">:</span> <span class="sr">/^([\w|\-]+)\.package\.json/</span><span class="p">,</span>
+ <span class="nx">pid</span><span class="o">:</span> <span class="sr">/^([\w|\-]+)\.(\d+)\.json/</span>
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <h3>function Balancer (options)</h3>
+
+<h4>@options {Object} Options for this instance.</h4>
+
+<p>Constructor function for the <code>haibu</code> Balancer responsible
+for load balancing across all applications know to haibu on
+this machine.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">Balancer</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">Balancer</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">events</span><span class="p">.</span><span class="nx">EventEmitter</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="k">this</span><span class="p">);</span>
+
+ <span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
+ </pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Setup shared state and reverse-proxy using <code>node-http-proxy</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">active</span> <span class="o">=</span> <span class="p">{};</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">httpProxy</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">httpProxy</span><span class="p">.</span><span class="nx">HttpProxy</span><span class="p">(</span><span class="nx">options</span><span class="p">);</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">processes</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">haibu</span><span class="p">.</span><span class="nx">ProcessStore</span><span class="p">(</span><span class="nx">options</span><span class="p">);</span>
+ </pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Load files into Memory when they are found
+in the ProcessStore</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">processes</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s1">&#39;created&#39;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">file</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">self</span><span class="p">.</span><span class="nx">_add</span><span class="p">(</span><span class="nx">file</span><span class="p">,</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="nx">self</span><span class="p">.</span><span class="nx">emit</span><span class="p">(</span><span class="s1">&#39;created&#39;</span><span class="p">,</span> <span class="nx">file</span><span class="p">);</span>
+ <span class="p">});</span>
+ <span class="p">});</span>
+ </pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Remove files from the Balancer when they are removed
+from the ProcessStore.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">processes</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s1">&#39;removed&#39;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">file</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">self</span><span class="p">.</span><span class="nx">_remove</span><span class="p">(</span><span class="nx">file</span><span class="p">);</span>
+ <span class="nx">self</span><span class="p">.</span><span class="nx">emit</span><span class="p">(</span><span class="s1">&#39;removed&#39;</span><span class="p">,</span> <span class="nx">file</span><span class="p">);</span>
+ <span class="p">});</span>
+ </pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Load all relevant files on initial load.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">processes</span><span class="p">.</span><span class="nx">once</span><span class="p">(</span><span class="s1">&#39;load&#39;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">files</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">function</span> <span class="nx">checkFile</span> <span class="p">(</span><span class="nx">file</span><span class="p">,</span> <span class="nx">next</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">files</span><span class="p">[</span><span class="nx">file</span><span class="p">].</span><span class="nx">isFile</span><span class="p">()</span> <span class="o">?</span> <span class="nx">self</span><span class="p">.</span><span class="nx">_add</span><span class="p">(</span><span class="nx">file</span><span class="p">,</span> <span class="nx">next</span><span class="p">)</span> <span class="o">:</span> <span class="nx">next</span><span class="p">();</span>
+ <span class="p">}</span>
+
+ <span class="nx">async</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">files</span><span class="p">),</span> <span class="nx">checkFile</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">err</span> <span class="o">?</span> <span class="nx">self</span><span class="p">.</span><span class="nx">emit</span><span class="p">(</span><span class="s1">&#39;error&#39;</span><span class="p">,</span> <span class="nx">err</span><span class="p">)</span> <span class="o">:</span> <span class="nx">self</span><span class="p">.</span><span class="nx">emit</span><span class="p">(</span><span class="s1">&#39;ready&#39;</span><span class="p">,</span> <span class="nx">self</span><span class="p">.</span><span class="nx">active</span><span class="p">);</span>
+ <span class="p">});</span>
+ <span class="p">})</span>
+ </pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Start monitoring for process files.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">processes</span><span class="p">.</span><span class="nx">monitor</span><span class="p">();</span>
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>Inherit from <code>events.EventEmitter</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">util</span><span class="p">.</span><span class="nx">inherits</span><span class="p">(</span><span class="nx">Balancer</span><span class="p">,</span> <span class="nx">events</span><span class="p">.</span><span class="nx">EventEmitter</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <h3>function handle (req, res)</h3>
+
+<h4>@req {ServerRequest} Incoming server request to balancer</h4>
+
+<h4>@res {ServerResponse} Outoing server request to write to.</h4>
+
+<p>Attempts to proxy the incoming request to the specified application
+by using the <code>req.headers.host</code> property.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Balancer</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">handle</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">req</span><span class="p">,</span> <span class="nx">res</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">record</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">findDrone</span><span class="p">(</span><span class="nx">req</span><span class="p">),</span> <span class="nx">drone</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">record</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">serveText</span><span class="p">(</span><span class="nx">req</span><span class="p">,</span> <span class="nx">res</span><span class="p">,</span> <span class="p">{</span>
+ <span class="nx">code</span><span class="o">:</span> <span class="mi">400</span><span class="p">,</span>
+ <span class="nx">message</span><span class="o">:</span> <span class="s1">&#39;Application not found for: &#39;</span> <span class="o">+</span> <span class="nx">req</span><span class="p">.</span><span class="nx">headers</span><span class="p">.</span><span class="nx">host</span>
+ <span class="p">});</span>
+ <span class="p">}</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">record</span><span class="p">.</span><span class="nx">drones</span> <span class="o">||</span> <span class="nx">record</span><span class="p">.</span><span class="nx">drones</span><span class="p">.</span><span class="nx">length</span> <span class="o">===</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">serveText</span><span class="p">(</span><span class="nx">req</span><span class="p">,</span> <span class="nx">res</span><span class="p">,</span> <span class="p">{</span>
+ <span class="nx">code</span><span class="o">:</span> <span class="mi">400</span><span class="p">,</span>
+ <span class="nx">message</span><span class="o">:</span> <span class="s1">&#39;No drones for: &#39;</span> <span class="o">+</span> <span class="nx">req</span><span class="p">.</span><span class="nx">headers</span><span class="p">.</span><span class="nx">host</span>
+ <span class="p">});</span>
+ <span class="p">}</span>
+
+ <span class="nx">drone</span> <span class="o">=</span> <span class="nx">record</span><span class="p">.</span><span class="nx">drones</span><span class="p">.</span><span class="nx">shift</span><span class="p">();</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">httpProxy</span><span class="p">.</span><span class="nx">proxyRequest</span><span class="p">(</span><span class="nx">req</span><span class="p">,</span> <span class="nx">res</span><span class="p">,</span> <span class="nx">drone</span><span class="p">);</span>
+ <span class="nx">record</span><span class="p">.</span><span class="nx">drones</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">drone</span><span class="p">);</span>
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <h3>function findDrone (req)</h3>
+
+<h4>@req {ServerRequest} Incoming server request to find drones against</h4>
+
+<p>Attempts to find a drone for the incoming server request
+by cross-referencing <code>req.headers.host</code> against the <code>domain</code>
+or <code>domains</code> property of each application known to <code>haibu</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Balancer</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">findDrone</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">req</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">,</span>
+ <span class="nx">host</span> <span class="o">=</span> <span class="nx">req</span><span class="p">.</span><span class="nx">headers</span><span class="p">.</span><span class="nx">host</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">),</span>
+ <span class="nx">domain</span> <span class="o">=</span> <span class="nx">host</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">);</span>
+
+ <span class="k">return</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">active</span><span class="p">).</span><span class="nx">map</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">app</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">self</span><span class="p">.</span><span class="nx">active</span><span class="p">[</span><span class="nx">app</span><span class="p">];</span>
+ <span class="p">}).</span><span class="nx">filter</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">rec</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">rec</span><span class="p">.</span><span class="nx">app</span><span class="p">.</span><span class="nx">domain</span> <span class="o">===</span> <span class="nx">domain</span> <span class="o">||</span> <span class="p">(</span><span class="nx">rec</span><span class="p">.</span><span class="nx">app</span><span class="p">.</span><span class="nx">domains</span>
+ <span class="o">&amp;&amp;</span> <span class="nx">rec</span><span class="p">.</span><span class="nx">app</span><span class="p">.</span><span class="nx">domains</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">domain</span><span class="p">)</span> <span class="o">!==</span> <span class="o">-</span><span class="mi">1</span><span class="p">);</span>
+ <span class="p">})[</span><span class="mi">0</span><span class="p">];</span>
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <h3>function serveText (req, res, data)</h3>
+
+<h4>@req {ServerRequest} Incoming server request</h4>
+
+<h4>@res {ServerResponse} Outoing server request to write to.</h4>
+
+<p>Writes <code>data.message</code> to the outgoing <code>res</code> along with any
+metadata passed as <code>data.meta</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Balancer</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">serveText</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">req</span><span class="p">,</span> <span class="nx">res</span><span class="p">,</span> <span class="nx">data</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">text</span> <span class="o">=</span> <span class="nx">data</span><span class="p">.</span><span class="nx">message</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="nx">data</span><span class="p">.</span><span class="nx">meta</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">text</span> <span class="o">=</span> <span class="p">[</span><span class="nx">message</span><span class="p">,</span> <span class="nx">qs</span><span class="p">.</span><span class="nx">unescape</span><span class="p">(</span><span class="nx">qs</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">data</span><span class="p">.</span><span class="nx">meta</span><span class="p">,</span> <span class="s1">&#39;, &#39;</span><span class="p">))].</span><span class="nx">join</span><span class="p">(</span><span class="s1">&#39; | &#39;</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="nx">res</span><span class="p">.</span><span class="nx">writeHead</span><span class="p">(</span><span class="nx">data</span><span class="p">.</span><span class="nx">code</span><span class="p">,</span> <span class="p">{</span>
+ <span class="s1">&#39;Content-Length&#39;</span><span class="o">:</span> <span class="nx">data</span><span class="p">.</span><span class="nx">length</span><span class="p">,</span>
+ <span class="s1">&#39;Content-Type&#39;</span><span class="o">:</span> <span class="s1">&#39;text/plain&#39;</span>
+ <span class="p">});</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="nx">req</span><span class="p">.</span><span class="nx">method</span> <span class="o">!==</span> <span class="s1">&#39;HEAD&#39;</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">res</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="nx">text</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="nx">res</span><span class="p">.</span><span class="nx">end</span><span class="p">();</span>
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <h3>function close ()</h3>
+
+<p>Closes this balancer by shutting down the child
+<code>HttpProxy</code> instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Balancer</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">close</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">httpProxy</span><span class="p">.</span><span class="nx">close</span><span class="p">();</span>
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <h3>function _add (file, callback)</h3>
+
+<h4>@file {string} Filename to add to this instance.</h4>
+
+<h4>@callback {function} <strong>Optional</strong> Continuation to respond to when complete.</h4>
+
+<p>Adds the data in the specified <code>file</code> to the managed state for
+this balancer instance. </p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Balancer</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_add</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">file</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
+
+ <span class="nx">fs</span><span class="p">.</span><span class="nx">readFile</span><span class="p">(</span><span class="nx">file</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">data</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">callback</span> <span class="o">?</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="o">:</span> <span class="kc">null</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="k">try</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">json</span> <span class="o">=</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">data</span><span class="p">.</span><span class="nx">toString</span><span class="p">()),</span>
+ <span class="nx">app</span> <span class="o">=</span> <span class="nx">self</span><span class="p">.</span><span class="nx">_parseFilename</span><span class="p">(</span><span class="nx">file</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="nx">app</span> <span class="o">&amp;&amp;</span> <span class="nx">app</span><span class="p">.</span><span class="nx">type</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">switch</span> <span class="p">(</span><span class="nx">app</span><span class="p">.</span><span class="nx">type</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">case</span> <span class="s1">&#39;package&#39;</span><span class="o">:</span>
+ <span class="nx">self</span><span class="p">.</span><span class="nx">active</span><span class="p">[</span><span class="nx">app</span><span class="p">.</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="nx">self</span><span class="p">.</span><span class="nx">active</span><span class="p">[</span><span class="nx">app</span><span class="p">.</span><span class="nx">name</span><span class="p">]</span> <span class="o">||</span> <span class="p">{</span>
+ <span class="nx">drones</span><span class="o">:</span> <span class="p">[]</span>
+ <span class="p">};</span>
+
+ <span class="nx">self</span><span class="p">.</span><span class="nx">active</span><span class="p">[</span><span class="nx">app</span><span class="p">.</span><span class="nx">name</span><span class="p">].</span><span class="nx">app</span> <span class="o">=</span> <span class="nx">json</span><span class="p">;</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;pid&#39;</span><span class="o">:</span>
+ <span class="nx">self</span><span class="p">.</span><span class="nx">active</span><span class="p">[</span><span class="nx">app</span><span class="p">.</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="nx">self</span><span class="p">.</span><span class="nx">active</span><span class="p">[</span><span class="nx">app</span><span class="p">.</span><span class="nx">name</span><span class="p">]</span> <span class="o">||</span> <span class="p">{</span>
+ <span class="nx">drones</span><span class="o">:</span> <span class="p">[]</span>
+ <span class="p">};</span>
+
+ <span class="nx">self</span><span class="p">.</span><span class="nx">active</span><span class="p">[</span><span class="nx">app</span><span class="p">.</span><span class="nx">name</span><span class="p">].</span><span class="nx">drones</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span>
+ <span class="nx">pid</span><span class="o">:</span> <span class="nx">json</span><span class="p">.</span><span class="nx">pid</span><span class="p">,</span>
+ <span class="nx">host</span><span class="o">:</span> <span class="nx">json</span><span class="p">.</span><span class="nx">host</span><span class="p">,</span>
+ <span class="nx">port</span><span class="o">:</span> <span class="nx">json</span><span class="p">.</span><span class="nx">port</span>
+ <span class="p">});</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+
+ <span class="k">return</span> <span class="nx">callback</span> <span class="o">?</span> <span class="nx">callback</span><span class="p">()</span> <span class="o">:</span> <span class="kc">null</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="k">catch</span> <span class="p">(</span><span class="nx">ex</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">callback</span> <span class="o">?</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">ex</span><span class="p">)</span> <span class="o">:</span> <span class="kc">null</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="p">});</span>
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <h3>function _remove (file)</h3>
+
+<h4>@file {string} Filename to remove from this instance</h4>
+
+<p>Removes the data in the specified <code>file</code> from the managed state
+for this instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Balancer</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_remove</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">file</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">app</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_parseFilename</span><span class="p">(</span><span class="nx">file</span><span class="p">),</span> <span class="nx">index</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="nx">app</span> <span class="o">&amp;&amp;</span> <span class="nx">app</span><span class="p">.</span><span class="nx">type</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">switch</span> <span class="p">(</span><span class="nx">app</span><span class="p">.</span><span class="nx">type</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">case</span> <span class="s1">&#39;package&#39;</span><span class="o">:</span>
+ <span class="k">delete</span> <span class="k">this</span><span class="p">.</span><span class="nx">active</span><span class="p">[</span><span class="nx">app</span><span class="p">.</span><span class="nx">name</span><span class="p">];</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;pid&#39;</span><span class="o">:</span>
+ <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">active</span><span class="p">[</span><span class="nx">app</span><span class="p">.</span><span class="nx">name</span><span class="p">]</span> <span class="o">&amp;&amp;</span> <span class="k">this</span><span class="p">.</span><span class="nx">active</span><span class="p">[</span><span class="nx">app</span><span class="p">.</span><span class="nx">name</span><span class="p">].</span><span class="nx">drones</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">index</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">active</span><span class="p">[</span><span class="nx">app</span><span class="p">.</span><span class="nx">name</span><span class="p">].</span><span class="nx">drones</span><span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">d</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">d</span><span class="p">.</span><span class="nx">pid</span><span class="p">;</span>
+ <span class="p">}).</span><span class="nx">indexOf</span><span class="p">(</span><span class="nb">parseInt</span><span class="p">(</span><span class="nx">app</span><span class="p">.</span><span class="nx">drone</span><span class="p">,</span> <span class="mi">10</span><span class="p">));</span>
+
+ <span class="k">this</span><span class="p">.</span><span class="nx">active</span><span class="p">[</span><span class="nx">app</span><span class="p">.</span><span class="nx">name</span><span class="p">].</span><span class="nx">drones</span><span class="p">.</span><span class="nx">splice</span><span class="p">(</span><span class="nx">index</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <h3>function _parseFilename (file)</h3>
+
+<h4>@file {string} Filename to parse</h4>
+
+<p>Parses the data out of the specified <code>file</code> to be used
+in the managed application state for this instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Balancer</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_parseFilename</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">file</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">base</span> <span class="o">=</span> <span class="nx">path</span><span class="p">.</span><span class="nx">basename</span><span class="p">(</span><span class="nx">file</span><span class="p">),</span>
+ <span class="nx">match</span><span class="p">,</span> <span class="nx">drone</span><span class="p">,</span> <span class="nx">app</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="nx">matchers</span><span class="p">.</span><span class="nx">app</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">base</span><span class="p">))</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="p">{</span>
+ <span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;package&#39;</span><span class="p">,</span>
+ <span class="nx">name</span><span class="o">:</span> <span class="nx">base</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">matchers</span><span class="p">.</span><span class="nx">app</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">matchers</span><span class="p">.</span><span class="nx">pid</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">base</span><span class="p">))</span> <span class="p">{</span>
+ <span class="nx">match</span> <span class="o">=</span> <span class="nx">base</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">matchers</span><span class="p">.</span><span class="nx">pid</span><span class="p">);</span>
+ <span class="k">return</span> <span class="p">{</span>
+ <span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;pid&#39;</span><span class="p">,</span>
+ <span class="nx">name</span><span class="o">:</span> <span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
+ <span class="nx">drone</span><span class="o">:</span> <span class="nx">match</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
+ <span class="p">};</span>
+ <span class="p">}</span>
+
+ <span class="k">return</span> <span class="kc">null</span><span class="p">;</span>
+<span class="p">};</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
56 docs/haibu/balancer/index.html
View
@@ -0,0 +1,56 @@
+<!DOCTYPE html> <html> <head> <title>index.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="../../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="../..//haibu/balancer/balancer.html"> haibu/balancer/balancer.html </a> <a class="source" href="../..//haibu/balancer/index.html"> haibu/balancer/index.html </a> <a class="source" href="../..//haibu/core/config.html"> haibu/core/config.html </a> <a class="source" href="../..//haibu/core/process-store.html"> haibu/core/process-store.html </a> <a class="source" href="../..//haibu/core/spawner.html"> haibu/core/spawner.html </a> <a class="source" href="../..//haibu/drone/client.html"> haibu/drone/client.html </a> <a class="source" href="../..//haibu/drone/drone.html"> haibu/drone/drone.html </a> <a class="source" href="../..//haibu/drone/index.html"> haibu/drone/index.html </a> <a class="source" href="../..//haibu/drone/service.html"> haibu/drone/service.html </a> <a class="source" href="../..//haibu/plugins/changelog.html"> haibu/plugins/changelog.html </a> <a class="source" href="../..//haibu/plugins/chroot.html"> haibu/plugins/chroot.html </a> <a class="source" href="../..//haibu/plugins/logger.html"> haibu/plugins/logger.html </a> <a class="source" href="../..//haibu/repositories/git.html"> haibu/repositories/git.html </a> <a class="source" href="../..//haibu/repositories/index.html"> haibu/repositories/index.html </a> <a class="source" href="../..//haibu/repositories/local-file.html"> haibu/repositories/local-file.html </a> <a class="source" href="../..//haibu/repositories/npm.html"> haibu/repositories/npm.html </a> <a class="source" href="../..//haibu/repositories/remote-file.html"> haibu/repositories/remote-file.html </a> <a class="source" href="../..//haibu/repositories/repository.html"> haibu/repositories/repository.html </a> <a class="source" href="../..//haibu/repositories/tar.html"> haibu/repositories/tar.html </a> <a class="source" href="../..//haibu/repositories/zip.html"> haibu/repositories/zip.html </a> <a class="source" href="../..//haibu/utils/base64.html"> haibu/utils/base64.html </a> <a class="source" href="../..//haibu/utils/bin.html"> haibu/utils/bin.html </a> <a class="source" href="../..//haibu/utils/index.html"> haibu/utils/index.html </a> <a class="source" href="../..//haibu.html"> haibu.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> index.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
+<span class="cm"> * index.js: Responsible for balancing across all the instances available to haibu.</span>
+<span class="cm"> *</span>
+<span class="cm"> * (C) 2010, Nodejitsu Inc.</span>
+<span class="cm"> *</span>
+<span class="cm"> */</span>
+
+<span class="kd">var</span> <span class="nx">http</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;http&#39;</span><span class="p">),</span>
+ <span class="nx">haibu</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;haibu&#39;</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <h3>Include Exports</h3>
+
+<p>Export other components in the module</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">exports</span><span class="p">.</span><span class="nx">Balancer</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./balancer&#39;</span><span class="p">).</span><span class="nx">Balancer</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <h3>function createServer (options)</h3>
+
+<h4>@options {Object} Options to use when creating this server</h4>
+
+<p>Creates a server for the haibu <code>balancer</code> webservice. </p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">exports</span><span class="p">.</span><span class="nx">createServer</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="nx">balancer</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">balancer</span> <span class="o">=</span> <span class="nx">balancer</span> <span class="o">||</span> <span class="k">new</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">Balancer</span><span class="p">(</span><span class="nx">options</span><span class="p">);</span>
+
+ <span class="kd">var</span> <span class="nx">server</span> <span class="o">=</span> <span class="nx">http</span><span class="p">.</span><span class="nx">createServer</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">request</span><span class="p">,</span> <span class="nx">response</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">balancer</span><span class="p">.</span><span class="nx">handle</span><span class="p">(</span><span class="nx">request</span><span class="p">,</span> <span class="nx">response</span><span class="p">);</span>
+ <span class="p">});</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">port</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">server</span><span class="p">.</span><span class="nx">listen</span><span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">port</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="nx">balancer</span><span class="p">.</span><span class="nx">once</span><span class="p">(</span><span class="s1">&#39;ready&#39;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">active</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">server</span><span class="p">.</span><span class="nx">emit</span><span class="p">(</span><span class="s1">&#39;ready&#39;</span><span class="p">,</span> <span class="nx">active</span><span class="p">);</span>
+ <span class="p">});</span>
+
+ <span class="k">return</span> <span class="nx">server</span><span class="p">;</span>
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <h3>function start (options, callback)</h3>
+
+<h4>@options {Object} Options to use when starting this module.</h4>
+
+<h4>@callback {function} Continuation to respond to when complete.</h4>
+
+<p>Starts the haibu <code>balancer</code> webservice with the specified options.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">exports</span><span class="p">.</span><span class="nx">start</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">function</span> <span class="nx">startServer</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="kd">var</span> <span class="nx">balancer</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">Balancer</span><span class="p">(</span><span class="nx">options</span><span class="p">),</span>
+ <span class="nx">server</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">createServer</span><span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="nx">balancer</span><span class="p">);</span>
+
+ <span class="nx">balancer</span><span class="p">.</span><span class="nx">once</span><span class="p">(</span><span class="s1">&#39;ready&#39;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">active</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">server</span><span class="p">,</span> <span class="nx">balancer</span><span class="p">,</span> <span class="nx">active</span><span class="p">);</span>
+ <span class="p">});</span>
+ <span class="p">}</span>
+
+ <span class="k">return</span> <span class="nx">options</span><span class="p">.</span><span class="nx">init</span> <span class="o">===</span> <span class="kc">false</span>
+ <span class="o">?</span> <span class="nx">haibu</span><span class="p">.</span><span class="nx">init</span><span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="nx">startServer</span><span class="p">)</span>
+ <span class="o">:</span> <span class="nx">startServer</span><span class="p">();</span>
+<span class="p">};</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
184 docs/haibu/core/config.html
View
@@ -0,0 +1,184 @@
+<!DOCTYPE html> <html> <head> <title>config.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="../../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="../..//haibu/balancer/balancer.html"> haibu/balancer/balancer.html </a> <a class="source" href="../..//haibu/balancer/index.html"> haibu/balancer/index.html </a> <a class="source" href="../..//haibu/core/config.html"> haibu/core/config.html </a> <a class="source" href="../..//haibu/core/process-store.html"> haibu/core/process-store.html </a> <a class="source" href="../..//haibu/core/spawner.html"> haibu/core/spawner.html </a> <a class="source" href="../..//haibu/drone/client.html"> haibu/drone/client.html </a> <a class="source" href="../..//haibu/drone/drone.html"> haibu/drone/drone.html </a> <a class="source" href="../..//haibu/drone/index.html"> haibu/drone/index.html </a> <a class="source" href="../..//haibu/drone/service.html"> haibu/drone/service.html </a> <a class="source" href="../..//haibu/plugins/changelog.html"> haibu/plugins/changelog.html </a> <a class="source" href="../..//haibu/plugins/chroot.html"> haibu/plugins/chroot.html </a> <a class="source" href="../..//haibu/plugins/logger.html"> haibu/plugins/logger.html </a> <a class="source" href="../..//haibu/repositories/git.html"> haibu/repositories/git.html </a> <a class="source" href="../..//haibu/repositories/index.html"> haibu/repositories/index.html </a> <a class="source" href="../..//haibu/repositories/local-file.html"> haibu/repositories/local-file.html </a> <a class="source" href="../..//haibu/repositories/npm.html"> haibu/repositories/npm.html </a> <a class="source" href="../..//haibu/repositories/remote-file.html"> haibu/repositories/remote-file.html </a> <a class="source" href="../..//haibu/repositories/repository.html"> haibu/repositories/repository.html </a> <a class="source" href="../..//haibu/repositories/tar.html"> haibu/repositories/tar.html </a> <a class="source" href="../..//haibu/repositories/zip.html"> haibu/repositories/zip.html </a> <a class="source" href="../..//haibu/utils/base64.html"> haibu/utils/base64.html </a> <a class="source" href="../..//haibu/utils/bin.html"> haibu/utils/bin.html </a> <a class="source" href="../..//haibu/utils/index.html"> haibu/utils/index.html </a> <a class="source" href="../..//haibu.html"> haibu.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> config.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
+<span class="cm"> * index.js: Top level module include for config module.</span>
+<span class="cm"> *</span>
+<span class="cm"> * (C) 2010, Nodejitsu Inc.</span>
+<span class="cm"> *</span>
+<span class="cm"> */</span>
+
+<span class="kd">var</span> <span class="nx">fs</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;fs&#39;</span><span class="p">),</span>
+ <span class="nx">eyes</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;eyes&#39;</span><span class="p">),</span>
+ <span class="nx">path</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;path&#39;</span><span class="p">),</span>
+ <span class="nx">exec</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;child_process&#39;</span><span class="p">).</span><span class="nx">exec</span><span class="p">,</span>
+ <span class="nx">async</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;async&#39;</span><span class="p">),</span>
+ <span class="nx">nconf</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;nconf&#39;</span><span class="p">),</span>
+ <span class="nx">haibu</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;haibu&#39;</span><span class="p">);</span>
+
+<span class="kd">var</span> <span class="nx">root</span> <span class="o">=</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">__dirname</span><span class="p">,</span> <span class="s1">&#39;..&#39;</span><span class="p">,</span> <span class="s1">&#39;..&#39;</span><span class="p">,</span> <span class="s1">&#39;..&#39;</span><span class="p">),</span>
+ <span class="nx">config</span> <span class="o">=</span> <span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="nx">nconf</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <h3>function (options)</h3>
+
+<h4>@options {Object} Options to setup for flexibility</h4>
+
+<p>Sets up configuration options with default options for
+maximum flexibility in usage.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">setupOptions</span> <span class="p">(</span><span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">options</span> <span class="o">=</span> <span class="nx">options</span> <span class="o">||</span> <span class="p">{};</span>
+ <span class="nx">options</span><span class="p">.</span><span class="nx">env</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">env</span> <span class="o">||</span> <span class="s1">&#39;development&#39;</span><span class="p">;</span>
+ <span class="nx">options</span><span class="p">.</span><span class="nx">data</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">data</span> <span class="o">||</span> <span class="p">{};</span>
+ <span class="nx">options</span><span class="p">.</span><span class="nx">config</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">config</span> <span class="o">||</span> <span class="p">{};</span>
+ <span class="nx">options</span><span class="p">.</span><span class="nx">config</span><span class="p">.</span><span class="nx">files</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">config</span><span class="p">.</span><span class="nx">files</span> <span class="o">||</span> <span class="p">[];</span>
+ <span class="nx">options</span><span class="p">.</span><span class="nx">config</span><span class="p">.</span><span class="nx">namespace</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">config</span><span class="p">.</span><span class="nx">namespace</span> <span class="o">||</span> <span class="nx">options</span><span class="p">.</span><span class="nx">env</span><span class="p">;</span>
+ <span class="k">return</span> <span class="nx">options</span><span class="p">;</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <h3>Expose the simple routes for the haibu config API.</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nx">config</span><span class="p">.</span><span class="nx">addRoutes</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">map</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">map</span><span class="p">.</span><span class="nx">post</span><span class="p">(</span><span class="sr">/\/reload/</span><span class="p">).</span><span class="nx">bind</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">response</span><span class="p">,</span> <span class="nx">data</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p><strong>TODO: <em>(indexzero)</em></strong>: Ensure this request is authenticated.</p> </td> <td class="code"> <div class="highlight"><pre>
+ <span class="nx">data</span> <span class="o">=</span> <span class="nx">data</span><span class="p">.</span><span class="nx">config</span> <span class="o">?</span> <span class="nx">data</span> <span class="o">:</span> <span class="nx">haibu</span><span class="p">.</span><span class="nx">config</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;config&#39;</span><span class="p">);</span>
+ <span class="nx">haibu</span><span class="p">.</span><span class="nx">config</span><span class="p">.</span><span class="nx">load</span><span class="p">(</span><span class="nx">data</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">response</span><span class="p">.</span><span class="nx">send</span><span class="p">(</span><span class="mi">500</span><span class="p">,</span> <span class="p">{},</span> <span class="p">{</span> <span class="nx">error</span><span class="o">:</span> <span class="nx">err</span><span class="p">.</span><span class="nx">message</span> <span class="p">});</span>
+ <span class="p">}</span>
+
+ <span class="nx">response</span><span class="p">.</span><span class="nx">send</span><span class="p">(</span><span class="mi">200</span><span class="p">);</span>
+ <span class="p">});</span>
+ <span class="p">});</span>
+ <span class="p">};</span>
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <h3>function seed (options, callback)</h3>
+
+<h4>@options {Object} Options for nconf store.</h4>
+
+<h4>@callback {function} Continuation to respond to when complete.</h4>
+
+<p>Seeds any existing data from <code>options.files</code> into a Redis store
+for distributed use.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">config</span><span class="p">.</span><span class="nx">seed</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">callback</span> <span class="o">=</span> <span class="nx">options</span><span class="p">;</span>
+ <span class="nx">options</span> <span class="o">=</span> <span class="p">{};</span>
+ <span class="p">}</span>
+ </pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Setup <code>options</code> to be <em>really</em> flexible. </p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">options</span> <span class="o">=</span> <span class="nx">setupOptions</span><span class="p">(</span><span class="nx">options</span><span class="p">);</span>
+ <span class="kd">var</span> <span class="nx">store</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">nconf</span><span class="p">.</span><span class="nx">stores</span><span class="p">.</span><span class="nx">Redis</span><span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">config</span><span class="p">),</span> <span class="nx">keys</span><span class="p">;</span>
+
+ <span class="nx">config</span><span class="p">.</span><span class="nx">loadFiles</span><span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">config</span><span class="p">.</span><span class="nx">files</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">loaded</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="kd">function</span> <span class="nx">storeValue</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">next</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">store</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">options</span><span class="p">.</span><span class="nx">data</span><span class="p">[</span><span class="nx">key</span><span class="p">],</span> <span class="nx">next</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">loaded</span><span class="p">).</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">options</span><span class="p">.</span><span class="nx">data</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">loaded</span><span class="p">[</span><span class="nx">key</span><span class="p">];</span>
+ <span class="p">});</span>
+
+ <span class="kd">var</span> <span class="nx">keys</span> <span class="o">=</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">data</span><span class="p">);</span>
+ <span class="nx">async</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="nx">keys</span><span class="p">,</span> <span class="nx">storeValue</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="nx">store</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s1">&#39;loaded&#39;</span><span class="p">,</span> <span class="kc">true</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">store</span><span class="p">.</span><span class="nx">redis</span><span class="p">.</span><span class="nx">quit</span><span class="p">();</span>
+ <span class="k">return</span> <span class="nx">err</span> <span class="o">?</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="o">:</span> <span class="nx">callback</span><span class="p">();</span>
+ <span class="p">});</span>
+ <span class="p">});</span>
+ <span class="p">});</span>
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <h3>function load (options, callback)</h3>
+
+<h4>@options {Object} Options for nconf store.</h4>
+
+<h4>@callback {function} Continuation to respond to when complete.</h4>
+
+<p>Basically a complex version of <code>nconf.load</code> which will skip the <code>load</code>
+operation when using the memory engine instead of throwing an exception
+and always be async. Also loads any existing configuration from a remote
+Redis server into memory for usage with this process. </p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">config</span><span class="p">.</span><span class="nx">load</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">callback</span> <span class="o">=</span> <span class="nx">options</span><span class="p">;</span>
+ <span class="nx">options</span> <span class="o">=</span> <span class="p">{};</span>
+ <span class="p">}</span>
+ </pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Setup <code>options</code> to be <em>really</em> flexible. </p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">options</span> <span class="o">=</span> <span class="nx">setupOptions</span><span class="p">(</span><span class="nx">options</span><span class="p">);</span>
+
+ <span class="kd">function</span> <span class="nx">setObject</span> <span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">obj</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">obj</span><span class="p">).</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">config</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">obj</span><span class="p">[</span><span class="nx">key</span><span class="p">]);</span>
+ <span class="p">});</span>
+ <span class="p">}</span>
+
+ <span class="kd">function</span> <span class="nx">loadRemote</span> <span class="p">()</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>Load the haibu configuration, then extend it with extra information
+read from the nodejitsu config.json.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">store</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">nconf</span><span class="p">.</span><span class="nx">stores</span><span class="p">.</span><span class="nx">Redis</span><span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">config</span><span class="p">);</span>
+ <span class="nx">store</span><span class="p">.</span><span class="nx">load</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">remote</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Shutdown the temporary Redis store. </p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">store</span><span class="p">.</span><span class="nx">redis</span><span class="p">.</span><span class="nx">quit</span><span class="p">();</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>Handle errors appropriately</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">remote</span><span class="p">.</span><span class="nx">loaded</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">config</span><span class="p">.</span><span class="nx">seed</span><span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">err</span> <span class="o">?</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="o">:</span> <span class="nx">config</span><span class="p">.</span><span class="nx">load</span><span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
+ <span class="p">});</span>
+ <span class="p">}</span>
+ </pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>Set the cache information in the current Memory store. </p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">config</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s1">&#39;cache&#39;</span><span class="p">,</span> <span class="p">{</span>
+ <span class="nx">host</span><span class="o">:</span> <span class="nx">options</span><span class="p">.</span><span class="nx">config</span><span class="p">.</span><span class="nx">host</span><span class="p">,</span>
+ <span class="nx">port</span><span class="o">:</span> <span class="nx">options</span><span class="p">.</span><span class="nx">config</span><span class="p">.</span><span class="nx">port</span> <span class="o">||</span> <span class="mi">6379</span><span class="p">,</span>
+ <span class="nx">auth</span><span class="o">:</span> <span class="nx">options</span><span class="p">.</span><span class="nx">config</span><span class="p">.</span><span class="nx">auth</span>
+ <span class="p">});</span>
+ </pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <p>Add any existing remote configuration to the current Memory store.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">setObject</span><span class="p">(</span><span class="nx">remote</span><span class="p">);</span>
+
+ <span class="nx">callback</span><span class="p">();</span>
+ <span class="p">});</span>
+ <span class="p">}</span>
+
+ <span class="kd">function</span> <span class="nx">loadAll</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">local</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">setObject</span><span class="p">(</span><span class="nx">local</span><span class="p">);</span>
+ <span class="k">return</span> <span class="nx">options</span><span class="p">.</span><span class="nx">config</span><span class="p">.</span><span class="nx">host</span> <span class="o">?</span> <span class="nx">loadRemote</span><span class="p">()</span> <span class="o">:</span> <span class="nx">callback</span><span class="p">();</span>
+ <span class="p">}</span>
+
+ <span class="k">return</span> <span class="nx">options</span><span class="p">.</span><span class="nx">config</span><span class="p">.</span><span class="nx">files</span>
+ <span class="o">?</span> <span class="nx">config</span><span class="p">.</span><span class="nx">loadFiles</span><span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">config</span><span class="p">.</span><span class="nx">files</span><span class="p">,</span> <span class="nx">loadAll</span><span class="p">)</span>
+ <span class="o">:</span> <span class="nx">loadAll</span><span class="p">();</span>
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <h3>function loadFiles (files)</h3>
+
+<h4>@files {Array} List of files to load.</h4>
+
+<p>Loads all the data in the specified <code>files</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">config</span><span class="p">.</span><span class="nx">loadFiles</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">files</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">files</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="p">{});</span>
+ <span class="p">}</span>
+
+ <span class="kd">var</span> <span class="nx">allData</span> <span class="o">=</span> <span class="p">{};</span>
+
+ <span class="kd">function</span> <span class="nx">loadFile</span> <span class="p">(</span><span class="nx">file</span><span class="p">,</span> <span class="nx">next</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">fs</span><span class="p">.</span><span class="nx">readFile</span><span class="p">(</span><span class="nx">file</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">data</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">next</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="nx">data</span> <span class="o">=</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">data</span><span class="p">.</span><span class="nx">toString</span><span class="p">());</span>
+ <span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">data</span><span class="p">).</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">allData</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">data</span><span class="p">[</span><span class="nx">key</span><span class="p">];</span>
+ <span class="p">});</span>
+
+ <span class="nx">next</span><span class="p">();</span>
+ <span class="p">});</span>
+ <span class="p">}</span>
+
+ <span class="nx">async</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="nx">files</span><span class="p">,</span> <span class="nx">loadFile</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">err</span> <span class="o">?</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="o">:</span> <span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">allData</span><span class="p">);</span>
+ <span class="p">});</span>
+<span class="p">};</span>
+
+<span class="nx">config</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s1">&#39;directories&#39;</span><span class="p">,</span> <span class="p">{</span>
+ <span class="nx">apps</span><span class="o">:</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">root</span><span class="p">,</span> <span class="s1">&#39;local&#39;</span><span class="p">),</span>
+ <span class="nx">log</span><span class="o">:</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">root</span><span class="p">,</span> <span class="s1">&#39;log&#39;</span><span class="p">),</span>
+ <span class="nx">packages</span><span class="o">:</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">root</span><span class="p">,</span> <span class="s1">&#39;packages&#39;</span><span class="p">),</span>
+ <span class="nx">running</span><span class="o">:</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">root</span><span class="p">,</span> <span class="s1">&#39;running&#39;</span><span class="p">),</span>
+ <span class="nx">tmp</span><span class="o">:</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">root</span><span class="p">,</span> <span class="s1">&#39;tmp&#39;</span><span class="p">)</span>
+<span class="p">});</span>
+
+<span class="nx">config</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s1">&#39;npm&#39;</span><span class="p">,</span> <span class="p">{</span>
+ <span class="nx">log</span><span class="o">:</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">root</span><span class="p">,</span> <span class="s1">&#39;log&#39;</span><span class="p">,</span> <span class="s1">&#39;npm.log&#39;</span><span class="p">),</span>
+ <span class="nx">out</span><span class="o">:</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">root</span><span class="p">,</span> <span class="s1">&#39;log&#39;</span><span class="p">,</span> <span class="s1">&#39;npm.out&#39;</span><span class="p">)</span>
+<span class="p">});</span>
+
+<span class="nx">config</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s1">&#39;requiredNodeVersion&#39;</span><span class="p">,</span> <span class="s1">&#39;0.4.5&#39;</span><span class="p">);</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
82 docs/haibu/core/process-store.html
View
@@ -0,0 +1,82 @@
+<!DOCTYPE html> <html> <head> <title>process-store.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="../../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="../..//haibu/balancer/balancer.html"> haibu/balancer/balancer.html </a> <a class="source" href="../..//haibu/balancer/index.html"> haibu/balancer/index.html </a> <a class="source" href="../..//haibu/core/config.html"> haibu/core/config.html </a> <a class="source" href="../..//haibu/core/process-store.html"> haibu/core/process-store.html </a> <a class="source" href="../..//haibu/core/spawner.html"> haibu/core/spawner.html </a> <a class="source" href="../..//haibu/drone/client.html"> haibu/drone/client.html </a> <a class="source" href="../..//haibu/drone/drone.html"> haibu/drone/drone.html </a> <a class="source" href="../..//haibu/drone/index.html"> haibu/drone/index.html </a> <a class="source" href="../..//haibu/drone/service.html"> haibu/drone/service.html </a> <a class="source" href="../..//haibu/plugins/changelog.html"> haibu/plugins/changelog.html </a> <a class="source" href="../..//haibu/plugins/chroot.html"> haibu/plugins/chroot.html </a> <a class="source" href="../..//haibu/plugins/logger.html"> haibu/plugins/logger.html </a> <a class="source" href="../..//haibu/repositories/git.html"> haibu/repositories/git.html </a> <a class="source" href="../..//haibu/repositories/index.html"> haibu/repositories/index.html </a> <a class="source" href="../..//haibu/repositories/local-file.html"> haibu/repositories/local-file.html </a> <a class="source" href="../..//haibu/repositories/npm.html"> haibu/repositories/npm.html </a> <a class="source" href="../..//haibu/repositories/remote-file.html"> haibu/repositories/remote-file.html </a> <a class="source" href="../..//haibu/repositories/repository.html"> haibu/repositories/repository.html </a> <a class="source" href="../..//haibu/repositories/tar.html"> haibu/repositories/tar.html </a> <a class="source" href="../..//haibu/repositories/zip.html"> haibu/repositories/zip.html </a> <a class="source" href="../..//haibu/utils/base64.html"> haibu/utils/base64.html </a> <a class="source" href="../..//haibu/utils/bin.html"> haibu/utils/bin.html </a> <a class="source" href="../..//haibu/utils/index.html"> haibu/utils/index.html </a> <a class="source" href="../..//haibu.html"> haibu.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> process-store.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
+<span class="cm"> * process-store.js: Keeps track of process files `app.package.json`, `app.pid.json`, etc.</span>
+<span class="cm"> *</span>
+<span class="cm"> * (C) 2010, Nodejitsu Inc.</span>
+<span class="cm"> *</span>
+<span class="cm"> */</span>
+
+<span class="kd">var</span> <span class="nx">util</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;util&#39;</span><span class="p">),</span>
+ <span class="nx">fs</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;fs&#39;</span><span class="p">),</span>
+ <span class="nx">events</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;events&#39;</span><span class="p">),</span>
+ <span class="nx">path</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;path&#39;</span><span class="p">),</span>
+ <span class="nx">watch</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;watch&#39;</span><span class="p">),</span>
+ <span class="nx">haibu</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;haibu&#39;</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <h3>function ProcessStore ()</h3>
+
+<p>Constructor function for the ProcessStore responsible for
+managing persistent <code>app.package.json</code> and <code>app.pid.json</code>
+files in <code>haibu</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">ProcessStore</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">ProcessStore</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="nx">events</span><span class="p">.</span><span class="nx">EventEmitter</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="k">this</span><span class="p">);</span>
+
+ <span class="k">this</span><span class="p">.</span><span class="nx">runningDir</span> <span class="o">=</span> <span class="nx">haibu</span><span class="p">.</span><span class="nx">config</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;directories:running&#39;</span><span class="p">);</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">active</span> <span class="o">=</span> <span class="p">{};</span>
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Inherit from <code>events.EventEmitter</code></p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">util</span><span class="p">.</span><span class="nx">inherits</span><span class="p">(</span><span class="nx">ProcessStore</span><span class="p">,</span> <span class="nx">events</span><span class="p">.</span><span class="nx">EventEmitter</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <h3>function save (name, data, callback)</h3>
+
+<h4>@name {string} Application name for the file to save</h4>
+
+<h4>@data {Object} Data to save in the specified file</h4>
+
+<h4>@callback {function} Continuation to respond to when complete.</h4>
+
+<p>Saves the specified <code>data</code> into an appropriate <code>package.json</code> or
+<code>pid.json</code> file for <code>haibu</code> on this machine.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">ProcessStore</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">save</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">data</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span> </pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Save the data to the correct filepath for this type of data.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">filepath</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_filename</span><span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">data</span><span class="p">);</span>
+ <span class="nx">fs</span><span class="p">.</span><span class="nx">writeFile</span><span class="p">(</span><span class="nx">filepath</span><span class="p">,</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">data</span><span class="p">,</span> <span class="kc">null</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">err</span> <span class="o">?</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="o">:</span> <span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">filepath</span><span class="p">);</span>
+ <span class="p">});</span>
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <h3>function remove (name, data, callback)</h3>
+
+<h4>@name {string} Application name for the file to remove.</h4>
+
+<h4>@data {Object} Data in the specified file to remove.</h4>
+
+<h4>@callback {function} Continuation to respond to when complete.</h4>
+
+<p>Removes the file with <code>data</code> for the application with the specified <code>name</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">ProcessStore</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">remove</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">data</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Remove the file, ignoring any errors that are returned.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">filepath</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_filename</span><span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">data</span><span class="p">);</span>
+ <span class="nx">fs</span><span class="p">.</span><span class="nx">unlink</span><span class="p">(</span><span class="nx">filepath</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">callback</span><span class="p">();</span>
+ <span class="p">});</span>
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <h3>function monitor ()</h3>
+
+<p>Starts monitoring all files in the <code>runningDir</code> for this
+ProcessStore instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">ProcessStore</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">monitor</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
+
+ <span class="nx">watch</span><span class="p">.</span><span class="nx">createMonitor</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">runningDir</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">monitor</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">self</span><span class="p">.</span><span class="nx">emit</span><span class="p">(</span><span class="s1">&#39;load&#39;</span><span class="p">,</span> <span class="nx">monitor</span><span class="p">.</span><span class="nx">files</span><span class="p">);</span>
+
+ <span class="nx">monitor</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s1">&#39;created&#39;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">file</span><span class="p">,</span> <span class="nx">curr</span><span class="p">,</span> <span class="nx">prev</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">curr</span><span class="p">.</span><span class="nx">isFile</span><span class="p">())</span> <span class="p">{</span>
+ <span class="nx">self</span><span class="p">.</span><span class="nx">emit</span><span class="p">(</span><span class="s1">&#39;created&#39;</span><span class="p">,</span> <span class="nx">file</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">});</span>
+
+ <span class="nx">monitor</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s1">&#39;removed&#39;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">file</span><span class="p">,</span> <span class="nx">stats</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">stats</span><span class="p">.</span><span class="nx">isFile</span><span class="p">())</span> <span class="p">{</span>
+ <span class="nx">self</span><span class="p">.</span><span class="nx">emit</span><span class="p">(</span><span class="s1">&#39;removed&#39;</span><span class="p">,</span> <span class="nx">file</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">});</span>
+ <span class="p">});</span>
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <h3>private function _filename (name, data)</h3>
+
+<h4>@name {string} Application name for the filename.</h4>
+
+<h4>@data {Object} Data in the specified filename to generate.</h4>
+
+<p>Generates the appropriate filename (e.g. <code>app.package.json</code> or
+<code>app.12345.json</code>) for the specified <code>name</code> and <code>data</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">ProcessStore</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_filename</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">data</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">ext</span> <span class="o">=</span> <span class="nx">data</span><span class="p">.</span><span class="nx">pid</span> <span class="o">||</span> <span class="p">(</span><span class="nx">data</span><span class="p">.</span><span class="nx">_id</span><span class="p">,</span> <span class="s1">&#39;package&#39;</span><span class="p">),</span>
+ <span class="nx">filename</span> <span class="o">=</span> <span class="p">[</span><span class="nx">name</span><span class="p">,</span> <span class="nx">ext</span><span class="p">,</span> <span class="s1">&#39;json&#39;</span><span class="p">].</span><span class="nx">join</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">);</span>
+ </pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Save information about applications at <code>appname.package.json</code>
+and save pid information at <code>appname.pid.json</code></p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">return</span> <span class="nx">filepath</span> <span class="o">=</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">runningDir</span><span class="p">,</span> <span class="nx">filename</span><span class="p">);</span>
+<span class="p">};</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
190 docs/haibu/core/spawner.html
View
@@ -0,0 +1,190 @@
+<!DOCTYPE html> <html> <head> <title>spawner.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="../../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="../..//haibu/balancer/balancer.html"> haibu/balancer/balancer.html </a> <a class="source" href="../..//haibu/balancer/index.html"> haibu/balancer/index.html </a> <a class="source" href="../..//haibu/core/config.html"> haibu/core/config.html </a> <a class="source" href="../..//haibu/core/process-store.html"> haibu/core/process-store.html </a> <a class="source" href="../..//haibu/core/spawner.html"> haibu/core/spawner.html </a> <a class="source" href="../..//haibu/drone/client.html"> haibu/drone/client.html </a> <a class="source" href="../..//haibu/drone/drone.html"> haibu/drone/drone.html </a> <a class="source" href="../..//haibu/drone/index.html"> haibu/drone/index.html </a> <a class="source" href="../..//haibu/drone/service.html"> haibu/drone/service.html </a> <a class="source" href="../..//haibu/plugins/changelog.html"> haibu/plugins/changelog.html </a> <a class="source" href="../..//haibu/plugins/chroot.html"> haibu/plugins/chroot.html </a> <a class="source" href="../..//haibu/plugins/logger.html"> haibu/plugins/logger.html </a> <a class="source" href="../..//haibu/repositories/git.html"> haibu/repositories/git.html </a> <a class="source" href="../..//haibu/repositories/index.html"> haibu/repositories/index.html </a> <a class="source" href="../..//haibu/repositories/local-file.html"> haibu/repositories/local-file.html </a> <a class="source" href="../..//haibu/repositories/npm.html"> haibu/repositories/npm.html </a> <a class="source" href="../..//haibu/repositories/remote-file.html"> haibu/repositories/remote-file.html </a> <a class="source" href="../..//haibu/repositories/repository.html"> haibu/repositories/repository.html </a> <a class="source" href="../..//haibu/repositories/tar.html"> haibu/repositories/tar.html </a> <a class="source" href="../..//haibu/repositories/zip.html"> haibu/repositories/zip.html </a> <a class="source" href="../..//haibu/utils/base64.html"> haibu/utils/base64.html </a> <a class="source" href="../..//haibu/utils/bin.html"> haibu/utils/bin.html </a> <a class="source" href="../..//haibu/utils/index.html"> haibu/utils/index.html </a> <a class="source" href="../..//haibu.html"> haibu.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> spawner.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
+<span class="cm"> * spawner.js: Responsible for checking, downloading, and spawning drones </span>
+<span class="cm"> * inside of carapace objects.</span>
+<span class="cm"> *</span>
+<span class="cm"> * (C) 2010, Nodejitsu Inc.</span>
+<span class="cm"> *</span>
+<span class="cm"> */</span>
+
+<span class="kd">var</span> <span class="nx">sys</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;sys&#39;</span><span class="p">),</span>
+ <span class="nx">fs</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;fs&#39;</span><span class="p">),</span>
+ <span class="nx">colors</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;colors&#39;</