From 94ef58a55152084f18e993176e32ab34ab3424d3 Mon Sep 17 00:00:00 2001 From: craigp Date: Tue, 27 Jul 2010 17:19:01 +0200 Subject: [PATCH] fixed some config issues --- README.rdoc | 2 +- VERSION | 2 +- djinn.gemspec | 2 +- lib/djinn.rb | 1 + lib/djinn/base.rb | 10 +++++----- lib/djinn/logging.rb | 5 +++++ lib/djinn/rails.rb | 1 + 7 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.rdoc b/README.rdoc index bd1fe93..26434da 100644 --- a/README.rdoc +++ b/README.rdoc @@ -45,7 +45,7 @@ Assuming you didn't sleep there your script would end and the daemon would detach and run in the background until it dies or gets killed. You can wrap argument parsing around that if you want, or do it in any other way. By default the daemon will look for a config YAML file in same directory as you executed it -from, named the same as the Djinn class, so in this case _basic.yml_. It will by +from, named the same as the Djinn class, so in this case *basic.yml*. It will by default create the pid and log files in the same way. You can change this by putting it in the config file or supplying an options hash: diff --git a/VERSION b/VERSION index 5c4511c..7d6b3eb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.7 \ No newline at end of file +0.0.8 \ No newline at end of file diff --git a/djinn.gemspec b/djinn.gemspec index 29a1a3f..ca017f6 100644 --- a/djinn.gemspec +++ b/djinn.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |s| s.name = %q{djinn} - s.version = "0.0.7" + s.version = "0.0.8" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Craig Paterson"] diff --git a/lib/djinn.rb b/lib/djinn.rb index 437f1e5..47ad3a3 100644 --- a/lib/djinn.rb +++ b/lib/djinn.rb @@ -1,3 +1,4 @@ +require 'yaml' require 'djinn/base' # This is a base implementation which handles looking for config diff --git a/lib/djinn/base.rb b/lib/djinn/base.rb index ffafd9f..e68de8c 100644 --- a/lib/djinn/base.rb +++ b/lib/djinn/base.rb @@ -32,24 +32,24 @@ def handle_exit # Starts the Djinn in the background def start config={} - @config = (config.empty?) ? load_config : config.empty? + @config = (config.empty?) ? load_config : config log "Starting #{name} in the background.." logfile = get_logfile(config) daemonize(logfile, get_pidfile(config)) do trap('TERM') { handle_exit } trap('INT') { handle_exit } - perform(config) + perform(@config) end end # Starts the Djinn in the foreground, which is often useful for # testing or other noble pursuits def run config={} - @config = (config.empty?) ? load_config : config.empty? + @config = (config.empty?) ? load_config : config log "Starting #{name} in the foreground.." trap('TERM') { handle_exit } trap('INT') { handle_exit } - perform(config) + perform(@config) end # Convenience method, really just calls *stop* and then *start* for you :P @@ -61,7 +61,7 @@ def restart config={} # Stops the Djinn, unless you change the location of the pid file, in # which case its all about you and the *kill* command def stop config={} - @config = (config.empty?) ? load_config : config.empty? + @config = (config.empty?) ? load_config : config pidfile = get_pidfile(@config) log 'No such process' and exit unless pidfile.pid begin diff --git a/lib/djinn/logging.rb b/lib/djinn/logging.rb index c2e0fef..4fc2702 100644 --- a/lib/djinn/logging.rb +++ b/lib/djinn/logging.rb @@ -1,5 +1,10 @@ module Djinn module Logging + + def djinn_log msg + puts "#{Time.now.strftime("%m/%d/%Y %H:%M:%S")}: #{msg}" + STDOUT.flush + end def log msg puts "#{Time.now.strftime("%m/%d/%Y %H:%M:%S")}: #{msg}" diff --git a/lib/djinn/rails.rb b/lib/djinn/rails.rb index 880f76c..1073b27 100644 --- a/lib/djinn/rails.rb +++ b/lib/djinn/rails.rb @@ -1,5 +1,6 @@ $:.unshift(File.join(File.dirname(__FILE__))) +require 'yaml' require 'rails/handlers' module Djinn