Provides a daemon for running irc_machine (irc_machined) #4

Merged
merged 1 commit into from Apr 6, 2012
View
@@ -2,5 +2,5 @@
.bundle
Gemfile.lock
pkg/*
-
+/log/
/irc_machine.json
View
@@ -9,11 +9,19 @@ Design philosophy: simple to the point of under-engineered, make it work for the
git clone git://github.com/pda/irc_machine
cd irc_machine
cp example.json irc_machine.json
- ./bin/irc_machine
+
+ # run it
+ ./bin/irc_machined run
+ # ctrl+c
+
+ # daemonize it
+ ./bin/irc_machined start
+ # stop the daemon
+ ./bin/irc_machined stop
# or maybe even this (chances aren't good, though)
gem install irc_machine
- irc_machine
+ irc_machined run
HTTP interface
View
@@ -1,8 +1,6 @@
#!/usr/bin/env ruby
+$: << File.expand_path("../../lib", __FILE__)
-require "json"
-params = JSON.load(open("./irc_machine.json")).
- inject({}) { |h, (k,v)| h[k.to_sym] = v; h }
+require 'irc_machine/cli_shared'
-require File.join(File.dirname(__FILE__), "../lib/irc_machine")
-IrcMachine::Session.new(params).start
+IrcMachine::Session.new(IRC_MACHINE).start
View
@@ -0,0 +1,26 @@
+#!/usr/bin/env ruby
+$: << File.expand_path("../../lib", __FILE__)
+
+require 'rubygems'
+require 'daemons'
+
+require 'irc_machine/cli_shared'
+
+daemon_defaults = {
+ :app_name => 'irc_machine',
+ :dir_mode => :normal,
+ :dir => ".",
+ :multiple => false,
+ :backtrace => true,
+ :monitor => false,
+ :log_dir => File.expand_path("../../log", __FILE__),
+ :log_output => true
+}
+
+IRC_MACHINE[:daemon] ||= {}
+
+daemon_params = daemon_defaults.merge(IRC_MACHINE[:daemon])
+
+FileUtils.mkdir_p(daemon_params[:log_dir])
+
+Daemons.run(File.expand_path("../irc_machine", __FILE__), daemon_params)
View
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
s.add_dependency "eventmachine"
s.add_dependency "eventmachine_httpserver"
s.add_dependency "rack"
+ s.add_dependency "daemons"
s.add_development_dependency "bundler"
s.add_development_dependency "rake"
View
@@ -1,5 +1,3 @@
-$LOAD_PATH << File.dirname(__FILE__)
-
%w{
ostruct
eventmachine
@@ -0,0 +1,6 @@
+require "json"
+require 'irc_machine/monkey_patches'
+require 'irc_machine'
+
+ENV['IRC_MACHINE_CONF'] ||= File.expand_path("./irc_machine.json")
+IRC_MACHINE = JSON.load(open(ENV['IRC_MACHINE_CONF'])).symbolize_keys
@@ -0,0 +1,13 @@
+class Hash
+ def symbolize_keys
+ inject({}) do |h, (k,v)|
+ h[k.to_sym] = case v
+ when Hash
+ v.symbolize_keys
+ else
+ v
+ end
+ h
+ end
+ end
+end