ebb 0.0.4 → 0.1.0

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/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.4
@@ -1,98 +0,0 @@
1
- # Simplified version of Thin::Daemonizable by Marc-André Cournoyer
2
-
3
- module Kernel
4
- unless respond_to? :daemonize # Already part of Ruby 1.9, yeah!
5
- # Turns the current script into a daemon process that detaches from the console.
6
- # It can be shut down with a TERM signal. Taken from ActiveSupport.
7
- def daemonize
8
- exit if fork # Parent exits, child continues.
9
- Process.setsid # Become session leader.
10
- exit if fork # Zap session leader. See [1].
11
- Dir.chdir "/" # Release old working directory.
12
- File.umask 0000 # Ensure sensible umask. Adjust as needed.
13
- STDIN.reopen "/dev/null" # Free file descriptors and
14
- STDOUT.reopen "/dev/null", "a" # point them somewhere sensible.
15
- STDERR.reopen STDOUT # STDOUT/ERR should better go to a logfile.
16
- trap("TERM") { exit }
17
- end
18
- end
19
- end
20
-
21
- module Process
22
- # Returns +true+ the process identied by +pid+ is running.
23
- def running?(pid)
24
- Process.getpgid(pid) != -1
25
- rescue Errno::ESRCH
26
- false
27
- end
28
- module_function :running?
29
- end
30
-
31
- # Moadule included in classes that can be turned into a daemon.
32
- # Handle stuff like:
33
- # * storing the PID in a file
34
- # * redirecting output to the log file
35
- # * killing the process gracefully
36
- module Daemonizable
37
- attr_accessor :pid_file, :log_file, :timeout
38
-
39
- def pid
40
- File.exist?(pid_file) ? open(pid_file).read : nil
41
- end
42
-
43
- # Turns the current script into a daemon process that detaches from the console.
44
- def daemonize
45
- raise ArgumentError, 'You must specify a pid_file to deamonize' unless @pid_file
46
-
47
- pwd = Dir.pwd # Current directory is changed during daemonization, so store it
48
- Kernel.daemonize
49
- Dir.chdir pwd
50
-
51
- trap('HUP', 'IGNORE') # Don't die upon logout
52
-
53
- # Redirect output to the logfile
54
- [STDOUT, STDERR].each { |f| f.reopen @log_file, 'a' } if @log_file
55
-
56
- write_pid_file
57
- at_exit do
58
- log ">> Exiting!"
59
- remove_pid_file
60
- end
61
- end
62
-
63
- # Kill the process which PID is stored in +pid_file+.
64
- def self.kill(pid_file, timeout=60)
65
- if pid = open(pid_file).read
66
- pid = pid.to_i
67
- print "Sending INT signal to process #{pid} ... "
68
- begin
69
- Process.kill('INT', pid)
70
- Timeout.timeout(timeout) do
71
- sleep 0.1 while Process.running?(pid)
72
- end
73
- rescue Timeout::Error
74
- print "timeout, Sending KILL signal ... "
75
- Process.kill('KILL', pid)
76
- end
77
- puts "stopped!"
78
- else
79
- puts "Can't stop process, no PID found in #{@pid_file}"
80
- end
81
- rescue Errno::ESRCH # No such process
82
- puts "process not found!"
83
- ensure
84
- File.delete(pid_file) rescue nil
85
- end
86
-
87
- private
88
-
89
- def remove_pid_file
90
- File.delete(@pid_file) if @pid_file && File.exists?(@pid_file)
91
- end
92
-
93
- def write_pid_file
94
- log ">> Writing PID to #{@pid_file}"
95
- open(@pid_file,"w+") { |f| f.write(Process.pid) }
96
- File.chmod(0644, @pid_file)
97
- end
98
- end
@@ -1,16 +0,0 @@
1
- require 'rubygems'
2
- require 'json'
3
- require File.dirname(__FILE__) + '/../ruby_lib/ebb'
4
-
5
-
6
- class EchoApp
7
- def call(env)
8
- env['rack.input'] = env['rack.input'].read(1000000)
9
- env.delete('rack.errors')
10
- [200, {'Content-Type' => 'text/json'}, env.to_json]
11
- end
12
- end
13
-
14
-
15
- server = Ebb::Server.new(EchoApp.new, :port => 4037)
16
- server.start
@@ -1,15 +0,0 @@
1
- import sys
2
- sys.path.append('/Users/ry/projects/ebb/build/lib.macosx-10.3-ppc-2.5')
3
- import ebb
4
-
5
- print "hello"
6
-
7
- def simple_app(environ, start_response):
8
- """Simplest possible application object"""
9
- status = '200 OK'
10
- print repr(environ)
11
- response_headers = [('Content-type','text/plain')]
12
- #start_response(status, response_headers)
13
- return ['Hello world!\n']
14
-
15
- ebb.start_server(simple_app, 4000)