serverside 0.1.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +97 -0
- data/COPYING +18 -0
- data/README +51 -0
- data/Rakefile +92 -0
- data/bin/serverside +74 -0
- data/doc/rdoc/classes/Daemon.html +253 -0
- data/doc/rdoc/classes/Daemon/Base.html +146 -0
- data/doc/rdoc/classes/Daemon/Cluster.html +308 -0
- data/doc/rdoc/classes/Daemon/Cluster/PidFile.html +228 -0
- data/doc/rdoc/classes/Daemon/PidFile.html +178 -0
- data/doc/rdoc/classes/ServerSide.html +160 -0
- data/doc/rdoc/classes/ServerSide/Application.html +147 -0
- data/doc/rdoc/classes/ServerSide/Application/Base.html +196 -0
- data/doc/rdoc/classes/ServerSide/Application/Static.html +154 -0
- data/doc/rdoc/classes/ServerSide/Connection.html +128 -0
- data/doc/rdoc/classes/ServerSide/Connection/Base.html +343 -0
- data/doc/rdoc/classes/ServerSide/Connection/Const.html +229 -0
- data/doc/rdoc/classes/ServerSide/Connection/Static.html +172 -0
- data/doc/rdoc/classes/ServerSide/Server.html +162 -0
- data/doc/rdoc/classes/ServerSide/StaticFiles.html +208 -0
- data/doc/rdoc/classes/ServerSide/StaticFiles/Const.html +179 -0
- data/doc/rdoc/classes/String.html +210 -0
- data/doc/rdoc/classes/Symbol.html +156 -0
- data/doc/rdoc/created.rid +1 -0
- data/doc/rdoc/files/CHANGELOG.html +260 -0
- data/doc/rdoc/files/COPYING.html +129 -0
- data/doc/rdoc/files/README.html +171 -0
- data/doc/rdoc/files/lib/serverside/application_rb.html +109 -0
- data/doc/rdoc/files/lib/serverside/cluster_rb.html +101 -0
- data/doc/rdoc/files/lib/serverside/connection_rb.html +101 -0
- data/doc/rdoc/files/lib/serverside/core_ext_rb.html +107 -0
- data/doc/rdoc/files/lib/serverside/daemon_rb.html +108 -0
- data/doc/rdoc/files/lib/serverside/server_rb.html +108 -0
- data/doc/rdoc/files/lib/serverside/static_rb.html +101 -0
- data/doc/rdoc/files/lib/serverside_rb.html +131 -0
- data/doc/rdoc/fr_class_index.html +44 -0
- data/doc/rdoc/fr_file_index.html +37 -0
- data/doc/rdoc/fr_method_index.html +60 -0
- data/doc/rdoc/index.html +24 -0
- data/doc/rdoc/rdoc-style.css +208 -0
- data/lib/serverside.rb +13 -0
- data/lib/serverside/application.rb +40 -0
- data/lib/serverside/cluster.rb +72 -0
- data/lib/serverside/connection.rb +115 -0
- data/lib/serverside/core_ext.rb +27 -0
- data/lib/serverside/daemon.rb +67 -0
- data/lib/serverside/server.rb +18 -0
- data/lib/serverside/static.rb +96 -0
- data/test/functional/primitive_static_server_test.rb +37 -0
- data/test/functional/static_profile.rb +17 -0
- data/test/functional/static_rfuzz.rb +67 -0
- data/test/functional/static_server_test.rb +25 -0
- data/test/test_helper.rb +2 -0
- data/test/unit/application_test.rb +16 -0
- data/test/unit/cluster_test.rb +129 -0
- data/test/unit/connection_test.rb +193 -0
- data/test/unit/core_ext_test.rb +32 -0
- data/test/unit/daemon_test.rb +75 -0
- data/test/unit/server_test.rb +26 -0
- data/test/unit/static_test.rb +143 -0
- metadata +140 -0
data/CHANGELOG
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
*SVN*
|
2
|
+
|
3
|
+
* Added a profiled version of a static server - /test/functional/static_profile.rb.
|
4
|
+
|
5
|
+
* Added freezing of HTTP headers.
|
6
|
+
|
7
|
+
* Small change to documentation.
|
8
|
+
|
9
|
+
* Changed filename for cluster pid file to serverside_cluster.pid.
|
10
|
+
|
11
|
+
* Added documentation.
|
12
|
+
|
13
|
+
* Fixed require in serverside script to load the gem.
|
14
|
+
|
15
|
+
* Fixed the Daemon pid file for static file server mode.
|
16
|
+
|
17
|
+
* Added directory listing to static file server.
|
18
|
+
|
19
|
+
* Fixed request header parsing Regexp so a trailing slash would be ignored.
|
20
|
+
|
21
|
+
* Added static application. Using the binary script in static mode works.
|
22
|
+
|
23
|
+
* Added cluster class with unit tests.
|
24
|
+
|
25
|
+
* Added unit tests for static server.
|
26
|
+
|
27
|
+
* Added static server functional test.
|
28
|
+
|
29
|
+
* Added static file serving code.
|
30
|
+
|
31
|
+
* Renamed ServerSide::Request to ServerSide::Connection. This is more appropriate.
|
32
|
+
|
33
|
+
* Added functional static server test.
|
34
|
+
|
35
|
+
* Added test/functional for functional tests. Updated Rakefile.
|
36
|
+
|
37
|
+
* Added Request.send_response and stream.
|
38
|
+
|
39
|
+
* Added faster Symbol.to_s to core_ext.
|
40
|
+
|
41
|
+
* Added HTTP parsing code with unit tests.
|
42
|
+
|
43
|
+
* Started adding request code.
|
44
|
+
|
45
|
+
* More unit tests for application code.
|
46
|
+
|
47
|
+
* Basic server code works with unit tests.
|
48
|
+
|
49
|
+
* Started work on application code.
|
50
|
+
|
51
|
+
* Added option parsing to serverside script.
|
52
|
+
|
53
|
+
* Added daemon code and unit tests.
|
54
|
+
|
55
|
+
* Created serverside script.
|
56
|
+
|
57
|
+
* Created Gem spec.
|
58
|
+
|
59
|
+
* Created directory structure.
|
60
|
+
|
61
|
+
*Mongrel-based branch*
|
62
|
+
|
63
|
+
* Added host attribute to Controller::Request.
|
64
|
+
|
65
|
+
* Added ability to create rules on any request attribute, not just path.
|
66
|
+
|
67
|
+
* Added ability to mount controllers with a block for a rule.
|
68
|
+
|
69
|
+
* Wrote object extensions to create frozen constants on the fly.
|
70
|
+
|
71
|
+
* Changed DirHandler to use frozen strings for cache header.
|
72
|
+
|
73
|
+
* Hooked Mongrel server to Controller::Router.
|
74
|
+
|
75
|
+
* Imported request code with unit tests.
|
76
|
+
|
77
|
+
* Wrote unit tests for daemon module.
|
78
|
+
|
79
|
+
* Wrote unit tests for controller routing code.
|
80
|
+
|
81
|
+
* Refactored controller routing code.
|
82
|
+
|
83
|
+
* Imported unit tests for extensions.
|
84
|
+
|
85
|
+
* Created Rakefile.
|
86
|
+
|
87
|
+
* Prototypical routing code.
|
88
|
+
|
89
|
+
* Fixed location of daemon pid files.
|
90
|
+
|
91
|
+
* Imported Mongrel code from Reality project.
|
92
|
+
|
93
|
+
* Imported extensions from Reality project.
|
94
|
+
|
95
|
+
* Implemented daemon and server cluster.
|
96
|
+
|
97
|
+
* Basic configuration infrastructure is ready.
|
data/COPYING
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2006 Sharon Rosner
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
5
|
+
deal in the Software without restriction, including without limitation the
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
16
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
= about ServerSide
|
2
|
+
|
3
|
+
ServerSide is an HTTP server framework designed to be as fast as possible, and
|
4
|
+
as easy as possible to use. ServerSide includes a full-featured HTTP server, a
|
5
|
+
controller-view system and a bunch of other tools to easily create servers and
|
6
|
+
clusters of servers.
|
7
|
+
|
8
|
+
== Installation
|
9
|
+
|
10
|
+
<tt>sudo gem install serverside</tt>
|
11
|
+
|
12
|
+
== Source Code
|
13
|
+
|
14
|
+
http://serverside.googlecode.com/svn/
|
15
|
+
|
16
|
+
== The Daemon
|
17
|
+
|
18
|
+
Once you have the ServerSide gem installed, you can use the <tt>serverside</tt>
|
19
|
+
script to control servers. For example:
|
20
|
+
|
21
|
+
<tt>serverside -p 8000 start .</tt>
|
22
|
+
|
23
|
+
will start an HTTP server, serving the content of the working directory. You can
|
24
|
+
stop the server by running <tt>serverside stop .</tt>
|
25
|
+
|
26
|
+
== Serving Dynamic Content
|
27
|
+
|
28
|
+
You can use the ServerSide::Application and ServerSide::Controller classes to
|
29
|
+
create dynamic web applications. The ServerSide framework also lets you route
|
30
|
+
requests based on any attribute of incoming requests, such as host name, path,
|
31
|
+
URL parameters etc.
|
32
|
+
|
33
|
+
To start your app, you can either supply the <tt>serverside</tt> script with
|
34
|
+
your Ruby code file:
|
35
|
+
|
36
|
+
<tt>serverside start ~/myapp/myapp.rb</tt>
|
37
|
+
|
38
|
+
Or you can put your code in a file called <tt>serverside.rb</tt> and tell the
|
39
|
+
<tt>serverside</tt> script the directory path:
|
40
|
+
|
41
|
+
<tt>serverside start /home/nc/reality/production</tt>
|
42
|
+
|
43
|
+
The script will then load <tt>/home/nc/reality/production/serverside.rb</tt> and
|
44
|
+
take care of everything else.
|
45
|
+
|
46
|
+
== Running a Cluster of Servers
|
47
|
+
|
48
|
+
ServerSide makes it easy to control a cluster of servers. Just supply a range of
|
49
|
+
ports instead of a single port:
|
50
|
+
|
51
|
+
<tt>serverside -p 8000..8009 start .</tt>
|
data/Rakefile
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
require 'rake/rdoctask'
|
5
|
+
require 'rake/testtask'
|
6
|
+
require 'fileutils'
|
7
|
+
include FileUtils
|
8
|
+
|
9
|
+
NAME = "serverside"
|
10
|
+
REV = File.read(".svn/entries")[/committed-rev="(\d+)"/, 1] rescue nil
|
11
|
+
VERS = "0.1" + (REV ? ".#{REV}" : "")
|
12
|
+
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
13
|
+
RDOC_OPTS = ['--quiet', '--title', "ServerSide Documentation",
|
14
|
+
"--opname", "index.html",
|
15
|
+
"--line-numbers",
|
16
|
+
"--main", "README",
|
17
|
+
"--inline-source"]
|
18
|
+
|
19
|
+
desc "Packages up ServerSide."
|
20
|
+
task :default => [:package]
|
21
|
+
task :package => [:clean]
|
22
|
+
|
23
|
+
task :doc => [:rdoc]
|
24
|
+
|
25
|
+
Rake::RDocTask.new do |rdoc|
|
26
|
+
rdoc.rdoc_dir = 'doc/rdoc'
|
27
|
+
rdoc.options += RDOC_OPTS
|
28
|
+
rdoc.main = "README"
|
29
|
+
rdoc.title = "ServerSide Documentation"
|
30
|
+
rdoc.rdoc_files.add ['README', 'CHANGELOG', 'COPYING', 'lib/serverside.rb', 'lib/serverside/*.rb']
|
31
|
+
end
|
32
|
+
|
33
|
+
spec =
|
34
|
+
Gem::Specification.new do |s|
|
35
|
+
s.name = NAME
|
36
|
+
s.version = VERS
|
37
|
+
s.platform = Gem::Platform::RUBY
|
38
|
+
s.has_rdoc = true
|
39
|
+
s.extra_rdoc_files = ["README", "CHANGELOG", "COPYING"]
|
40
|
+
s.rdoc_options += RDOC_OPTS +
|
41
|
+
['--exclude', '^(examples|extras)\/', '--exclude', 'lib/serverside.rb']
|
42
|
+
s.summary = "Performance-oriented web framework."
|
43
|
+
s.description = s.summary
|
44
|
+
s.author = "Sharon Rosner"
|
45
|
+
s.email = 'ciconia@gmail.com'
|
46
|
+
s.homepage = 'http://code.google.com/p/serverside/'
|
47
|
+
s.executables = ['serverside']
|
48
|
+
|
49
|
+
s.add_dependency('metaid')
|
50
|
+
s.required_ruby_version = '>= 1.8.2'
|
51
|
+
|
52
|
+
s.files = %w(COPYING README Rakefile) +
|
53
|
+
Dir.glob("{bin,doc,test,lib}/**/*")
|
54
|
+
|
55
|
+
s.require_path = "lib"
|
56
|
+
s.bindir = "bin"
|
57
|
+
end
|
58
|
+
|
59
|
+
Rake::GemPackageTask.new(spec) do |p|
|
60
|
+
p.need_tar = true
|
61
|
+
p.gem_spec = spec
|
62
|
+
end
|
63
|
+
|
64
|
+
task :install do
|
65
|
+
sh %{rake package}
|
66
|
+
sh %{sudo gem install pkg/#{NAME}-#{VERS}}
|
67
|
+
end
|
68
|
+
|
69
|
+
task :uninstall => [:clean] do
|
70
|
+
sh %{sudo gem uninstall #{NAME}}
|
71
|
+
end
|
72
|
+
|
73
|
+
desc 'Run unit tests'
|
74
|
+
Rake::TestTask.new('test_unit') do |t|
|
75
|
+
t.libs << 'test'
|
76
|
+
t.pattern = 'test/unit/**/*_test.rb'
|
77
|
+
t.verbose = true
|
78
|
+
end
|
79
|
+
|
80
|
+
desc 'Run functional tests'
|
81
|
+
Rake::TestTask.new('test_functional') do |t|
|
82
|
+
t.libs << 'test'
|
83
|
+
t.pattern = 'test/functional/**/*_test.rb'
|
84
|
+
t.verbose = true
|
85
|
+
end
|
86
|
+
|
87
|
+
desc 'Run all tests'
|
88
|
+
Rake::TestTask.new('test') do |t|
|
89
|
+
t.libs << 'test'
|
90
|
+
t.pattern = 'test/**/*_test.rb'
|
91
|
+
t.verbose = true
|
92
|
+
end
|
data/bin/serverside
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'serverside'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
$cmd_config = {
|
8
|
+
:host => '0.0.0.0',
|
9
|
+
:ports => 8000..8000
|
10
|
+
}
|
11
|
+
|
12
|
+
opts = OptionParser.new do |opts|
|
13
|
+
opts.banner = "Usage: serverside start|stop|restart [app1 app2 ...]"
|
14
|
+
opts.define_head "ServerSide, a fast and simple web framework for ruby."
|
15
|
+
opts.separator ""
|
16
|
+
opts.separator "The supplied app paths can be directory or file references."
|
17
|
+
opts.separator ""
|
18
|
+
opts.separator "Options:"
|
19
|
+
|
20
|
+
opts.on("-h", "--host HOSTNAME", "Host to bind to (default is all IPs)") do |v|
|
21
|
+
$cmd_config[:host] = v
|
22
|
+
end
|
23
|
+
opts.on("-p", "--port NUM", "Port or port range (default is 8000)") do |v|
|
24
|
+
$cmd_config[:ports] = (v =~ /\.\./) ? eval(v) : v.to_i..v_to_i
|
25
|
+
end
|
26
|
+
|
27
|
+
# No argument, shows at tail. This will print an options summary.
|
28
|
+
# Try it and see!
|
29
|
+
opts.on_tail("-?", "--help", "Show this message") do
|
30
|
+
puts opts
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
|
34
|
+
# Another typical switch to print the version.
|
35
|
+
opts.on_tail("-v", "--version", "Show version") do
|
36
|
+
class << Gem; attr_accessor :loaded_specs; end
|
37
|
+
specs = Gem.loaded_specs['serverside']
|
38
|
+
puts "ServerSide #{specs.version} (#{specs.date.strftime '%Y-%m-%d'})"
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
opts.parse! ARGV
|
45
|
+
if ARGV.length < 1
|
46
|
+
puts opts
|
47
|
+
exit
|
48
|
+
end
|
49
|
+
|
50
|
+
$cmd = ARGV.shift
|
51
|
+
unless %w(start stop restart).include?($cmd)
|
52
|
+
puts "Invalid command specified. Known commands are: start, stop, restart."
|
53
|
+
exit
|
54
|
+
end
|
55
|
+
|
56
|
+
puts $cmd_config.inspect
|
57
|
+
|
58
|
+
ARGV << '.' if ARGV.empty?
|
59
|
+
path = ARGV.shift
|
60
|
+
if File.file?(path)
|
61
|
+
puts "Application file #{path}"
|
62
|
+
require path
|
63
|
+
ServerSide::Application.daemonize($cmd)
|
64
|
+
else
|
65
|
+
fn = File.join(path, 'serverside.rb')
|
66
|
+
if File.file?(fn)
|
67
|
+
puts "Application file #{fn}"
|
68
|
+
require fn
|
69
|
+
ServerSide::Application.daemonize($cmd)
|
70
|
+
else
|
71
|
+
puts "Static file server #{path}"
|
72
|
+
ServerSide::Application::Static.daemonize($cmd_config, $cmd)
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,253 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Module: Daemon</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Module</strong></td>
|
53
|
+
<td class="class-name-in-header">Daemon</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../files/lib/serverside/daemon_rb.html">
|
59
|
+
lib/serverside/daemon.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
<a href="../files/lib/serverside/cluster_rb.html">
|
63
|
+
lib/serverside/cluster.rb
|
64
|
+
</a>
|
65
|
+
<br />
|
66
|
+
</td>
|
67
|
+
</tr>
|
68
|
+
|
69
|
+
</table>
|
70
|
+
</div>
|
71
|
+
<!-- banner header -->
|
72
|
+
|
73
|
+
<div id="bodyContent">
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
<div id="contextContent">
|
78
|
+
|
79
|
+
<div id="description">
|
80
|
+
<p>
|
81
|
+
The <a href="Daemon.html">Daemon</a> module takes care of starting and
|
82
|
+
stopping daemons.
|
83
|
+
</p>
|
84
|
+
|
85
|
+
</div>
|
86
|
+
|
87
|
+
|
88
|
+
</div>
|
89
|
+
|
90
|
+
<div id="method-list">
|
91
|
+
<h3 class="section-bar">Methods</h3>
|
92
|
+
|
93
|
+
<div class="name-list">
|
94
|
+
<a href="#M000005">control</a>
|
95
|
+
<a href="#M000006">start</a>
|
96
|
+
<a href="#M000007">stop</a>
|
97
|
+
</div>
|
98
|
+
</div>
|
99
|
+
|
100
|
+
</div>
|
101
|
+
|
102
|
+
|
103
|
+
<!-- if includes -->
|
104
|
+
|
105
|
+
<div id="section">
|
106
|
+
|
107
|
+
<div id="class-list">
|
108
|
+
<h3 class="section-bar">Classes and Modules</h3>
|
109
|
+
|
110
|
+
Module <a href="Daemon/PidFile.html" class="link">Daemon::PidFile</a><br />
|
111
|
+
Class <a href="Daemon/Base.html" class="link">Daemon::Base</a><br />
|
112
|
+
Class <a href="Daemon/Cluster.html" class="link">Daemon::Cluster</a><br />
|
113
|
+
|
114
|
+
</div>
|
115
|
+
|
116
|
+
<div id="constants-list">
|
117
|
+
<h3 class="section-bar">Constants</h3>
|
118
|
+
|
119
|
+
<div class="name-list">
|
120
|
+
<table summary="Constants">
|
121
|
+
<tr class="top-aligned-row context-row">
|
122
|
+
<td class="context-item-name">WorkingDirectory</td>
|
123
|
+
<td>=</td>
|
124
|
+
<td class="context-item-value">FileUtils.pwd</td>
|
125
|
+
</tr>
|
126
|
+
</table>
|
127
|
+
</div>
|
128
|
+
</div>
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
<!-- if method_list -->
|
136
|
+
<div id="methods">
|
137
|
+
<h3 class="section-bar">Public Class methods</h3>
|
138
|
+
|
139
|
+
<div id="method-M000005" class="method-detail">
|
140
|
+
<a name="M000005"></a>
|
141
|
+
|
142
|
+
<div class="method-heading">
|
143
|
+
<a href="#M000005" class="method-signature">
|
144
|
+
<span class="method-name">control</span><span class="method-args">(daemon, cmd = nil)</span>
|
145
|
+
</a>
|
146
|
+
</div>
|
147
|
+
|
148
|
+
<div class="method-description">
|
149
|
+
<p>
|
150
|
+
Controls a daemon according to the supplied command or command-line
|
151
|
+
parameter. If an invalid command is specified, an error is raised.
|
152
|
+
</p>
|
153
|
+
<p><a class="source-toggle" href="#"
|
154
|
+
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
155
|
+
<div class="method-source-code" id="M000005-source">
|
156
|
+
<pre>
|
157
|
+
<span class="ruby-comment cmt"># File lib/serverside/daemon.rb, line 31</span>
|
158
|
+
31: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">control</span>(<span class="ruby-identifier">daemon</span>, <span class="ruby-identifier">cmd</span> = <span class="ruby-keyword kw">nil</span>)
|
159
|
+
32: <span class="ruby-keyword kw">case</span> (<span class="ruby-identifier">cmd</span> <span class="ruby-operator">||</span> (<span class="ruby-operator">!</span><span class="ruby-constant">ARGV</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">&&</span> <span class="ruby-constant">ARGV</span>[<span class="ruby-value">0</span>]) <span class="ruby-operator">||</span> <span class="ruby-identifier">:nil</span>).<span class="ruby-identifier">to_sym</span>
|
160
|
+
33: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:start</span>
|
161
|
+
34: <span class="ruby-identifier">start</span>(<span class="ruby-identifier">daemon</span>)
|
162
|
+
35: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:stop</span>
|
163
|
+
36: <span class="ruby-identifier">stop</span>(<span class="ruby-identifier">daemon</span>)
|
164
|
+
37: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:restart</span>
|
165
|
+
38: <span class="ruby-identifier">stop</span>(<span class="ruby-identifier">daemon</span>)
|
166
|
+
39: <span class="ruby-identifier">start</span>(<span class="ruby-identifier">daemon</span>)
|
167
|
+
40: <span class="ruby-keyword kw">else</span>
|
168
|
+
41: <span class="ruby-identifier">raise</span> <span class="ruby-value str">'Invalid command. Please specify start, stop or restart.'</span>
|
169
|
+
42: <span class="ruby-keyword kw">end</span>
|
170
|
+
43: <span class="ruby-keyword kw">end</span>
|
171
|
+
</pre>
|
172
|
+
</div>
|
173
|
+
</div>
|
174
|
+
</div>
|
175
|
+
|
176
|
+
<div id="method-M000006" class="method-detail">
|
177
|
+
<a name="M000006"></a>
|
178
|
+
|
179
|
+
<div class="method-heading">
|
180
|
+
<a href="#M000006" class="method-signature">
|
181
|
+
<span class="method-name">start</span><span class="method-args">(daemon)</span>
|
182
|
+
</a>
|
183
|
+
</div>
|
184
|
+
|
185
|
+
<div class="method-description">
|
186
|
+
<p>
|
187
|
+
Starts the daemon by forking and bcoming session leader.
|
188
|
+
</p>
|
189
|
+
<p><a class="source-toggle" href="#"
|
190
|
+
onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
|
191
|
+
<div class="method-source-code" id="M000006-source">
|
192
|
+
<pre>
|
193
|
+
<span class="ruby-comment cmt"># File lib/serverside/daemon.rb, line 46</span>
|
194
|
+
46: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">start</span>(<span class="ruby-identifier">daemon</span>)
|
195
|
+
47: <span class="ruby-identifier">fork</span> <span class="ruby-keyword kw">do</span>
|
196
|
+
48: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
|
197
|
+
49: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
|
198
|
+
50: <span class="ruby-constant">PidFile</span>.<span class="ruby-identifier">store</span>(<span class="ruby-identifier">daemon</span>, <span class="ruby-constant">Process</span>.<span class="ruby-identifier">pid</span>)
|
199
|
+
51: <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">chdir</span> <span class="ruby-constant">WorkingDirectory</span>
|
200
|
+
52: <span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span> <span class="ruby-value">0000</span>
|
201
|
+
53: <span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">"/dev/null"</span>
|
202
|
+
54: <span class="ruby-constant">STDOUT</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-value str">"/dev/null"</span>, <span class="ruby-value str">"a"</span>
|
203
|
+
55: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">reopen</span> <span class="ruby-constant">STDOUT</span>
|
204
|
+
56: <span class="ruby-identifier">trap</span>(<span class="ruby-value str">"TERM"</span>) {<span class="ruby-identifier">daemon</span>.<span class="ruby-identifier">stop</span>; <span class="ruby-identifier">exit</span>}
|
205
|
+
57: <span class="ruby-identifier">daemon</span>.<span class="ruby-identifier">start</span>
|
206
|
+
58: <span class="ruby-keyword kw">end</span>
|
207
|
+
59: <span class="ruby-keyword kw">end</span>
|
208
|
+
</pre>
|
209
|
+
</div>
|
210
|
+
</div>
|
211
|
+
</div>
|
212
|
+
|
213
|
+
<div id="method-M000007" class="method-detail">
|
214
|
+
<a name="M000007"></a>
|
215
|
+
|
216
|
+
<div class="method-heading">
|
217
|
+
<a href="#M000007" class="method-signature">
|
218
|
+
<span class="method-name">stop</span><span class="method-args">(daemon)</span>
|
219
|
+
</a>
|
220
|
+
</div>
|
221
|
+
|
222
|
+
<div class="method-description">
|
223
|
+
<p>
|
224
|
+
Stops the daemon by sending it a TERM signal.
|
225
|
+
</p>
|
226
|
+
<p><a class="source-toggle" href="#"
|
227
|
+
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
228
|
+
<div class="method-source-code" id="M000007-source">
|
229
|
+
<pre>
|
230
|
+
<span class="ruby-comment cmt"># File lib/serverside/daemon.rb, line 62</span>
|
231
|
+
62: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">stop</span>(<span class="ruby-identifier">daemon</span>)
|
232
|
+
63: <span class="ruby-identifier">pid</span> = <span class="ruby-constant">PidFile</span>.<span class="ruby-identifier">recall</span>(<span class="ruby-identifier">daemon</span>)
|
233
|
+
64: <span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">rm</span>(<span class="ruby-identifier">daemon</span>.<span class="ruby-identifier">pid_fn</span>)
|
234
|
+
65: <span class="ruby-identifier">pid</span> <span class="ruby-operator">&&</span> <span class="ruby-constant">Process</span>.<span class="ruby-identifier">kill</span>(<span class="ruby-value str">"TERM"</span>, <span class="ruby-identifier">pid</span>)
|
235
|
+
66: <span class="ruby-keyword kw">end</span>
|
236
|
+
</pre>
|
237
|
+
</div>
|
238
|
+
</div>
|
239
|
+
</div>
|
240
|
+
|
241
|
+
|
242
|
+
</div>
|
243
|
+
|
244
|
+
|
245
|
+
</div>
|
246
|
+
|
247
|
+
|
248
|
+
<div id="validator-badges">
|
249
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
250
|
+
</div>
|
251
|
+
|
252
|
+
</body>
|
253
|
+
</html>
|