13 lines
7.7 KiB
HTML
13 lines
7.7 KiB
HTML
<!DOCTYPE html> <html lang=en> <head> <meta charset=utf-8> <meta name=viewport content="width=device-width, initial-scale=1.0"> <meta name=description content=""> <meta name=author content=""> <title>Event Handlers - Serf</title> <link href="/stylesheets/bootstrap.min-82fe1490.css" media=screen rel=stylesheet /><link href="/stylesheets/main-e5014f86.css" media=screen rel=stylesheet /> <!--[if lt IE 9]><script src="/javascripts/html5shiv-310dd184.js"></script> <script src="/javascripts/respond.min-88c91176.js"></script><![endif]--> <script>
|
|
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
|
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
|
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
|
|
|
ga('create', 'UA-45101516-1', 'serfdom.io');
|
|
ga('send', 'pageview');
|
|
|
|
</script> </head> <body class="page-Event Handlers"> <div id=header> <div class=container> <a class="navbar-brand logo" href="/"> <span></span> </a> <a class="navbar-brand text rls-l" href="/">SERF</a> <ul class="buttons nav navbar-nav navbar-right rls-sb"> <li class=first><a href="/downloads.html">Download</a></li> <li><a href="https://github.com/hashicorp/serf">Github</a></li> </ul> <ul class="main-links nav navbar-nav navbar-right rls-sb"> <li><a href="/intro/index.html">Intro</a></li> <li><a href="/docs/index.html">Docs</a></li> <li><a href="/community.html">Community</a></li> </ul> </div> </div> <div class=container> <div class=col-md-4> <div class="docs-sidebar hidden-print affix-top" role=complementary> <ul class="nav docs-sidenav"> <li> <a href="/docs/index.html">Documentation Home</a> </li> <li> <a href="/docs/upgrading.html">Upgrading and Compatibility</a> <ul class=nav> <li> <a href="/docs/upgrading.html">Upgrading Serf</a> </li> <li> <a href="/docs/compatibility.html">Compatibility Promise</a> </li> </ul> </li> <li> <a href="/docs/internals/index.html">Serf Internals</a> <ul class=nav> <li> <a href="/docs/internals/gossip.html">Gossip Protocol</a> </li> <li> <a href="/docs/internals/security.html">Security Model</a> </li> <li> <a href="/docs/internals/simulator.html">Convergence Simulator</a> </li> </ul> </li> <li> <a href="/docs/commands/index.html">Serf Commands (CLI)</a> <ul class=nav> <li> <a href="/docs/commands/agent.html">agent</a> </li> <li> <a href="/docs/commands/event.html">event</a> </li> <li> <a href="/docs/commands/force-leave.html">force-leave</a> </li> <li> <a href="/docs/commands/join.html">join</a> </li> <li> <a href="/docs/commands/keygen.html">keygen</a> </li> <li> <a href="/docs/commands/leave.html">leave</a> </li> <li> <a href="/docs/commands/members.html">members</a> </li> <li> <a href="/docs/commands/monitor.html">monitor</a> </li> </ul> </li> <li class=active> <a href="/docs/agent/basics.html">Serf Agent</a> <ul class=nav> <li> <a href="/docs/agent/basics.html">Running and Stopping</a> </li> <li> <a href="/docs/agent/options.html">Configuration</a> </li> <li class=active> <a href="/docs/agent/event-handlers.html">Event Handlers</a> </li> <li> <a href="/docs/agent/encryption.html">Encryption</a> </li> <li> <a href="/docs/agent/rpc.html">RPC Protocol</a> </li> </ul> <li> <a href="/docs/roadmap.html">Roadmap</a> </li> </ul> </div> </div> <div class=col-md-8 role=main> <div class=bs-docs-section> <h1 id=toc_0>Event Handlers</h1> <p>Serf's true power and flexibility comes in the form of event handlers: scripts that are executed in response to various events that can occur related to the Serf cluster. Serf invokes events related to membership changes (when a node comes online or goes offline) as well as <a href="/docs/commands/event.html">custom events</a>.</p> <p>Event handlers can be any executable, including piped executables (such as <code>awk '{print $2}' | grep foo</code>, since event handlers are invoked within the context of a shell. The event handler is executed anytime an event occurs and are expected to exit within a reasonable amount of time.</p> <h2 id=toc_1>Inputs and Parameters</h2> <p>Every time an event handler is invoked, Serf sets some environmental variables:</p> <ul> <li><p><code>SERF_EVENT</code> is the event type that is occuring. This will be one of <code>member-join</code>, <code>member-leave</code>, <code>member-failed</code>, or <code>user</code>.</p></li> <li><p><code>SERF_SELF_NAME</code> is the name of the node that is executing the event handler.</p></li> <li><p><code>SERF_SELF_ROLE</code> is the role of the node that is executing the event handler.</p></li> <li><p><code>SERF_USER_EVENT</code> is the name of the user event type if <code>SERF_EVENT</code> is "user".</p></li> <li><p><code>SERF_USER_LTIME</code> is the <code>LamportTime</code> of the user event if <code>SERF_EVENT</code> is "user".</p></li> </ul> <p>In addition to these environmental variables, the data for an event is passed in via stdin. The format of the data is dependent on the event type.</p> <h4 id=toc_2>Membership Event Data</h4> <p>For membership related events (<code>member-join</code>, <code>member-leave</code>, and <code>member-failed</code>), stdin is the list of members that participated in that event. Each member is separated by a newline and each field about the member is separated by whitespace. The fields of a membership event are name, address, then role. For example:</p> <pre><code>mitchellh.local 127.0.0.1 web
|
|
</code></pre> <h4 id=toc_3>User Event Data</h4> <p>For user events, stdin is the payload (if any) of the user event.</p> <h2 id=toc_4>Specifying Event Handlers</h2> <p>Event handlers are specified using the <code>-event-handler</code> flag for <code>serf agent</code>. This flag can be specified multiple times for multiple event handlers, in which case each event handler will be executed.</p> <p>Event handlers can also be filtered by event type. By default, the event handler will be invoked for any event which may occur. But you can restrict the events the event handler is invoked for by using a simple syntax of <code>type=script</code>. Below are all the available ways this syntax can be used to filter an event handler:</p> <ul> <li><p><code>foo.sh</code> - The script "foo.sh" will be invoked for any/every event.</p></li> <li><p><code>member-join=foo.sh</code> - The script "foo.sh" will only be invoked for the "member-join" event.</p></li> <li><p><code>member-join,member-leave=foo.sh</code> - The script "foo.sh" will be invoked for either member-join or member-leave events. Any combination of events may be specified in this way.</p></li> <li><p><code>user=foo.sh</code> - The script "foo.sh" will be invoked for all user events.</p></li> <li><p><code>user:deploy=foo.sh</code> - The script "foo.sh" will be invoked only for "deploy" user events.</p></li> </ul> </div> </div> </div> <div id=footer> <div class=container> <div class=footer-links> <ul class="main-links nav navbar-nav rls-sb"> <li><a href="/intro/index.html">Intro</a></li> <li class=active><a href="/docs/index.html">Docs</a></li> <li><a href="/community.html">Community</a></li> </ul> <ul class="buttons nav navbar-nav rls-sb"> <li class=first><a href="/downloads.html">Download</a></li> <li><a href="https://github.com/hashicorp/serf">Github</a></li> </ul> </div> <div class=footer-logo> <span></span> </div> <div class="footer-hashi os"> <span>© 2013. A <a href="//www.hashicorp.com">HashiCorp</a> Project.</span> <a href="//www.hashicorp.com"><img src="/images/hashi-logo-s-3644fe63.png"></a> </div> </div> </div> <script src="javascripts/lib/d3.v3.min.js"></script> <script src="javascripts/app/deploy/site.js"></script> <script>
|
|
Serf.initialize();
|
|
</script> </body> </html> |