daemonchild 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/LICENSE +25 -0
- data/README +49 -0
- data/lib/daemonchild.rb +80 -0
- data/test/test_daemonchild.rb +10 -0
- metadata +66 -0
data/CHANGELOG
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
== LICENSE:
|
2
|
+
|
3
|
+
(The MIT License)
|
4
|
+
|
5
|
+
Copyright (c) 2010 Jason Rohwedder
|
6
|
+
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
8
|
+
a copy of this software and associated documentation files (the
|
9
|
+
'Software'), to deal in the Software without restriction, including
|
10
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
11
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
12
|
+
permit persons to whom the Software is furnished to do so, subject to
|
13
|
+
the following conditions:
|
14
|
+
|
15
|
+
The above copyright notice and this permission notice shall be
|
16
|
+
included in all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
19
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
20
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
21
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
22
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
23
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
24
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
25
|
+
|
data/README
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
= DaemonChild
|
2
|
+
|
3
|
+
A stripped down and hopefully more straightforward way to write daemons in
|
4
|
+
Ruby.
|
5
|
+
|
6
|
+
* http://github.com/jro/daemonchild
|
7
|
+
|
8
|
+
== FEATURES/PROBLEMS:
|
9
|
+
|
10
|
+
* There aren't a lot. It should just turn the running script into a
|
11
|
+
daemon. From there it's all on you.
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
require 'DaemonChild'
|
16
|
+
|
17
|
+
DaemonChild.spawn
|
18
|
+
<insert your code here>
|
19
|
+
|
20
|
+
== INSTALL:
|
21
|
+
|
22
|
+
* gem install daemonchild
|
23
|
+
|
24
|
+
== LICENSE
|
25
|
+
|
26
|
+
(The MIT License)
|
27
|
+
|
28
|
+
Copyright (c) 2010 Jason Rohwedder
|
29
|
+
|
30
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
31
|
+
a copy of this software and associated documentation files (the
|
32
|
+
'Software'), to deal in the Software without restriction, including
|
33
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
34
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
35
|
+
permit persons to whom the Software is furnished to do so, subject to
|
36
|
+
the following conditions:
|
37
|
+
|
38
|
+
The above copyright notice and this permission notice shall be
|
39
|
+
included in all copies or substantial portions of the Software.
|
40
|
+
|
41
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
42
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
43
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
44
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
45
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
46
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
47
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
48
|
+
|
49
|
+
|
data/lib/daemonchild.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
|
2
|
+
# == Credits
|
3
|
+
#
|
4
|
+
# Inspired by and based on Daemonize as distributed as part of
|
5
|
+
# Thomas Uehlinger's Daemons gem.
|
6
|
+
#
|
7
|
+
# Daemonize was written by Travis Whitton and is based on Perl's
|
8
|
+
# Proc::Daemonize, which was written by Earl Hood.
|
9
|
+
#
|
10
|
+
# Based on the Unix Programmer FAQ which is currently available
|
11
|
+
# http://www.faqs.org/faqs/unix-faq/programmer/faq/
|
12
|
+
# (and other places I'm sure)
|
13
|
+
|
14
|
+
class DaemonChild
|
15
|
+
VERSION = '0.0.1'
|
16
|
+
|
17
|
+
def self.spawn()
|
18
|
+
# Exit fast if in app that presents itself as irb
|
19
|
+
# as a rudimentary safety check. if irb daemonizes and gets
|
20
|
+
# /dev/null as STDIN, it chews up all the cpu trying to take input
|
21
|
+
# but you really shouldn't daemonize irb anyway
|
22
|
+
exit if $0 == 'irb'
|
23
|
+
|
24
|
+
cwd = Dir.getwd
|
25
|
+
|
26
|
+
# Fork so the parent can exit
|
27
|
+
Process.fork and Process.exit
|
28
|
+
|
29
|
+
# Become a process group and session group leader
|
30
|
+
sid = Process.setsid
|
31
|
+
|
32
|
+
# Fork so the session group leader can exit and we can not regain
|
33
|
+
# a controlling terminal
|
34
|
+
Process.fork and Process.exit
|
35
|
+
|
36
|
+
# Return to original working directory
|
37
|
+
Dir.chdir cwd
|
38
|
+
|
39
|
+
# Give ourselves complete control over permissions of files we'd write
|
40
|
+
File.umask 0
|
41
|
+
|
42
|
+
# Close any open filehandles
|
43
|
+
ObjectSpace.each_object(IO) do |io|
|
44
|
+
begin
|
45
|
+
io.close unless io.closed?
|
46
|
+
rescue ::Exception
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Reopen stdin, stdout, stdin to /dev/null
|
51
|
+
[STDIN,STDOUT,STDERR].each do |io|
|
52
|
+
begin
|
53
|
+
io.reopen '/dev/null'
|
54
|
+
rescue ::Exception
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
return Process.pid
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.process_name
|
62
|
+
$0
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.process_name=(name)
|
66
|
+
$0 = name
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.stdin=(fp)
|
70
|
+
STDIN.reopen fp
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.stdout=(fp)
|
74
|
+
STDOUT.reopen fp
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.stderr=(fp)
|
78
|
+
STDERR.reopen fp
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: daemonchild
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jason Rohwedder
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-09-04 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: jro@badgerhound.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- CHANGELOG
|
24
|
+
- lib/daemonchild.rb
|
25
|
+
- LICENSE
|
26
|
+
- README
|
27
|
+
files:
|
28
|
+
- CHANGELOG
|
29
|
+
- lib/daemonchild.rb
|
30
|
+
- LICENSE
|
31
|
+
- README
|
32
|
+
has_rdoc: true
|
33
|
+
homepage: http://github.com/jro/daemonchild
|
34
|
+
licenses: []
|
35
|
+
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options:
|
38
|
+
- --line-numbers
|
39
|
+
- --inline-source
|
40
|
+
- --title
|
41
|
+
- DaemonChild
|
42
|
+
- --main
|
43
|
+
- README
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.3.5
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: A stripped down and straightforward way to write daemons in Ruby.
|
65
|
+
test_files:
|
66
|
+
- test/test_daemonchild.rb
|