Skip to content

Commit

Permalink
Demonize and add capistrano support.
Browse files Browse the repository at this point in the history
  • Loading branch information
CoralineAda committed Nov 28, 2014
1 parent 0b878f9 commit e57f9bf
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 6 deletions.
27 changes: 27 additions & 0 deletions Capfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Load DSL and set up stages
require 'capistrano/setup'

# Include default deployment tasks
require 'capistrano/deploy'

# Include tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
# https://github.com/capistrano/rvm
# https://github.com/capistrano/rbenv
# https://github.com/capistrano/chruby
# https://github.com/capistrano/bundler
# https://github.com/capistrano/rails
# https://github.com/capistrano/passenger
#
# require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
# require 'capistrano/bundler'
# require 'capistrano/rails/assets'
# require 'capistrano/rails/migrations'
# require 'capistrano/passenger'

# Load custom tasks from `lib/capistrano/tasks' if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ source 'https://rubygems.org'

gem "aasm"
gem "brewery_db"
gem "capistrano", '~> 3.3.0'
gem "cinch"
gem "dotenv"
gem "google-search", "~> 1.0"
Expand All @@ -11,6 +12,7 @@ gem 'database_cleaner', :github => 'bmabey/database_cleaner', group: :test
gem 'marky_markov'
gem 'poro_plus'
gem 'pry'
gem 'raad'
gem 'rake'
gem 'require_all'
gem 'rspec', :group => :test
Expand Down
19 changes: 19 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ GEM
faraday_middleware (~> 0.8)
hashie (>= 1.1, < 3)
builder (3.0.4)
capistrano (3.3.3)
capistrano-stats (~> 1.0.3)
i18n
rake (>= 10.0.0)
sshkit (~> 1.3)
capistrano-stats (1.0.3)
cinch (2.1.0)
coderay (1.1.0)
colorize (0.7.3)
crass (0.2.1)
diff-lcs (1.2.5)
dotenv (0.11.1)
Expand All @@ -35,6 +42,7 @@ GEM
hashie (2.1.2)
i18n (0.6.9)
json (1.8.1)
log4r (1.1.10)
marky_markov (0.3.5)
msgpack
method_source (0.8.2)
Expand All @@ -48,6 +56,9 @@ GEM
msgpack (0.5.8)
multi_json (1.10.0)
multipart-post (1.2.0)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (2.9.1)
nokogiri (1.6.3.1)
mini_portile (= 0.6.0)
nokogumbo (1.1.12)
Expand All @@ -58,6 +69,8 @@ GEM
coderay (~> 1.0)
method_source (~> 0.8)
slop (~> 3.4)
raad (0.5.0)
log4r (~> 1.1.9)
rack (1.5.2)
rake (10.3.2)
require_all (1.3.2)
Expand All @@ -76,6 +89,10 @@ GEM
nokogiri (>= 1.4.4)
nokogumbo (= 1.1.12)
slop (3.5.0)
sshkit (1.5.1)
colorize
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
tzinfo (0.3.39)
wikipedia-client (1.3.3)
yummly (0.0.13)
Expand All @@ -89,6 +106,7 @@ PLATFORMS
DEPENDENCIES
aasm
brewery_db
capistrano (~> 3.3.0)
cinch
database_cleaner!
dotenv
Expand All @@ -97,6 +115,7 @@ DEPENDENCIES
mongoid (~> 3.1.6)
poro_plus
pry
raad
rake
require_all
rspec
Expand Down
25 changes: 21 additions & 4 deletions alice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,41 @@
require 'cinch'
require 'dotenv'
require 'require_all'
require 'raad'

Dotenv.load
Bundler.require
Mongoid.load!("config/mongoid.yml")

require_all 'alice'

module Alice

def self.start
bot.start
def self.new
Daemon.new(bot)
end

def self.bot
@@bot ||= Alice::Bot.new
# @@bot.bot.loggers = nil
@@bot
end

class Daemon

attr_reader :bot

def initialize(bot)
@bot = bot
end

def start
Raad::Logger.info("Daemon started. I LIVE!")
self.bot.start
end

def stop
Raad::Logger.info("Daemon stopped.")
end
end
end

Yummly.configure do |config|
Expand Down
3 changes: 2 additions & 1 deletion alice/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def initialize
config.channels = [ENV['PRIMARY_CHANNEL'], ENV['DEBUG_CHANNEL']]
config.nick = ENV['IRC_NICK']
config.user = ENV['IRC_USER']
config.logger = Raad::Logger
config.plugins.plugins = [
Listener
]
Expand All @@ -29,7 +30,7 @@ def leave(channel_name)
end

def log(message)
bot.loggers.warn "#{Time.now} - #{message}"
Raad::Logger.info "#{Time.now} - #{message}"
end

def start
Expand Down
3 changes: 2 additions & 1 deletion alice/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ def self.from(message)
match ||= find_verb(trigger)
if match
match.message = message
p "*** Executing #{match.name} with #{trigger} ***"
Raad::Logger.info "*** Executing #{match.name} with \"#{trigger}\" ***"
else
Raad::Logger.info "*** Received unhandled trigger \"#{trigger}\" ***"
match = default
end
match
Expand Down
49 changes: 49 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# config valid only for current version of Capistrano
lock '3.3.3'

set :application, 'alice'
set :repo_url, '[email protected]:CoralineAda/alice.git'

# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call

# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, '/home/coraline/alice'

# Default value for :scm is :git
# set :scm, :git

# Default value for :format is :pretty
# set :format, :pretty

# Default value for :log_level is :debug
# set :log_level, :debug

# Default value for :pty is false
# set :pty, true

# Default value for :linked_files is []
# set :linked_files, fetch(:linked_files, []).push('config/database.yml')

# Default value for linked_dirs is []
# set :linked_dirs, fetch(:linked_dirs, []).push('bin', 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')

# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }

# Default value for keep_releases is 5
# set :keep_releases, 5

namespace :deploy do

after :restart, :clear_cache do
on roles(:app), in: :groups, limit: 3, wait: 10 do
within release_path do
execute :ruby, 'alice.rb stop'
execute :git, "pull origin master"
execute :ruby, 'alice.rb -dvs --log log/alice.log --timeout 1 start'
end
end
end

end
42 changes: 42 additions & 0 deletions config/deploy/production.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Simple Role Syntax
# ==================
# Supports bulk-adding hosts to roles, the primary server in each group
# is considered to be the first unless any hosts have the primary
# property set. Don't declare `role :all`, it's a meta role.

role :app, %w{[email protected]}

# Extended Server Syntax
# ======================
# This can be used to drop a more detailed server definition into the
# server list. The second argument is a, or duck-types, Hash and is
# used to set extended properties on the server.

server 'irc.lonelyhackersclub.com', user: 'coraline', roles: %w{app}


# Custom SSH Options
# ==================
# You may pass any option but keep in mind that net/ssh understands a
# limited set of options, consult[net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start).
#
# Global options
# --------------
# set :ssh_options, {
# keys: %w(/home/rlisowski/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(password)
# }
#
# And/or per server (overrides global)
# ------------------------------------
# server 'example.com',
# user: 'user_name',
# roles: %w{web app},
# ssh_options: {
# user: 'user_name', # overrides user setting above
# keys: %w(/home/user_name/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(publickey password)
# # password: 'please use keys'
# }
45 changes: 45 additions & 0 deletions config/deploy/staging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Simple Role Syntax
# ==================
# Supports bulk-adding hosts to roles, the primary server in each group
# is considered to be the first unless any hosts have the primary
# property set. Don't declare `role :all`, it's a meta role.

role :app, %w{[email protected]}
role :web, %w{[email protected]}
role :db, %w{[email protected]}


# Extended Server Syntax
# ======================
# This can be used to drop a more detailed server definition into the
# server list. The second argument is a, or duck-types, Hash and is
# used to set extended properties on the server.

server 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value


# Custom SSH Options
# ==================
# You may pass any option but keep in mind that net/ssh understands a
# limited set of options, consult[net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start).
#
# Global options
# --------------
# set :ssh_options, {
# keys: %w(/home/rlisowski/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(password)
# }
#
# And/or per server (overrides global)
# ------------------------------------
# server 'example.com',
# user: 'user_name',
# roles: %w{web app},
# ssh_options: {
# user: 'user_name', # overrides user setting above
# keys: %w(/home/user_name/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(publickey password)
# # password: 'please use keys'
# }

0 comments on commit e57f9bf

Please sign in to comment.