Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Provides a daemon for running irc_machine (irc_machined) #4

Merged
merged 1 commit into from

2 participants

@ericanderson
  • Adds ./bin/irc_machined as a daemons wrapper script
  • Refactors some of ./bin/irc_machine into cli_shared
  • Refactors symbolization of keys into lib/monkey_patches
  • Adds a dependency on daemons to the gemspec
@ericanderson ericanderson Provides a daemon for running irc_machine (irc_machined)
* Adds ./bin/irc_machined as a daemons wrapper script
* Refactors some of ./bin/irc_machine into cli_shared
* Refactors symbolization of keys into lib/monkey_patches
* Adds a dependency on daemons to the gemspec
a0b39a0
@pda
Owner
pda commented

Excellent, thanks.

I'm not a huge fan of monkey patching #symbolize_keys into Hash, but I'm not that fussed about it.

Cheers!
Paul

@pda pda merged commit ac2cff2 into pda:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 4, 2012
  1. @ericanderson

    Provides a daemon for running irc_machine (irc_machined)

    ericanderson authored
    * Adds ./bin/irc_machined as a daemons wrapper script
    * Refactors some of ./bin/irc_machine into cli_shared
    * Refactors symbolization of keys into lib/monkey_patches
    * Adds a dependency on daemons to the gemspec
This page is out of date. Refresh to see the latest.
View
2  .gitignore
@@ -2,5 +2,5 @@
.bundle
Gemfile.lock
pkg/*
-
+/log/
/irc_machine.json
View
12 README.md
@@ -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
8 bin/irc_machine
@@ -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
26 bin/irc_machined
@@ -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
1  irc_machine.gemspec
@@ -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
2  lib/irc_machine.rb
@@ -1,5 +1,3 @@
-$LOAD_PATH << File.dirname(__FILE__)
-
%w{
ostruct
eventmachine
View
6 lib/irc_machine/cli_shared.rb
@@ -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
View
13 lib/irc_machine/monkey_patches.rb
@@ -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
Something went wrong with that request. Please try again.