Skip to content

Commit

Permalink
Blank 0.2.3 app to be used as a fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethkalmer committed Sep 16, 2013
1 parent 8ec558e commit 286a8e5
Show file tree
Hide file tree
Showing 20 changed files with 309 additions and 0 deletions.
21 changes: 21 additions & 0 deletions spec/fixtures/zero_two_three/Gemfile
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
65 changes: 65 additions & 0 deletions spec/fixtures/zero_two_three/README
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
6 changes: 6 additions & 0 deletions spec/fixtures/zero_two_three/Rakefile
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 }
8 changes: 8 additions & 0 deletions spec/fixtures/zero_two_three/bin/zero_two_three
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' )
12 changes: 12 additions & 0 deletions spec/fixtures/zero_two_three/config/arguments.rb
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
64 changes: 64 additions & 0 deletions spec/fixtures/zero_two_three/config/boot.rb
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!
22 changes: 22 additions & 0 deletions spec/fixtures/zero_two_three/config/environment.rb
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
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
5 changes: 5 additions & 0 deletions spec/fixtures/zero_two_three/config/post-daemonize/readme
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.
12 changes: 12 additions & 0 deletions spec/fixtures/zero_two_three/config/pre-daemonize/readme
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 spec/fixtures/zero_two_three/config/pre-daemonize/safely.rb
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"
2 changes: 2 additions & 0 deletions spec/fixtures/zero_two_three/lib/zero_two_three.rb
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 spec/fixtures/zero_two_three/libexec/zero_two_three-daemon.rb
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
4 changes: 4 additions & 0 deletions spec/fixtures/zero_two_three/script/console
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'
4 changes: 4 additions & 0 deletions spec/fixtures/zero_two_three/script/destroy
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'
4 changes: 4 additions & 0 deletions spec/fixtures/zero_two_three/script/generate
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'
1 change: 1 addition & 0 deletions spec/fixtures/zero_two_three/spec/spec.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--colour
22 changes: 22 additions & 0 deletions spec/fixtures/zero_two_three/spec/spec_helper.rb
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
11 changes: 11 additions & 0 deletions spec/fixtures/zero_two_three/spec/zero_two_three_spec.rb
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
13 changes: 13 additions & 0 deletions spec/fixtures/zero_two_three/tasks/rspec.rake
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

0 comments on commit 286a8e5

Please sign in to comment.