Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

update site

  • Loading branch information...
commit eba67193924bcb2747f1d771272b6fa555678717 1 parent a1c2c50
Tom Preston-Werner mojombo authored

Showing 1 changed file with 136 additions and 51 deletions. Show diff stats Hide diff stats

  1. +136 51 site/index.html
187 site/index.html
@@ -47,7 +47,7 @@
47 47 </ul>
48 48 </div>
49 49
50   - <h1>Installation (v 0.7.17)</h1>
  50 + <h1>Installation (v 0.10.1)</h1>
51 51 <p>The best way to get god is via rubygems:</p>
52 52 <pre>$ sudo gem install god</pre>
53 53
@@ -211,38 +211,6 @@
211 211
212 212 <!-- ------------------------------------------------------------------------- -->
213 213
214   -<h1>Changing UID/GID for processes</h1>
215   -
216   -<p>It is possible to have god run your start/stop/restart commands as a specific user/group. This can be done by setting the <code>uid</code> and/or <code>gid</code> attributes of a watch.</p>
217   -
218   -<pre><code class="ruby"> God.watch do |w|
219   - ...
220   -
221   - w.uid = 'tom'
222   - w.gid = 'devs'
223   -
224   - ...
225   - end</code></pre>
226   -
227   -</p>This only works for commands specified as a string. Lambda commands are unaffected.</p>
228   -
229   -
230   -<!-- ------------------------------------------------------------------------- -->
231   -
232   -<h1>Lambda commands</h1>
233   -
234   -<p>In addition to specifying start/stop/restart commands as strings (to be executed via the shell), you can specify a lambda that will be called.</p>
235   -
236   -<pre><code class="ruby"> God.watch do |w|
237   - ...
238   -
239   - w.start = lambda { ENV['APACHE'] ? `apachectl -k graceful` : `lighttpd restart` }
240   -
241   - ...
242   - end</code></pre>
243   -
244   -<!-- ------------------------------------------------------------------------- -->
245   -
246 214 <h1>Starting and Controlling God</h1>
247 215
248 216 <p>To start the god monitoring process as a daemon simply run the <code>god</code> executable passing in the path to the config file (you need to sudo if you're using events on Linux or want to use the setuid/setgid functionality):</p>
@@ -259,24 +227,6 @@
259 227
260 228 <!-- ------------------------------------------------------------------------- -->
261 229
262   -<h1>Grouping Watches</h1>
263   -
264   -<p>Watches can be assigned to groups. These groups can then be controlled together from the command line.</p>
265   -
266   -<pre><code class="ruby"> God.watch do |w|
267   - ...
268   -
269   - w.group = 'mongrels'
270   -
271   - ...
272   - end</code></pre>
273   -
274   -<p>The above configuration now allows you to control the watch (and any others that are in the group) with a single command:</p>
275   -
276   -<pre>$ sudo god stop mongrels</pre>
277   -
278   -<!-- ------------------------------------------------------------------------- -->
279   -
280 230 <h1>Advanced Configuration with Transitions and Events</h1>
281 231
282 232 <p>So far you've been introduced to a simple poll-based config file and seen how to run it. Poll-based monitoring works great for simple things, but falls short for highly critical tasks. God has native support for kqueue/netlink events on BSD/Darwin/Linux systems. For instance, instead of using the <code>process_running</code> condition to poll for the status of your process, you can use the <code>process_exits</code> condition that will be notified <b>immediately</b> upon the exit of your process. This means less load on your system and shorter downtime after a crash.</p>
@@ -418,6 +368,141 @@
418 368
419 369 <!-- ------------------------------------------------------------------------- -->
420 370
  371 +<h1>Grouping Watches</h1>
  372 +
  373 +<p>Watches can be assigned to groups. These groups can then be controlled together from the command line.</p>
  374 +
  375 +<pre><code class="ruby"> God.watch do |w|
  376 + ...
  377 +
  378 + w.group = 'mongrels'
  379 +
  380 + ...
  381 + end</code></pre>
  382 +
  383 +<p>The above configuration now allows you to control the watch (and any others that are in the group) with a single command:</p>
  384 +
  385 +<pre>$ sudo god stop mongrels</pre>
  386 +
  387 +<!-- ------------------------------------------------------------------------- -->
  388 +
  389 +<h1>Redirecting STDOUT and STDERR of your Process</h1>
  390 +
  391 +<p>By default, the STDOUT stream for your process is redirected to <code>/dev/null</code>. To get access to this output, you can redirect the stream either to a file or to a command.<p>
  392 +
  393 +<p>To redirect STDOUT to a file, set the <code>log</code> attribute to a file path. The file will be written in append mode and created if it does not exist.</p>
  394 +
  395 +<pre><code class="ruby"> God.watch do |w|
  396 + ...
  397 +
  398 + w.log = '/var/log/myprocess.log'
  399 +
  400 + ...
  401 + end</code></pre>
  402 +
  403 +<p>To redirect STDOUT to a command that will be run for you, set the <code>log_cmd</code> attribute to a command.</p>
  404 +
  405 +<pre><code class="ruby"> God.watch do |w|
  406 + ...
  407 +
  408 + w.log_cmd = '/usr/bin/logger'
  409 +
  410 + ...
  411 + end</code></pre>
  412 +
  413 +<p>By default, STDERR is redirected to STDOUT. You can redirect it to a file or a command just like STDOUT by setting the <code>err_log</code> or <code>err_log_cmd</code> attributes respectively.</p>
  414 +
  415 +<!-- ------------------------------------------------------------------------- -->
  416 +
  417 +<h1>Changing UID/GID for processes</h1>
  418 +
  419 +<p>It is possible to have god run your start/stop/restart commands as a specific user/group. This can be done by setting the <code>uid</code> and/or <code>gid</code> attributes of a watch.</p>
  420 +
  421 +<pre><code class="ruby"> God.watch do |w|
  422 + ...
  423 +
  424 + w.uid = 'tom'
  425 + w.gid = 'devs'
  426 +
  427 + ...
  428 + end</code></pre>
  429 +
  430 +</p>This only works for commands specified as a string. Lambda commands are unaffected.</p>
  431 +
  432 +<!-- ------------------------------------------------------------------------- -->
  433 +
  434 +<h1>Setting the Working Directory</h1>
  435 +
  436 +<p>By default, God sets the working directory to / before running your process. You can change this by setting the <code>dir</code> attribute on the watch.</p>
  437 +
  438 +<pre><code class="ruby"> God.watch do |w|
  439 + ...
  440 +
  441 + w.dir = '/var/www/myapp'
  442 +
  443 + ...
  444 + end</code></pre>
  445 +
  446 +<!-- ------------------------------------------------------------------------- -->
  447 +
  448 +<h1>Setting environment variables</h1>
  449 +
  450 +<p>You can set any number of environment variables you wish via the <code>env</code> attribute of a watch.</p>
  451 +
  452 +<pre><code class="ruby"> God.watch do |w|
  453 + ...
  454 +
  455 + w.env = { 'RAILS_ROOT' = "/var/www/myapp",
  456 + 'RAILS_ENV' = "production" }
  457 +
  458 + ...
  459 + end</code></pre>
  460 +
  461 +<!-- ------------------------------------------------------------------------- -->
  462 +
  463 +<h1>Using chroot to Change the File System Root</h1>
  464 +
  465 +<p>If you want your process to run chrooted, simply use the <code>chroot</code> attribute on the watch. The specified directory must exist and have a /dev/null.</p>
  466 +
  467 +<pre><code class="ruby"> God.watch do |w|
  468 + ...
  469 +
  470 + w.chroot = '/var/myroot'
  471 +
  472 + ...
  473 + end</code></pre>
  474 +
  475 +<!-- ------------------------------------------------------------------------- -->
  476 +
  477 +<h1>Lambda commands</h1>
  478 +
  479 +<p>In addition to specifying start/stop/restart commands as strings (to be executed via the shell), you can specify a lambda that will be called.</p>
  480 +
  481 +<pre><code class="ruby"> God.watch do |w|
  482 + ...
  483 +
  484 + w.start = lambda { ENV['APACHE'] ? `apachectl -k graceful` : `lighttpd restart` }
  485 +
  486 + ...
  487 + end</code></pre>
  488 +
  489 +<!-- ------------------------------------------------------------------------- -->
  490 +
  491 +<h1>Customizing the Default Stop Lambda</h1>
  492 +
  493 +<p>If you do not provide a stop command, God will attempt to stop your process by first sending a SIGTERM. It will then wait for ten seconds for the process to exit. If after this time it still has not exited, it will be sent a SIGKILL. You can customize the stop signal and/or the time to wait for the process to exit by setting the <code>stop_signal</code> and <code>stop_timeout</code> attributes on the watch.</p>
  494 +
  495 +<pre><code class="ruby"> God.watch do |w|
  496 + ...
  497 +
  498 + w.stop_signal = 'QUIT'
  499 + w.stop_timeout = 20.seconds
  500 +
  501 + ...
  502 + end</code></pre>
  503 +
  504 +<!-- ------------------------------------------------------------------------- -->
  505 +
421 506 <h1>Watching Non-Daemon Processes</h1>
422 507
423 508 <p>Need to watch a script that doesn't have built in daemonization? No problem! God will daemonize and keep track of your process for you. If you don't specify a <code>pid_file</code> attribute for a watch, it will be auto-daemonized and a PID file will be stored for it in <code>/var/run/god</code>. If you'd rather have the PID file stored in a different location, you can set it at the top of your config:</p>

0 comments on commit eba6719

Please sign in to comment.
Something went wrong with that request. Please try again.