Module: Launch

Defined in:
lib/launch/webrick.rb,
lib/launch.rb,
lib/launch/job.rb,
lib/launch/errors.rb,
lib/launch/version.rb,
ext/launch.c

Overview

Launch::WEBrickHTTPServer adds launchd support to WEBrick.

To use, replace WEBrick::HTTPServer with Launch::WEBrickHTTPServer.

By default Launch::WEBrickHTTPServer expects to find the socket list under 'WEBrickSockets' but this may be overridden through the :LaunchdSockets option.

The server will automatically shut down when a TERM signal is sent. If you wish to perform other shutdown actions override TERM but be sure to shut down webrick.

An example WEBrick server using Launch::WEBrickHTTPServer would be:

require 'launch/webrick'

Launch::WEBrickHTTPServer.new(:DocumentRoot => ARGV.shift).start

Here is an example plist for this server which listens on port 8000:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>net.segment7.launch.webrick</string>
  <key>ProgramArguments</key>
  <array>
    <string>/path/to/ruby</string>
    <string>/path/to/webrick</string>
    <string>/Users/your_user/Sites</string>
  </array>
  <key>ServiceIPC</key>
  <true/>
  <key>Sockets</key>
  <dict>
    <key>WEBrickSockets</key>
    <dict>
      <key>SockServiceName</key>
      <string>8000</string>
    </dict>
  </dict>
</dict>
</plist>

Defined Under Namespace

Modules: Messages Classes: Error, InvalidJob, Job, JobAlreadyExists, JobError, UnknownJob, WEBrickHTTPServer

Constant Summary collapse

VERSION =
"2.0.0"

Class Method Summary collapse

Class Method Details

.jobsObject



9
10
11
# File 'lib/launch.rb', line 9

def jobs
  message(Messages::GETJOBS).values.map(&Job.method(:from_launch))
end

.message(obj) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'ext/launch.c', line 141

static VALUE launch_message(VALUE self, VALUE obj)
{
  VALUE result = Qnil;
  launch_data_t item, response;

  item = ruby_to_launch_data(obj);
  if (item == NULL)
    rb_raise(rb_cLaunchError, "item is nil");

  response = launch_msg(item);
  launch_data_free(item);

  if (response == NULL)
    rb_sys_fail("launch");\

  result = launch_data_to_ruby(response);
  launch_data_free(response);

  return result;
}