-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Blank 0.2.3 app to be used as a fixture
- Loading branch information
1 parent
8ec558e
commit 286a8e5
Showing
20 changed files
with
309 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# If you need to 'vendor your gems' for deploying your daemons, bundler is a | ||
# great option. Update this Gemfile with any additional dependencies and run | ||
# 'bundle install' to get them all installed. Daemon-kit's capistrano | ||
# deployment will ensure that the bundle required by your daemon is properly | ||
# installed. | ||
# | ||
# For more information on bundler, please visit http://gembundler.com | ||
|
||
source 'https://rubygems.org' | ||
|
||
# daemon-kit | ||
gem 'daemon-kit' | ||
|
||
# safely (http://github.com/kennethkalmer/safely) | ||
gem 'safely' | ||
# gem 'toadhopper' # For reporting exceptions to hoptoad | ||
# gem 'mail' # For reporting exceptions via mail | ||
group :development, :test do | ||
gem 'rake' | ||
gem 'rspec' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
daemon-kit README | ||
================ | ||
|
||
daemon-kit has generated a skeleton Ruby daemon for you to build on. Please read | ||
through this file to ensure you get going quickly. | ||
|
||
Directories | ||
=========== | ||
|
||
bin/ | ||
zero_two_three - Stub executable to control your daemon with | ||
|
||
config/ | ||
Environment configuration files | ||
|
||
lib/ | ||
Place for your libraries | ||
|
||
libexec/ | ||
zero_two_three.rb - Your daemon code | ||
|
||
log/ | ||
Log files based on the environment name | ||
|
||
spec/ | ||
rspec's home | ||
|
||
tasks/ | ||
Place for rake tasks | ||
|
||
vendor/ | ||
Place for unpacked gems and DaemonKit | ||
|
||
tmp/ | ||
Scratch folder | ||
|
||
Rake Tasks | ||
========== | ||
|
||
Note that the Rakefile does not load the `config/environments.rb` file, so if you have | ||
environment-specific tasks (such as tests), you will need to call rake with the environment: | ||
|
||
DAEMON_ENV=staging bundle exec rake -T | ||
|
||
Logging | ||
======= | ||
|
||
One of the biggest issues with writing daemons are getting insight into what your | ||
daemons are doing. Logging with daemon-kit is simplified as DaemonKit creates log | ||
files per environment in log. | ||
|
||
On all environments except production the log level is set to DEBUG, but you can | ||
toggle the log level by sending the running daemon SIGUSR1 and SIGUSR2 signals. | ||
SIGUSR1 will toggle between DEBUG and INFO levels, SIGUSR2 will blatantly set the | ||
level to DEBUG. | ||
|
||
Bundler | ||
======= | ||
|
||
daemon-kit uses bundler to ease the nightmare of dependency loading in Ruby | ||
projects. daemon-kit and its generators all create/update the Gemfile in the | ||
root of the daemon. You can satisfy the project's dependencies by running | ||
`bundle install` from within the project root. | ||
|
||
For more information on bundler, please see http://github.com/carlhuda/bundler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require File.expand_path('../config/boot', __FILE__) | ||
|
||
require 'rake' | ||
require 'daemon_kit/tasks' | ||
|
||
Dir[File.join(File.dirname(__FILE__), 'tasks/*.rake')].each { |rake| load rake } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env ruby | ||
# | ||
# Stub executable for zero_two_three | ||
# | ||
|
||
require File.expand_path('../../config/environment', __FILE__) | ||
|
||
DaemonKit::Application.exec( DAEMON_ROOT + '/libexec/zero_two_three-daemon.rb' ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Argument handling for your daemon is configured here. | ||
# | ||
# You have access to two variables when this file is | ||
# parsed. The first is +opts+, which is the object yielded from | ||
# +OptionParser.new+, the second is +@options+ which is a standard | ||
# Ruby hash that is later accessible through | ||
# DaemonKit.arguments.options and can be used in your daemon process. | ||
|
||
# Here is an example: | ||
# opts.on('-f', '--foo FOO', 'Set foo') do |foo| | ||
# @options[:foo] = foo | ||
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Don't change this file! | ||
# Configure your daemon in config/environment.rb | ||
|
||
DAEMON_ROOT = "#{File.expand_path(File.dirname(__FILE__))}/.." unless defined?( DAEMON_ROOT ) | ||
|
||
require "rubygems" | ||
require "bundler/setup" | ||
|
||
module DaemonKit | ||
class << self | ||
def boot! | ||
unless booted? | ||
pick_boot.run | ||
end | ||
end | ||
|
||
def booted? | ||
defined? DaemonKit::Initializer | ||
end | ||
|
||
def pick_boot | ||
(vendor_kit? ? VendorBoot : GemBoot).new | ||
end | ||
|
||
def vendor_kit? | ||
File.exists?( "#{DAEMON_ROOT}/vendor/daemon-kit" ) | ||
end | ||
end | ||
|
||
class Boot | ||
def run | ||
load_initializer | ||
DaemonKit::Initializer.run | ||
end | ||
end | ||
|
||
class VendorBoot < Boot | ||
def load_initializer | ||
require "#{DAEMON_ROOT}/vendor/daemon-kit/lib/daemon_kit/initializer" | ||
end | ||
end | ||
|
||
class GemBoot < Boot | ||
def load_initializer | ||
begin | ||
require 'rubygems' unless defined?( ::Gem ) | ||
gem 'daemon-kit' | ||
require 'daemon_kit/initializer' | ||
rescue ::Gem::LoadError => e | ||
msg = <<EOF | ||
You are missing the daemon-kit gem. Please install the following gem: | ||
sudo gem install daemon-kit | ||
EOF | ||
$stderr.puts msg | ||
exit 1 | ||
end | ||
end | ||
end | ||
end | ||
|
||
DaemonKit.boot! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Be sure to restart your daemon when you modify this file | ||
|
||
# Uncomment below to force your daemon into production mode | ||
#ENV['DAEMON_ENV'] ||= 'production' | ||
|
||
# Boot up | ||
require File.join(File.dirname(__FILE__), 'boot') | ||
|
||
# Auto-require default libraries and those for the current ruby environment. | ||
Bundler.require :default, DaemonKit.env | ||
|
||
DaemonKit::Initializer.run do |config| | ||
|
||
# The name of the daemon as reported by process monitoring tools | ||
config.daemon_name = 'zero_two_three' | ||
|
||
# Force the daemon to be killed after X seconds from asking it to | ||
# config.force_kill_wait = 30 | ||
|
||
# Log backraces when a thread/daemon dies (Recommended) | ||
# config.backtraces = true | ||
end |
2 changes: 2 additions & 0 deletions
2
spec/fixtures/zero_two_three/config/environments/development.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# This is the same context as the environment.rb file, it is only | ||
# loaded afterwards and only in the development environment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# You can place files in here to be loaded after the code is daemonized. | ||
# | ||
# All the files placed here will just be required into the running | ||
# process. This is the correct place to open any IO objects, establish | ||
# database connections, etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# You can place files in here to be loaded before the code is daemonized. | ||
# | ||
# DaemonKit looks for a file named '<config.daemon_name>.rb' and loads | ||
# that file first, and inside a DaemonKit::Initializer block. The | ||
# remaning files then simply required into the running process. | ||
# | ||
# These files are mostly useful for operations that should fail blatantly | ||
# before daemonizing, like loading gems. | ||
# | ||
# Be careful not to open any form of IO in here and expecting it to be | ||
# open inside the running daemon since all IO instances are closed when | ||
# daemonizing (including STDIN, STDOUT & STDERR). |
13 changes: 13 additions & 0 deletions
13
spec/fixtures/zero_two_three/config/pre-daemonize/safely.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Safely is responsible for providing exception reporting and the | ||
# logging of backtraces when your daemon dies unexpectedly. The full | ||
# documentation for safely can be found at | ||
# http://github.com/kennethkalmer/safely/wiki | ||
|
||
# By default Safely will use the daemon-kit's logger to log exceptions, | ||
# and will store backtraces in the "log" directory. | ||
|
||
# Comment out to enable Hoptoad support | ||
# Safely::Strategy::Hoptoad.hoptoad_key = "" | ||
|
||
# Comment out to use email exceptions | ||
# Safely::Strategy::Mail.recipient = "your.name@gmail.com" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Your starting point for daemon specific classes. This directory is | ||
# already included in your load path, so no need to specify it. |
18 changes: 18 additions & 0 deletions
18
spec/fixtures/zero_two_three/libexec/zero_two_three-daemon.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Change this file to be a wrapper around your daemon code. | ||
|
||
# Do your post daemonization configuration here | ||
# At minimum you need just the first line (without the block), or a lot | ||
# of strange things might start happening... | ||
DaemonKit::Application.running! do |config| | ||
# Trap signals with blocks or procs | ||
# config.trap( 'INT' ) do | ||
# # do something clever | ||
# end | ||
# config.trap( 'TERM', Proc.new { puts 'Going down' } ) | ||
end | ||
|
||
# Sample loop to show process | ||
loop do | ||
DaemonKit.logger.info "I'm running" | ||
sleep 60 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env ruby | ||
#!/usr/bin/env ruby | ||
require File.expand_path('../../config/boot', __FILE__) | ||
require 'daemon_kit/commands/console' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env ruby | ||
#!/usr/bin/env ruby | ||
require File.expand_path( '../../config/environment', __FILE__ ) | ||
require 'daemon_kit/commands/generate' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env ruby | ||
#!/usr/bin/env ruby | ||
require File.expand_path( '../../config/environment', __FILE__ ) | ||
require 'daemon_kit/commands/generate' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--colour |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
DAEMON_ENV = 'test' unless defined?( DAEMON_ENV ) | ||
|
||
begin | ||
require 'rspec' | ||
rescue LoadError | ||
require 'rubygems' | ||
require 'rspec' | ||
end | ||
|
||
require File.dirname(__FILE__) + '/../config/environment' | ||
DaemonKit::Application.running! | ||
|
||
RSpec.configure do |config| | ||
# == Mock Framework | ||
# | ||
# RSpec uses it's own mocking framework by default. If you prefer to | ||
# use mocha, flexmock or RR, uncomment the appropriate line: | ||
# | ||
# config.mock_with :mocha | ||
# config.mock_with :flexmock | ||
# config.mock_with :rr | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require File.dirname(__FILE__) + '/spec_helper.rb' | ||
|
||
# Time to add your specs! | ||
# http://rspec.info/ | ||
describe "Place your specs here" do | ||
|
||
it "find this spec in spec directory" do | ||
violated "Be sure to write your specs" | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
if ['test', 'development'].include?(DAEMON_ENV) | ||
require 'rspec' | ||
require 'rspec/core/rake_task' | ||
|
||
desc "Run the specs under spec/" | ||
RSpec::Core::RakeTask.new do |t| | ||
t.rspec_opts = ['--options', "spec/spec.opts"] | ||
end | ||
|
||
# Want other tests/tasks run by default? | ||
# Add them to the list | ||
task :default => [:spec] #, :features] | ||
end |