Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provides a daemon for running irc_machine (irc_machined) #4

Merged
merged 1 commit into from Apr 6, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -2,5 +2,5 @@
.bundle .bundle
Gemfile.lock Gemfile.lock
pkg/* pkg/*

/log/
/irc_machine.json /irc_machine.json
12 changes: 10 additions & 2 deletions README.md
Expand Up @@ -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 git clone git://github.com/pda/irc_machine
cd irc_machine cd irc_machine
cp example.json irc_machine.json 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) # or maybe even this (chances aren't good, though)
gem install irc_machine gem install irc_machine
irc_machine irc_machined run




HTTP interface HTTP interface
Expand Down
8 changes: 3 additions & 5 deletions bin/irc_machine
@@ -1,8 +1,6 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
$: << File.expand_path("../../lib", __FILE__)


require "json" require 'irc_machine/cli_shared'
params = JSON.load(open("./irc_machine.json")).
inject({}) { |h, (k,v)| h[k.to_sym] = v; h }


require File.join(File.dirname(__FILE__), "../lib/irc_machine") IrcMachine::Session.new(IRC_MACHINE).start
IrcMachine::Session.new(params).start
26 changes: 26 additions & 0 deletions 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)
1 change: 1 addition & 0 deletions irc_machine.gemspec
Expand Up @@ -19,6 +19,7 @@ Gem::Specification.new do |s|
s.add_dependency "eventmachine" s.add_dependency "eventmachine"
s.add_dependency "eventmachine_httpserver" s.add_dependency "eventmachine_httpserver"
s.add_dependency "rack" s.add_dependency "rack"
s.add_dependency "daemons"


s.add_development_dependency "bundler" s.add_development_dependency "bundler"
s.add_development_dependency "rake" s.add_development_dependency "rake"
Expand Down
2 changes: 0 additions & 2 deletions lib/irc_machine.rb
@@ -1,5 +1,3 @@
$LOAD_PATH << File.dirname(__FILE__)

%w{ %w{
ostruct ostruct
eventmachine eventmachine
Expand Down
6 changes: 6 additions & 0 deletions 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
13 changes: 13 additions & 0 deletions 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