ripta-daemon-kit 0.1.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.
- data/History.txt +7 -0
- data/Manifest.txt +58 -0
- data/PostInstall.txt +6 -0
- data/README.textile +77 -0
- data/Rakefile +30 -0
- data/TODO.txt +24 -0
- data/app_generators/daemon_kit/USAGE +7 -0
- data/app_generators/daemon_kit/daemon_kit_generator.rb +121 -0
- data/app_generators/daemon_kit/templates/README +48 -0
- data/app_generators/daemon_kit/templates/Rakefile +4 -0
- data/app_generators/daemon_kit/templates/bin/daemon.erb +7 -0
- data/app_generators/daemon_kit/templates/config/boot.rb +52 -0
- data/app_generators/daemon_kit/templates/config/environment.rb +19 -0
- data/app_generators/daemon_kit/templates/config/environments/development.rb +0 -0
- data/app_generators/daemon_kit/templates/config/environments/production.rb +0 -0
- data/app_generators/daemon_kit/templates/config/environments/test.rb +0 -0
- data/app_generators/daemon_kit/templates/config/initializers/readme +11 -0
- data/app_generators/daemon_kit/templates/libexec/daemon.erb +18 -0
- data/bin/daemon_kit +19 -0
- data/daemon_generators/jabber/USAGE +5 -0
- data/daemon_generators/jabber/jabber_generator.rb +65 -0
- data/daemon_generators/jabber/templates/config/initializers/jabber.rb +8 -0
- data/daemon_generators/jabber/templates/config/jabber.yml +26 -0
- data/daemon_generators/jabber/templates/libexec/daemon.rb +27 -0
- data/lib/daemon_kit/application.rb +32 -0
- data/lib/daemon_kit/initializer.rb +249 -0
- data/lib/daemon_kit/jabber.rb +172 -0
- data/lib/daemon_kit/patches/force_kill_wait.rb +120 -0
- data/lib/daemon_kit/tasks/framework.rake +75 -0
- data/lib/daemon_kit/tasks.rb +2 -0
- data/lib/daemon_kit.rb +11 -0
- data/rubygems_generators/install_rspec/USAGE +5 -0
- data/rubygems_generators/install_rspec/install_rspec_generator.rb +57 -0
- data/rubygems_generators/install_rspec/templates/spec/spec.opts +1 -0
- data/rubygems_generators/install_rspec/templates/spec/spec_helper.rb +10 -0
- data/rubygems_generators/install_rspec/templates/spec.rb +11 -0
- data/rubygems_generators/install_rspec/templates/tasks/rspec.rake +21 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +71 -0
- data/spec/daemon_kit_spec.rb +7 -0
- data/spec/initializer_spec.rb +31 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +30 -0
- data/tasks/rspec.rake +21 -0
- data/test/test_daemon-kit_generator.rb +67 -0
- data/test/test_generator_helper.rb +29 -0
- data/test/test_jabber_generator.rb +49 -0
- metadata +150 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
PostInstall.txt
|
4
|
+
README.textile
|
5
|
+
Rakefile
|
6
|
+
TODO.txt
|
7
|
+
app_generators/daemon_kit/USAGE
|
8
|
+
app_generators/daemon_kit/daemon_kit_generator.rb
|
9
|
+
app_generators/daemon_kit/templates/README
|
10
|
+
app_generators/daemon_kit/templates/Rakefile
|
11
|
+
app_generators/daemon_kit/templates/bin/daemon.erb
|
12
|
+
app_generators/daemon_kit/templates/config/boot.rb
|
13
|
+
app_generators/daemon_kit/templates/config/environment.rb
|
14
|
+
app_generators/daemon_kit/templates/config/environments/development.rb
|
15
|
+
app_generators/daemon_kit/templates/config/environments/production.rb
|
16
|
+
app_generators/daemon_kit/templates/config/environments/test.rb
|
17
|
+
app_generators/daemon_kit/templates/config/initializers/readme
|
18
|
+
app_generators/daemon_kit/templates/libexec/daemon.erb
|
19
|
+
bin/daemon_kit
|
20
|
+
config/website.yml.sample
|
21
|
+
daemon_generators/jabber/USAGE
|
22
|
+
daemon_generators/jabber/jabber_generator.rb
|
23
|
+
daemon_generators/jabber/templates/config/initializers/jabber.rb
|
24
|
+
daemon_generators/jabber/templates/config/jabber.yml
|
25
|
+
daemon_generators/jabber/templates/libexec/daemon.rb
|
26
|
+
features/development.feature
|
27
|
+
features/steps/common.rb
|
28
|
+
features/steps/env.rb
|
29
|
+
lib/daemon_kit.rb
|
30
|
+
lib/daemon_kit/application.rb
|
31
|
+
lib/daemon_kit/initializer.rb
|
32
|
+
lib/daemon_kit/jabber.rb
|
33
|
+
lib/daemon_kit/patches/force_kill_wait.rb
|
34
|
+
lib/daemon_kit/tasks.rb
|
35
|
+
lib/daemon_kit/tasks/framework.rake
|
36
|
+
rubygems_generators/install_rspec/USAGE
|
37
|
+
rubygems_generators/install_rspec/install_rspec_generator.rb
|
38
|
+
rubygems_generators/install_rspec/templates/spec.rb
|
39
|
+
rubygems_generators/install_rspec/templates/spec/spec.opts
|
40
|
+
rubygems_generators/install_rspec/templates/spec/spec_helper.rb
|
41
|
+
rubygems_generators/install_rspec/templates/tasks/rspec.rake
|
42
|
+
script/console
|
43
|
+
script/destroy
|
44
|
+
script/generate
|
45
|
+
script/txt2html
|
46
|
+
spec/daemon_kit_spec.rb
|
47
|
+
spec/initializer_spec.rb
|
48
|
+
spec/spec.opts
|
49
|
+
spec/spec_helper.rb
|
50
|
+
tasks/rspec.rake
|
51
|
+
test/test_daemon-kit_generator.rb
|
52
|
+
test/test_generator_helper.rb
|
53
|
+
test/test_jabber_generator.rb
|
54
|
+
website/index.html
|
55
|
+
website/index.txt
|
56
|
+
website/javascripts/rounded_corners_lite.inc.js
|
57
|
+
website/stylesheets/screen.css
|
58
|
+
website/template.html.erb
|
data/PostInstall.txt
ADDED
data/README.textile
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
h1. Daemon Kit
|
2
|
+
|
3
|
+
* http://daemon-kit.rubyforge.org/ (coming soon)
|
4
|
+
|
5
|
+
h2. Description
|
6
|
+
|
7
|
+
Daemon Kit aims to simplify creating Ruby daemons by providing a sound application skeleton (through a generator), task specific generators (jabber bot, etc) and robust environment management code.
|
8
|
+
|
9
|
+
Using simple built-in generators it is easy to created evented and non-evented daemons that perform a multitude of different tasks.
|
10
|
+
|
11
|
+
Supported generators:
|
12
|
+
|
13
|
+
* Evented and non-evented Jabber Bot (coming next)
|
14
|
+
* Evented and non-evented loops (coming soon)
|
15
|
+
* Queue poller (SQS, AMQP, etc) (coming soon)
|
16
|
+
|
17
|
+
h2. Features/Problems
|
18
|
+
|
19
|
+
* Build it
|
20
|
+
* Review TODO.txt
|
21
|
+
|
22
|
+
h2. Synopsis
|
23
|
+
|
24
|
+
$ daemon-kit [/path/to/your/daemon] [options]
|
25
|
+
|
26
|
+
The above command generates a skeleton daemon environment for you to adapt.
|
27
|
+
|
28
|
+
$ daemon-kit [/path/to/your/daemon] -i jabber
|
29
|
+
|
30
|
+
Use the 'jabber' generator instead of the default one.
|
31
|
+
|
32
|
+
h2. Generators
|
33
|
+
|
34
|
+
Currently only two generators exist, a 'default' generator and a 'jabber' generator.
|
35
|
+
|
36
|
+
The default generator creates a simple daemon with an infinite loop inside that you can adapt.
|
37
|
+
|
38
|
+
The jabber generator creates a simple daemon that leverages the "xmpp4r-simple":http://xmpp4r-simple.rubyforge.org/ gem to process inbound messages. The daemon will manage the roster and other little tasks, leaving you to provide the hooks for processing messages, presence notifications and subscription request.
|
39
|
+
|
40
|
+
h2. Requirements
|
41
|
+
|
42
|
+
* Ruby 1.8.6
|
43
|
+
* daemons 1.0.10
|
44
|
+
* xmpp4r-simple 0.8.8 (if using the 'jabber' generator)
|
45
|
+
* eventmachine 0.12.2 (if using any of the evented generators)
|
46
|
+
* rspec 1.1.11 (for writing/running your specs)
|
47
|
+
|
48
|
+
h2. Install
|
49
|
+
|
50
|
+
$ git clone git://github.com/kennethkalmer/daemon-kit.git
|
51
|
+
$ rake gem
|
52
|
+
$ gem install pkg/daemon-kit-X.X.X.gem
|
53
|
+
|
54
|
+
h2. License
|
55
|
+
|
56
|
+
(The MIT License)
|
57
|
+
|
58
|
+
Copyright (c) 2009 Kenneth Kalmer (Internet Exchange CC, Clear Planet Information Solutions Pty Ltd)
|
59
|
+
|
60
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
61
|
+
a copy of this software and associated documentation files (the
|
62
|
+
'Software'), to deal in the Software without restriction, including
|
63
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
64
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
65
|
+
permit persons to whom the Software is furnished to do so, subject to
|
66
|
+
the following conditions:
|
67
|
+
|
68
|
+
The above copyright notice and this permission notice shall be
|
69
|
+
included in all copies or substantial portions of the Software.
|
70
|
+
|
71
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
72
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
73
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
74
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
75
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
76
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
77
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
3
|
+
require File.dirname(__FILE__) + '/lib/daemon_kit'
|
4
|
+
|
5
|
+
# Generate all the Rake tasks
|
6
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
7
|
+
$hoe = Hoe.new('daemon-kit', DaemonKit::VERSION) do |p|
|
8
|
+
p.summary = 'Daemon Kit aims to simplify creating Ruby daemons by providing a sound application skeleton (through a generator), task specific generators (jabber bot, etc) and robust environment management code.'
|
9
|
+
p.developer('Kenneth Kalmer', 'kenneth.kalmer@gmail.com')
|
10
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
11
|
+
p.post_install_message = IO.read( 'PostInstall.txt' ) # TODO remove if post-install message not required
|
12
|
+
p.rubyforge_name = p.name # TODO this is default value
|
13
|
+
p.extra_deps = [
|
14
|
+
['daemons','>= 1.0.10'],
|
15
|
+
]
|
16
|
+
p.extra_dev_deps = [
|
17
|
+
['newgem', ">= #{::Newgem::VERSION}"]
|
18
|
+
]
|
19
|
+
|
20
|
+
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
21
|
+
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
22
|
+
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
23
|
+
p.rsync_args = '-av --delete --ignore-errors'
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'newgem/tasks' # load /tasks/*.rake
|
27
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
28
|
+
|
29
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
30
|
+
task :default => [:spec] #, :features]
|
data/TODO.txt
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
DaemonKit TODO List
|
2
|
+
===================
|
3
|
+
|
4
|
+
This is purely a drop in the bucket of what has to come...
|
5
|
+
|
6
|
+
* [DONE] Easy way to trap signals
|
7
|
+
* Error handling to the degree Rails does
|
8
|
+
* Easy configuration of an ORM of choice, including patching it if needed (ActiveRecourd *cough*)
|
9
|
+
* Improved generators for creating skeleton daemons:
|
10
|
+
* [DONE] Jabber bot
|
11
|
+
* Evented jabber bot
|
12
|
+
* Empty periodic event loop
|
13
|
+
* Empty periodic loop (non-evented)
|
14
|
+
* Queue (SQS, AMQP, etc) pollers
|
15
|
+
* Rake tasks for generating:
|
16
|
+
* god configs
|
17
|
+
* Pre-built capistrano configs for easy deployment
|
18
|
+
* Support for dropping privileges
|
19
|
+
* Support for chroot'ing
|
20
|
+
* Improved and cleaned up logging
|
21
|
+
* Plenty of docs, seriously a lot of docs
|
22
|
+
* Specs & features, tons of them too
|
23
|
+
* Some level of thread safety, or mechanisms to ease thread safety
|
24
|
+
* DON'T FORGET 1.9 SUPPORT
|
@@ -0,0 +1,7 @@
|
|
1
|
+
Description:
|
2
|
+
This generator creates a new skeleton project suitable for easy
|
3
|
+
Ruby daemon development. The generated project is preconfigured
|
4
|
+
and just requires your task specific code.
|
5
|
+
|
6
|
+
Use one of the provided generators to stub out even more
|
7
|
+
functionality for common daemon patterns.
|
@@ -0,0 +1,121 @@
|
|
1
|
+
class DaemonKitGenerator < RubiGen::Base
|
2
|
+
|
3
|
+
DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
|
4
|
+
Config::CONFIG['ruby_install_name'])
|
5
|
+
|
6
|
+
VALID_GENERATORS = ['default', 'jabber']
|
7
|
+
|
8
|
+
default_options :shebang => DEFAULT_SHEBANG,
|
9
|
+
:author => nil
|
10
|
+
|
11
|
+
attr_reader :daemon_name
|
12
|
+
attr_reader :installer
|
13
|
+
|
14
|
+
def initialize(runtime_args, runtime_options = {})
|
15
|
+
super
|
16
|
+
usage if args.empty?
|
17
|
+
@destination_root = File.expand_path(args.shift)
|
18
|
+
@daemon_name = base_name
|
19
|
+
extract_options
|
20
|
+
end
|
21
|
+
|
22
|
+
def manifest
|
23
|
+
# ensure some sanity
|
24
|
+
unless VALID_GENERATORS.include?( installer )
|
25
|
+
$stderr.puts "Invalid generator: '#{installer}'."
|
26
|
+
$stderr.puts "Valid generators are: #{VALID_GENERATORS.join(', ')}"
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
|
30
|
+
script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
|
31
|
+
|
32
|
+
record do |m|
|
33
|
+
# Ensure appropriate folder(s) exists
|
34
|
+
m.directory ''
|
35
|
+
|
36
|
+
# Create stubs
|
37
|
+
# m.template "template.rb", "some_file_after_erb.rb"
|
38
|
+
# m.template_copy_each ["template.rb", "template2.rb"]
|
39
|
+
# m.file "file", "some_file_copied"
|
40
|
+
# m.file_copy_each ["path/to/file", "path/to/file2"]
|
41
|
+
|
42
|
+
# Readme
|
43
|
+
m.template "README", "README"
|
44
|
+
m.template "Rakefile", "Rakefile"
|
45
|
+
|
46
|
+
# Executable
|
47
|
+
m.directory "bin"
|
48
|
+
m.template "bin/daemon.erb", "bin/#{daemon_name}", script_options
|
49
|
+
|
50
|
+
# Generator
|
51
|
+
if installer == "default"
|
52
|
+
m.directory "libexec"
|
53
|
+
m.template "libexec/daemon.erb", "libexec/#{daemon_name}.rb"
|
54
|
+
else
|
55
|
+
m.dependency installer, [daemon_name], :destination => destination_root, :collision => :force
|
56
|
+
end
|
57
|
+
|
58
|
+
# Config/Environment
|
59
|
+
m.directory "config"
|
60
|
+
m.file "config/boot.rb", "config/boot.rb"
|
61
|
+
m.template "config/environment.rb", "config/environment.rb"
|
62
|
+
m.directory "config/environments"
|
63
|
+
%w{ development test production }.each { |f| m.file "config/environments/#{f}.rb", "config/environments/#{f}.rb" }
|
64
|
+
m.directory "config/initializers"
|
65
|
+
m.file "config/initializers/readme", "config/initializers/readme"
|
66
|
+
|
67
|
+
# Libraries
|
68
|
+
m.directory "lib"
|
69
|
+
|
70
|
+
# Tests
|
71
|
+
m.directory "tasks"
|
72
|
+
m.dependency "install_rspec", [daemon_name], :destination => destination_root, :collision => :force
|
73
|
+
|
74
|
+
# Others
|
75
|
+
m.directory "log"
|
76
|
+
m.directory "tmp"
|
77
|
+
m.directory "vendor"
|
78
|
+
|
79
|
+
m.dependency "install_rubigen_scripts", [destination_root, 'daemon_kit'],
|
80
|
+
:shebang => options[:shebang], :collision => :force
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
protected
|
85
|
+
def banner
|
86
|
+
<<-EOS
|
87
|
+
Creates a preconfigured environment for writing Ruby daemon processes.
|
88
|
+
|
89
|
+
USAGE: #{spec.name} /path/to/your/daemon [options]
|
90
|
+
EOS
|
91
|
+
end
|
92
|
+
|
93
|
+
def add_options!(opts)
|
94
|
+
opts.separator ''
|
95
|
+
opts.separator 'Options:'
|
96
|
+
# For each option below, place the default
|
97
|
+
# at the top of the file next to "default_options"
|
98
|
+
# opts.on("-a", "--author=\"Your Name\"", String,
|
99
|
+
# "Some comment about this option",
|
100
|
+
# "Default: none") { |o| options[:author] = o }
|
101
|
+
opts.on("-i", "--install=generator", String,
|
102
|
+
"Select a generator to use (other than the default).",
|
103
|
+
"Available generators: #{VALID_GENERATORS.join(', ')}",
|
104
|
+
"Defaults to: default") do |installer|
|
105
|
+
options[:installer] = installer
|
106
|
+
end
|
107
|
+
opts.on("-r", "--ruby=path", String,
|
108
|
+
"Path to the Ruby binary of your choice (otherwise scripts use env, dispatchers current path).",
|
109
|
+
"Default: #{DEFAULT_SHEBANG}") { |x| options[:shebang] = x }
|
110
|
+
opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
111
|
+
end
|
112
|
+
|
113
|
+
def extract_options
|
114
|
+
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
|
115
|
+
# Templates can access these value via the attr_reader-generated methods, but not the
|
116
|
+
# raw instance variable value.
|
117
|
+
# @author = options[:author]
|
118
|
+
@installer = options[:installer] || 'default'
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
DaemonKit README
|
2
|
+
================
|
3
|
+
|
4
|
+
DaemonKit has generated a skeleton Ruby daemon for you to build on. Please read
|
5
|
+
through this file to ensure you get going quickly.
|
6
|
+
|
7
|
+
Directories
|
8
|
+
===========
|
9
|
+
|
10
|
+
bin/
|
11
|
+
<%= daemon_name %> - Stub executable to control your daemon with
|
12
|
+
|
13
|
+
config/
|
14
|
+
Environment configuration files
|
15
|
+
|
16
|
+
lib/
|
17
|
+
Place for your libraries
|
18
|
+
|
19
|
+
libexec/
|
20
|
+
<%= daemon_name %>.rb - Your daemon code
|
21
|
+
|
22
|
+
log/
|
23
|
+
Log files based on the environment name
|
24
|
+
|
25
|
+
spec/
|
26
|
+
rspec's home
|
27
|
+
|
28
|
+
tasks/
|
29
|
+
Place for rake tasks
|
30
|
+
|
31
|
+
vendor/
|
32
|
+
Place for unpacked gems and DaemonKit
|
33
|
+
|
34
|
+
tmp/
|
35
|
+
Scratch folder
|
36
|
+
|
37
|
+
|
38
|
+
Logging
|
39
|
+
=======
|
40
|
+
|
41
|
+
One of the biggest issues with writing daemons are gettign insight into what your
|
42
|
+
daemons are doing. Logging with DaemonKit is simplified as DaemonKit creates log
|
43
|
+
files per environment in log.
|
44
|
+
|
45
|
+
On all environments except production the log level is set to DEBUG, but you can
|
46
|
+
toggle the log level by sending the running daemon SIGUSR1 and SIGUSR2 signals.
|
47
|
+
SIGUSR1 will toggle between DEBUG and INFO levels, SIGUSR2 will blatantly set the
|
48
|
+
level to DEBUG.
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# Don't change this file!
|
2
|
+
# Configure your daemon in config/environment.rb
|
3
|
+
|
4
|
+
DAEMON_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?( DAEMON_ROOT )
|
5
|
+
|
6
|
+
module DaemonKit
|
7
|
+
class << self
|
8
|
+
def boot!
|
9
|
+
unless booted?
|
10
|
+
pick_boot.run
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def booted?
|
15
|
+
defined? DaemonKit::Initializer
|
16
|
+
end
|
17
|
+
|
18
|
+
def pick_boot
|
19
|
+
(vendor_kit? ? VendorBoot : GemBoot).new
|
20
|
+
end
|
21
|
+
|
22
|
+
def vendor_kit?
|
23
|
+
File.exists?( "#{DAEMON_ROOT}/vendor/daemon_kit" )
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Boot
|
28
|
+
def run
|
29
|
+
load_initializer
|
30
|
+
DaemonKit::Initializer.run
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class VendorBoot < Boot
|
35
|
+
def load_initializer
|
36
|
+
require "#{DAEMON_ROOT}/vendor/daemon_kit/lib/daemon_kit/initializer"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class GemBoot < Boot
|
41
|
+
def load_initializer
|
42
|
+
require 'rubygems'
|
43
|
+
gem 'daemon-kit'
|
44
|
+
require 'daemon_kit/initializer'
|
45
|
+
rescue Gem::LoadError => e
|
46
|
+
$stderr.puts %(Missing the daemon-kit gem. Please 'gem install daemon_kit')
|
47
|
+
exit 1
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
DaemonKit.boot!
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Be sure to restart your daemon when you modify this file
|
2
|
+
|
3
|
+
# Uncomment below to force your daemon into production mode
|
4
|
+
#ENV['DAEMON_ENV'] ||= 'production'
|
5
|
+
|
6
|
+
# Boot up
|
7
|
+
require File.join(File.dirname(__FILE__), 'boot')
|
8
|
+
|
9
|
+
DaemonKit::Initializer.run do |config|
|
10
|
+
|
11
|
+
# The name of the daemon as reported by process monitoring tools
|
12
|
+
config.daemon_name = '<%= daemon_name %>'
|
13
|
+
|
14
|
+
# Uncomment to allow multiple instances to run
|
15
|
+
# config.mulitple = true
|
16
|
+
|
17
|
+
# Force the daemon to be killed after X seconds from asking it to
|
18
|
+
# config.force_kill_wait = 30
|
19
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# You can place files in here to be loaded before the code is daemonized.
|
2
|
+
#
|
3
|
+
# DaemonKit looks for a file named '<config.daemon_name>.rb' and loads
|
4
|
+
# that file with as if inside a DaemonKit::Initializer block.
|
5
|
+
#
|
6
|
+
# These files are mostly useful for operations that should fail blatantly
|
7
|
+
# before daemonizing, like loading gems.
|
8
|
+
#
|
9
|
+
# Be careful not to open any form of IO in here and expecting it to be
|
10
|
+
# open inside the running daemon since all IO instances are closed when
|
11
|
+
# daemonizing (including STDIN, STDOUT & STDERR).
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Change this file to be a wrapper around your daemon code.
|
2
|
+
|
3
|
+
# Do your post daemonization configuration here
|
4
|
+
# At minimum you need just the first line (without the block), or a lot
|
5
|
+
# of strange things might start happening...
|
6
|
+
DaemonKit::Application.running! do |config|
|
7
|
+
# Trap signals with blocks or procs
|
8
|
+
# config.trap( 'INT' ) do
|
9
|
+
# # do something clever
|
10
|
+
# end
|
11
|
+
# config.trap( 'TERM', Proc.new { puts 'Going down' } )
|
12
|
+
end
|
13
|
+
|
14
|
+
# Sample loop to show process
|
15
|
+
loop do
|
16
|
+
DaemonKit.logger.info "I'm running"
|
17
|
+
sleep 60
|
18
|
+
end
|
data/bin/daemon_kit
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rubigen'
|
5
|
+
|
6
|
+
if %w(-v --version).include? ARGV.first
|
7
|
+
require 'daemon_kit'
|
8
|
+
puts "#{File.basename($0)} #{DaemonKit::VERSION}"
|
9
|
+
exit(0)
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'rubigen/scripts/generate'
|
13
|
+
RubiGen::Base.use_application_sources! :rubygems
|
14
|
+
RubiGen::Base.prepend_sources(*[
|
15
|
+
RubiGen::PathSource.new(:app, File.join(File.dirname(__FILE__), "..", "app_generators")),
|
16
|
+
RubiGen::PathSource.new(:app, File.join(File.dirname(__FILE__), "..", "daemon_generators")),
|
17
|
+
RubiGen::PathSource.new(:app, File.join(File.dirname(__FILE__), "..", "rubygems_generators"))
|
18
|
+
])
|
19
|
+
RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'daemon_kit')
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class JabberGenerator < RubiGen::Base
|
2
|
+
|
3
|
+
default_options :author => nil
|
4
|
+
|
5
|
+
attr_reader :name
|
6
|
+
|
7
|
+
def initialize(runtime_args, runtime_options = {})
|
8
|
+
super
|
9
|
+
usage if args.empty?
|
10
|
+
@name = args.shift
|
11
|
+
extract_options
|
12
|
+
end
|
13
|
+
|
14
|
+
def manifest
|
15
|
+
record do |m|
|
16
|
+
# Ensure appropriate folder(s) exists
|
17
|
+
m.directory ''
|
18
|
+
|
19
|
+
# Create stubs
|
20
|
+
# m.template "template.rb.erb", "some_file_after_erb.rb"
|
21
|
+
# m.template_copy_each ["template.rb", "template2.rb"]
|
22
|
+
# m.template_copy_each ["template.rb", "template2.rb"], "some/path"
|
23
|
+
# m.file "file", "some_file_copied"
|
24
|
+
# m.file_copy_each ["path/to/file", "path/to/file2"]
|
25
|
+
# m.file_copy_each ["path/to/file", "path/to/file2"], "some/path"
|
26
|
+
|
27
|
+
# Copy over our configs
|
28
|
+
m.directory 'config'
|
29
|
+
m.template 'config/jabber.yml', 'config/jabber.yml'
|
30
|
+
m.directory 'config/initializers'
|
31
|
+
m.template 'config/initializers/jabber.rb', "config/initializers/#{name}.rb"
|
32
|
+
|
33
|
+
# Copy over our daemon
|
34
|
+
m.directory 'libexec'
|
35
|
+
m.template 'libexec/daemon.rb', "libexec/#{name}.rb"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
def banner
|
41
|
+
<<-EOS
|
42
|
+
Creates a ...
|
43
|
+
|
44
|
+
USAGE: #{$0} #{spec.name} name
|
45
|
+
EOS
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_options!(opts)
|
49
|
+
# opts.separator ''
|
50
|
+
# opts.separator 'Options:'
|
51
|
+
# For each option below, place the default
|
52
|
+
# at the top of the file next to "default_options"
|
53
|
+
# opts.on("-a", "--author=\"Your Name\"", String,
|
54
|
+
# "Some comment about this option",
|
55
|
+
# "Default: none") { |o| options[:author] = o }
|
56
|
+
# opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
57
|
+
end
|
58
|
+
|
59
|
+
def extract_options
|
60
|
+
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
|
61
|
+
# Templates can access these value via the attr_reader-generated methods, but not the
|
62
|
+
# raw instance variable value.
|
63
|
+
# @author = options[:author]
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Jabber configuration file
|
2
|
+
|
3
|
+
# The configuration specifies the following keys:
|
4
|
+
# * jabber_id - Identidy (username) of the user
|
5
|
+
# * password - Password used to authenticate
|
6
|
+
# * resource - Multiple connections can be made with the same credentials and different resources
|
7
|
+
# * masters - Array of Jabber ID's whose messages will be processed
|
8
|
+
# * supporters - Additional 'buddies' to keep on roster, but messages won't be processed
|
9
|
+
|
10
|
+
defaults: &defaults
|
11
|
+
jabber_id: <%= name %>@gmail.com
|
12
|
+
password: secret
|
13
|
+
resource: daemon_kit
|
14
|
+
masters:
|
15
|
+
- you@gmail.com
|
16
|
+
supporters:
|
17
|
+
- someone@gmail.com
|
18
|
+
|
19
|
+
development:
|
20
|
+
<<: *defaults
|
21
|
+
|
22
|
+
test:
|
23
|
+
<<: *defaults
|
24
|
+
|
25
|
+
production:
|
26
|
+
<<: *defaults
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Generated jabber daemon
|
2
|
+
|
3
|
+
# Do your post daemonization configuration here
|
4
|
+
# At minimum you need just the first line (without the block), or a lot
|
5
|
+
# of strange things might start happening...
|
6
|
+
DaemonKit::Application.running! do |config|
|
7
|
+
# Trap signals with blocks or procs
|
8
|
+
# config.trap( 'INT' ) do
|
9
|
+
# # do something clever
|
10
|
+
# end
|
11
|
+
# config.trap( 'TERM', Proc.new { puts 'Going down' } )
|
12
|
+
end
|
13
|
+
|
14
|
+
# IMPORTANT CONFIGURATION NOTE
|
15
|
+
#
|
16
|
+
# Please review and update 'config/jabber.yml' accordingly or this
|
17
|
+
# daemon won't work as advertised.
|
18
|
+
|
19
|
+
# This block gets called every time a message has been received from a
|
20
|
+
# valid master.
|
21
|
+
DaemonKit::Jabber.received_messages do |message|
|
22
|
+
# Simple echo service
|
23
|
+
DaemonKit::Jabber.deliver( message.from, message.body )
|
24
|
+
end
|
25
|
+
|
26
|
+
# Run our Jabber bot
|
27
|
+
DaemonKit::Jabber.run
|