daemonic 0.0.1 → 0.0.2
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.
- checksums.yaml +7 -0
- data/README.md +27 -0
- data/bin/daemonic +2 -10
- data/lib/daemonic/configuration.rb +5 -9
- data/lib/daemonic/master.rb +6 -6
- data/lib/daemonic/version.rb +1 -1
- data/lib/daemonic.rb +5 -5
- data/test/integration_test.rb +17 -0
- metadata +9 -15
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c90af55fdad70a6c4a99fc782c9fa34fb7ed6939
|
4
|
+
data.tar.gz: 08b9b435ce0d8e4c5b87978b66f804a55b388dab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d6a23fc8d43c33e1346dce80900130ea7c703d80b05e6028cbb8cb7d0c8c44315f3aad50d1a20f17bcc849412b77376db282582e6b9a2fb16c4d38cfdf1fc444
|
7
|
+
data.tar.gz: e38c14642dc4d6c5b618610b62bfd30e3b315571dff5cf2cbf36ff7e040be1b3735522c85c6e8f841c20ca0986485ddc4a90ebd6a043d69592d93a6654120f74
|
data/README.md
CHANGED
@@ -87,6 +87,33 @@ These are the signals daemonic responds to:
|
|
87
87
|
* `TTIN` increase the number of workers by one
|
88
88
|
* `TTOU` decrease the number of workers by one
|
89
89
|
|
90
|
+
### Creating a worker
|
91
|
+
|
92
|
+
Here's an example of a basic daemonic worker:
|
93
|
+
|
94
|
+
``` ruby
|
95
|
+
exiting = false
|
96
|
+
|
97
|
+
trap("TERM") { exiting = true }
|
98
|
+
trap("INT") { exiting = true }
|
99
|
+
trap("HUP") {
|
100
|
+
# reload settings
|
101
|
+
}
|
102
|
+
|
103
|
+
puts "Booting worker number #{ENV["DAEMON_WORKER_NUMBER"]}"
|
104
|
+
|
105
|
+
SomePollingService.poll do
|
106
|
+
# do your work here
|
107
|
+
break if exiting
|
108
|
+
end
|
109
|
+
|
110
|
+
puts "Shutting down worker number #{ENV["DAEMON_WORKER_NUMBER"]}"
|
111
|
+
```
|
112
|
+
|
113
|
+
Most importantly:
|
114
|
+
|
115
|
+
* Trap INT and TERM signals to cleanly stop your process
|
116
|
+
|
90
117
|
## Contributing
|
91
118
|
|
92
119
|
1. Fork it
|
data/bin/daemonic
CHANGED
@@ -2,13 +2,5 @@
|
|
2
2
|
$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
|
3
3
|
|
4
4
|
require 'daemonic'
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
config.reload
|
9
|
-
|
10
|
-
if config.daemonize?
|
11
|
-
Process.daemon
|
12
|
-
end
|
13
|
-
|
14
|
-
Daemonic.spawn(config)
|
5
|
+
options = Daemonic::CLI.parse(ARGV)
|
6
|
+
Daemonic.start(options)
|
@@ -6,10 +6,10 @@ module Daemonic
|
|
6
6
|
|
7
7
|
Invalid = Class.new(ArgumentError)
|
8
8
|
|
9
|
-
attr_reader :eventual_config, :
|
9
|
+
attr_reader :eventual_config, :given_options
|
10
10
|
|
11
|
-
def initialize(
|
12
|
-
@
|
11
|
+
def initialize(given_options, pwd)
|
12
|
+
@given_options = given_options
|
13
13
|
@pwd = pwd
|
14
14
|
@eventual_config = {}
|
15
15
|
end
|
@@ -34,9 +34,9 @@ module Daemonic
|
|
34
34
|
@eventual_config = {}
|
35
35
|
@logger = nil
|
36
36
|
load_options defaults
|
37
|
-
load_options
|
37
|
+
load_options given_options
|
38
38
|
load_options config_file_options if config_file
|
39
|
-
load_options
|
39
|
+
load_options given_options
|
40
40
|
logger.debug { to_h.inspect }
|
41
41
|
validate
|
42
42
|
end
|
@@ -92,10 +92,6 @@ module Daemonic
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
def command_line_options
|
96
|
-
CLI.parse(args)
|
97
|
-
end
|
98
|
-
|
99
95
|
def config_file_options
|
100
96
|
contents = File.open(config_file, 'r:utf-8').read
|
101
97
|
args = Shellwords.split(contents)
|
data/lib/daemonic/master.rb
CHANGED
@@ -76,12 +76,12 @@ module Daemonic
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def trap_signals
|
79
|
-
trap("USR2") { info "USR2 received!"; restart }
|
80
|
-
trap("TERM") { info "TERM received!"; stop }
|
81
|
-
trap("INT") { info "INT received!"; stop }
|
82
|
-
trap("HUP") { info "HUP received!"; hup }
|
83
|
-
trap("TTIN") { info "TTIN received!"; ttin }
|
84
|
-
trap("TTOU") { info "TTOU received!"; ttou }
|
79
|
+
trap("USR2") { Thread.new { info "USR2 received!"; restart } }
|
80
|
+
trap("TERM") { Thread.new { info "TERM received!"; stop } }
|
81
|
+
trap("INT") { Thread.new { info "INT received!"; stop } }
|
82
|
+
trap("HUP") { Thread.new { info "HUP received!"; hup } }
|
83
|
+
trap("TTIN") { Thread.new { info "TTIN received!"; ttin } }
|
84
|
+
trap("TTOU") { Thread.new { info "TTOU received!"; ttou } }
|
85
85
|
end
|
86
86
|
|
87
87
|
def ttin
|
data/lib/daemonic/version.rb
CHANGED
data/lib/daemonic.rb
CHANGED
@@ -6,12 +6,12 @@ require "daemonic/cli"
|
|
6
6
|
|
7
7
|
module Daemonic
|
8
8
|
|
9
|
-
def self.
|
10
|
-
|
9
|
+
def self.start(options)
|
10
|
+
config = Configuration.new(options, Dir.pwd)
|
11
|
+
config.reload
|
12
|
+
Process.daemon if config.daemonize?
|
13
|
+
Master.new(config).start
|
11
14
|
end
|
12
15
|
|
13
|
-
def self.configuration(*args)
|
14
|
-
Configuration.new(*args)
|
15
|
-
end
|
16
16
|
|
17
17
|
end
|
data/test/integration_test.rb
CHANGED
@@ -19,6 +19,23 @@ class TestIntegration < MiniTest::Unit::TestCase
|
|
19
19
|
wait_for(10) { not running? master_pid }
|
20
20
|
end
|
21
21
|
|
22
|
+
def test_start_daemonic_programmatically
|
23
|
+
$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
|
24
|
+
require 'daemonic'
|
25
|
+
Thread.new {
|
26
|
+
Daemonic.start(
|
27
|
+
name: "daemon-test",
|
28
|
+
workers: 5,
|
29
|
+
command: "ruby test/test_daemon.rb",
|
30
|
+
logfile: LOGFILE,
|
31
|
+
pidfile: "tmp/test.pid",
|
32
|
+
)
|
33
|
+
}
|
34
|
+
sleep 0.2
|
35
|
+
master_pid = Integer(File.open("tmp/test.pid").read)
|
36
|
+
perform_tests(master_pid)
|
37
|
+
end
|
38
|
+
|
22
39
|
def setup
|
23
40
|
FileUtils.mkdir_p(File.dirname(LOGFILE))
|
24
41
|
FileUtils.rm(LOGFILE) if File.exist?(LOGFILE)
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daemonic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- iain
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-01-07 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,17 +27,15 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
description: Manages daemonizing your workers with basic monitoring and restart behavior.
|
@@ -74,27 +69,26 @@ files:
|
|
74
69
|
homepage: https://github.com/yourkarma/daemonic
|
75
70
|
licenses:
|
76
71
|
- MIT
|
72
|
+
metadata: {}
|
77
73
|
post_install_message:
|
78
74
|
rdoc_options: []
|
79
75
|
require_paths:
|
80
76
|
- lib
|
81
77
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
78
|
requirements:
|
84
|
-
- -
|
79
|
+
- - '>='
|
85
80
|
- !ruby/object:Gem::Version
|
86
81
|
version: '0'
|
87
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
-
none: false
|
89
83
|
requirements:
|
90
|
-
- -
|
84
|
+
- - '>='
|
91
85
|
- !ruby/object:Gem::Version
|
92
86
|
version: '0'
|
93
87
|
requirements: []
|
94
88
|
rubyforge_project:
|
95
|
-
rubygems_version: 1.
|
89
|
+
rubygems_version: 2.1.0
|
96
90
|
signing_key:
|
97
|
-
specification_version:
|
91
|
+
specification_version: 4
|
98
92
|
summary: Manages daemonizing your workers with basic monitoring and restart behavior.
|
99
93
|
test_files:
|
100
94
|
- test/config
|