344 lines
15 KiB
HTML
344 lines
15 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="content-type" content="text/html;charset=utf-8">
|
|
<title>sample.py</title>
|
|
<link rel="stylesheet" href="pycco.css">
|
|
</head>
|
|
<body>
|
|
<div id='container'>
|
|
<div id="background"></div>
|
|
<div class='section'>
|
|
<div class='docs'><h1>sample.py</h1></div>
|
|
</div>
|
|
<div class='clearall'>
|
|
<div class='section' id='section-0'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-0'>#</a>
|
|
</div>
|
|
<p>Sample user-defined service.</p>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">core.service</span> <span class="kn">import</span> <span class="n">CoreService</span>
|
|
<span class="kn">from</span> <span class="nn">core.service</span> <span class="kn">import</span> <span class="n">ServiceMode</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-1'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-1'>#</a>
|
|
</div>
|
|
<h1>Custom CORE Service</h1>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre><span class="k">class</span> <span class="nc">MyService</span><span class="p">(</span><span class="n">CoreService</span><span class="p">):</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-2'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-2'>#</a>
|
|
</div>
|
|
<h2>Service Attributes</h2>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-3'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-3'>#</a>
|
|
</div>
|
|
<p>Name used as a unique ID for this service and is required, no spaces.</p>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre> <span class="n">name</span> <span class="o">=</span> <span class="s2">"MyService"</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-4'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-4'>#</a>
|
|
</div>
|
|
<p>Allows you to group services within the GUI under a common name.</p>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre> <span class="n">group</span> <span class="o">=</span> <span class="s2">"Utility"</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-5'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-5'>#</a>
|
|
</div>
|
|
<p>Executables this service depends on to function, if executable is not on the path, service will not be loaded.</p>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre> <span class="n">executables</span> <span class="o">=</span> <span class="p">()</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-6'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-6'>#</a>
|
|
</div>
|
|
<p>Services that this service depends on for startup, tuple of service names.</p>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre> <span class="n">dependencies</span> <span class="o">=</span> <span class="p">()</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-7'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-7'>#</a>
|
|
</div>
|
|
<p>Directories that this service will create within a node.</p>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre> <span class="n">dirs</span> <span class="o">=</span> <span class="p">()</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-8'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-8'>#</a>
|
|
</div>
|
|
<p>Files that this service will generate, without a full path this file goes in the node’s directory.
|
|
e.g. /tmp/pycore.12345/n1.conf/myfile</p>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre> <span class="n">configs</span> <span class="o">=</span> <span class="p">(</span><span class="s2">"myservice1.sh"</span><span class="p">,</span> <span class="s2">"myservice2.sh"</span><span class="p">)</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-9'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-9'>#</a>
|
|
</div>
|
|
<p>Commands used to start this service, any non-zero exit code will cause a failure.</p>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre> <span class="n">startup</span> <span class="o">=</span> <span class="p">(</span><span class="s2">"sh </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="n">configs</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="s2">"sh </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="n">configs</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-10'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-10'>#</a>
|
|
</div>
|
|
<p>Commands used to validate that a service was started, any non-zero exit code will cause a failure.</p>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre> <span class="n">validate</span> <span class="o">=</span> <span class="p">()</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-11'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-11'>#</a>
|
|
</div>
|
|
<p>Validation mode, used to determine startup success.</p>
|
|
<ul>
|
|
<li>NON_BLOCKING - runs startup commands, and validates success with validation commands</li>
|
|
<li>BLOCKING - runs startup commands, and validates success with the startup commands themselves</li>
|
|
<li>TIMER - runs startup commands, and validates success by waiting for “validation_timer” alone</li>
|
|
</ul>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre> <span class="n">validation_mode</span> <span class="o">=</span> <span class="n">ServiceMode</span><span class="o">.</span><span class="n">NON_BLOCKING</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-12'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-12'>#</a>
|
|
</div>
|
|
<p>Time in seconds for a service to wait for validation, before determining success in TIMER/NON_BLOCKING modes.</p>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre> <span class="n">validation_timer</span> <span class="o">=</span> <span class="mi">5</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-13'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-13'>#</a>
|
|
</div>
|
|
<p>Period in seconds to wait before retrying validation, only used in NON_BLOCKING mode.</p>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre> <span class="n">validation_period</span> <span class="o">=</span> <span class="mf">0.5</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-14'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-14'>#</a>
|
|
</div>
|
|
<p>Shutdown commands to stop this service.</p>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre> <span class="n">shutdown</span> <span class="o">=</span> <span class="p">()</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-15'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-15'>#</a>
|
|
</div>
|
|
<h2>On Load</h2>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre> <span class="nd">@classmethod</span>
|
|
<span class="k">def</span> <span class="nf">on_load</span><span class="p">(</span><span class="bp">cls</span><span class="p">):</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-16'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-16'>#</a>
|
|
</div>
|
|
<p>Provides a way to run some arbitrary logic when the service is loaded, possibly to help facilitate
|
|
dynamic settings for the environment.</p>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre> <span class="k">pass</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-17'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-17'>#</a>
|
|
</div>
|
|
<h2>Get Configs</h2>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre> <span class="nd">@classmethod</span>
|
|
<span class="k">def</span> <span class="nf">get_configs</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">node</span><span class="p">):</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-18'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-18'>#</a>
|
|
</div>
|
|
<p>Provides a way to dynamically generate the config files from the node a service will run.
|
|
Defaults to the class definition and can be left out entirely if not needed.</p>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre> <span class="k">return</span> <span class="bp">cls</span><span class="o">.</span><span class="n">configs</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-19'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-19'>#</a>
|
|
</div>
|
|
<h2>Generate Config</h2>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre> <span class="nd">@classmethod</span>
|
|
<span class="k">def</span> <span class="nf">generate_config</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">node</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-20'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-20'>#</a>
|
|
</div>
|
|
<p>Returns a string representation for a file, given the node the service is starting on the config filename
|
|
that this information will be used for. This must be defined, if “configs” are defined.</p>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre> <span class="n">cfg</span> <span class="o">=</span> <span class="s2">"#!/bin/sh</span><span class="se">\n</span><span class="s2">"</span>
|
|
|
|
<span class="k">if</span> <span class="n">filename</span> <span class="o">==</span> <span class="bp">cls</span><span class="o">.</span><span class="n">configs</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>
|
|
<span class="n">cfg</span> <span class="o">+=</span> <span class="s2">"# auto-generated by MyService (sample.py)</span><span class="se">\n</span><span class="s2">"</span>
|
|
<span class="k">for</span> <span class="n">ifc</span> <span class="ow">in</span> <span class="n">node</span><span class="o">.</span><span class="n">netifs</span><span class="p">():</span>
|
|
<span class="n">cfg</span> <span class="o">+=</span> <span class="s1">'echo "Node </span><span class="si">%s</span><span class="s1"> has interface </span><span class="si">%s</span><span class="s1">"</span><span class="se">\n</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">ifc</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
|
|
<span class="k">elif</span> <span class="n">filename</span> <span class="o">==</span> <span class="bp">cls</span><span class="o">.</span><span class="n">configs</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span>
|
|
<span class="n">cfg</span> <span class="o">+=</span> <span class="s2">"echo hello"</span>
|
|
|
|
<span class="k">return</span> <span class="n">cfg</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-21'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-21'>#</a>
|
|
</div>
|
|
<h2>Get Startup</h2>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre> <span class="nd">@classmethod</span>
|
|
<span class="k">def</span> <span class="nf">get_startup</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">node</span><span class="p">):</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-22'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-22'>#</a>
|
|
</div>
|
|
<p>Provides a way to dynamically generate the startup commands from the node a service will run.
|
|
Defaults to the class definition and can be left out entirely if not needed.</p>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre> <span class="k">return</span> <span class="bp">cls</span><span class="o">.</span><span class="n">startup</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-23'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-23'>#</a>
|
|
</div>
|
|
<h2>Get Validate</h2>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre> <span class="nd">@classmethod</span>
|
|
<span class="k">def</span> <span class="nf">get_validate</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">node</span><span class="p">):</span></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
<div class='section' id='section-24'>
|
|
<div class='docs'>
|
|
<div class='octowrap'>
|
|
<a class='octothorpe' href='#section-24'>#</a>
|
|
</div>
|
|
<p>Provides a way to dynamically generate the validate commands from the node a service will run.
|
|
Defaults to the class definition and can be left out entirely if not needed.</p>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre> <span class="k">return</span> <span class="bp">cls</span><span class="o">.</span><span class="n">validate</span>
|
|
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
<div class='clearall'></div>
|
|
</div>
|
|
</body>
|