ahn-rails 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +2 -0
- data/ahn-rails.gemspec +1 -0
- data/features/deployment_generator.feature +95 -0
- data/features/step_definitions/rails_setup_steps.rb +4 -0
- data/lib/ahn-rails/version.rb +1 -1
- data/lib/generators/ahn/app/app_generator.rb +7 -13
- data/lib/generators/ahn/deployment/USAGE +5 -0
- data/lib/generators/ahn/deployment/deployment_generator.rb +36 -0
- data/lib/generators/ahn/deployment/templates/adhearsion.god +60 -0
- data/lib/generators/ahn/deployment/templates/general.god +14 -0
- metadata +18 -1
data/README.md
CHANGED
@@ -5,6 +5,8 @@ AHNRails provides neat little generators for your Adhearsion + Rails mashups.
|
|
5
5
|
|
6
6
|
Simply include ahn-rails in your rails Gemfile and run `rails g ahn:app`.
|
7
7
|
|
8
|
+
If you wish to generate God config for adhearsion, simply run `rails g ahn:deployment`.
|
9
|
+
|
8
10
|
Note on Patches/Pull Requests
|
9
11
|
-----------------------------
|
10
12
|
|
data/ahn-rails.gemspec
CHANGED
@@ -0,0 +1,95 @@
|
|
1
|
+
Feature: Adhearsion Deployment Generator
|
2
|
+
In order to integrate Adhearsion and Rails
|
3
|
+
As a rails developer
|
4
|
+
I want to be able to deploy adhearsion as part of my rails app
|
5
|
+
|
6
|
+
Scenario: Generate rails integrated deployment config
|
7
|
+
Given a new Rails app
|
8
|
+
When I cd to "rails_app"
|
9
|
+
And I have capistrano setup
|
10
|
+
And I run `rails g ahn:deployment world_domination -f`
|
11
|
+
|
12
|
+
Then the file "config/all.god" should contain exactly:
|
13
|
+
"""
|
14
|
+
God::Contacts::Email.defaults do |d|
|
15
|
+
d.from_email = "status@mydomain.com"
|
16
|
+
d.from_name = "World Domination Status Monitor"
|
17
|
+
d.delivery_method = :sendmail
|
18
|
+
end
|
19
|
+
|
20
|
+
God.contact(:email) do |c|
|
21
|
+
c.name = "me"
|
22
|
+
c.to_email = "me@mydomain.com"
|
23
|
+
c.group = "support"
|
24
|
+
end
|
25
|
+
|
26
|
+
# load in all god configs
|
27
|
+
God.load File.join(File.dirname(__FILE__), 'god', '*.god')
|
28
|
+
|
29
|
+
"""
|
30
|
+
And the file "config/god/adhearsion.god" should contain exactly:
|
31
|
+
"""
|
32
|
+
@deploy_path = '/home/deploy/application'
|
33
|
+
@app_path = File.join @deploy_path, 'current', 'adhearsion'
|
34
|
+
@pid_file = File.join @deploy_path, 'shared', 'adhearsion', 'pids', 'adhearsion.pid'
|
35
|
+
|
36
|
+
def ahnctl_command(action = :start)
|
37
|
+
"cd #{@app_path} && bundle exec ahnctl #{action} #{@app_path} --pid-file=#{@pid_file}"
|
38
|
+
end
|
39
|
+
|
40
|
+
God.watch do |w|
|
41
|
+
w.name = "world_domination-adhearsion"
|
42
|
+
w.group = "world_domination"
|
43
|
+
|
44
|
+
w.interval = 30.seconds
|
45
|
+
w.start_grace = 20.seconds
|
46
|
+
w.restart_grace = 20.seconds
|
47
|
+
|
48
|
+
w.dir = @app_path
|
49
|
+
|
50
|
+
w.start = ahnctl_command :start
|
51
|
+
w.stop = ahnctl_command :stop
|
52
|
+
w.restart = ahnctl_command :restart
|
53
|
+
|
54
|
+
w.pid_file = @pid_file
|
55
|
+
w.behavior :clean_pid_file
|
56
|
+
|
57
|
+
w.uid = "deploy"
|
58
|
+
w.gid = "deploy"
|
59
|
+
|
60
|
+
w.start_if do |start|
|
61
|
+
start.condition(:process_running) do |c|
|
62
|
+
c.interval = 5.seconds
|
63
|
+
c.running = false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
w.restart_if do |restart|
|
68
|
+
restart.condition(:memory_usage) do |c|
|
69
|
+
c.above = 150.megabytes
|
70
|
+
c.times = [3, 5] # 3 out of 5 intervals
|
71
|
+
end
|
72
|
+
|
73
|
+
restart.condition(:cpu_usage) do |c|
|
74
|
+
c.above = 50.percent
|
75
|
+
c.times = 5
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
w.lifecycle do |on|
|
80
|
+
on.condition(:flapping) do |c|
|
81
|
+
c.to_state = [:start, :restart]
|
82
|
+
c.times = 5
|
83
|
+
c.within = 5.minute
|
84
|
+
c.transition = :unmonitored
|
85
|
+
c.retry_in = 10.minutes
|
86
|
+
c.retry_times = 5
|
87
|
+
c.retry_within = 2.hours
|
88
|
+
c.notify = {:contacts => ['support'], :priority => 1, :category => 'adhearsion'}
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
"""
|
94
|
+
And the file "config/deploy.rb" should contain "god load #{release_path}/config/all.god"
|
95
|
+
And the file "config/deploy.rb" should contain "god restart world_domination-adhearsion"
|
data/lib/ahn-rails/version.rb
CHANGED
@@ -3,19 +3,6 @@ require 'generators/ahn'
|
|
3
3
|
module Ahn
|
4
4
|
module Generators
|
5
5
|
class AppGenerator < Base
|
6
|
-
def generate_app
|
7
|
-
generate_ahn_app
|
8
|
-
place_files_for_rails
|
9
|
-
remove_ahn_tmp
|
10
|
-
place_custom_files
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def ahn_tmp_dir
|
16
|
-
'tmp/adhearsion'
|
17
|
-
end
|
18
|
-
|
19
6
|
def generate_ahn_app
|
20
7
|
run "ahn create #{ahn_tmp_dir}"
|
21
8
|
end
|
@@ -37,6 +24,13 @@ module Ahn
|
|
37
24
|
copy_file "adhearsion.yml", "config/adhearsion.example.yml"
|
38
25
|
copy_file "ahnrc", ".ahnrc"
|
39
26
|
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def ahn_tmp_dir
|
31
|
+
'tmp/adhearsion'
|
32
|
+
end
|
33
|
+
|
40
34
|
end
|
41
35
|
end
|
42
36
|
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
Description:
|
2
|
+
The ahn:deployment generator integrates adhearsion into your rails app's deployment setup. It creates God config files, and if you've setup Capistrano, it includes functionality there to restart adhearsion on deploy.
|
3
|
+
|
4
|
+
Examples:
|
5
|
+
rails generate ahn:deployment [org_name]
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'generators/ahn'
|
2
|
+
|
3
|
+
module Ahn
|
4
|
+
module Generators
|
5
|
+
class DeploymentGenerator < Base
|
6
|
+
argument :project_name, :type => :string, :default => 'my_company', :banner => 'project_name'
|
7
|
+
|
8
|
+
def create_god_config
|
9
|
+
template "general.god", "config/all.god"
|
10
|
+
template "adhearsion.god", "config/god/adhearsion.god"
|
11
|
+
end
|
12
|
+
|
13
|
+
def use_god_via_capistrano
|
14
|
+
return unless got_capistrano?
|
15
|
+
|
16
|
+
append_file "config/deploy.rb", <<-STRING
|
17
|
+
after 'deploy:restart', 'deploy:restart_adhearsion'
|
18
|
+
role :adhearsion, "adhearsion.domain.com"
|
19
|
+
namespace :deploy do
|
20
|
+
task :restart_adhearsion, :roles => :adhearsion do
|
21
|
+
sudo "god load \#{release_path}/config/all.god"
|
22
|
+
sudo "god restart #{project_name}-adhearsion"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
STRING
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def got_capistrano?
|
31
|
+
File.exists? File.join(destination_root, "config/deploy.rb")
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
@deploy_path = '/home/deploy/application'
|
2
|
+
@app_path = File.join @deploy_path, 'current', 'adhearsion'
|
3
|
+
@pid_file = File.join @deploy_path, 'shared', 'adhearsion', 'pids', 'adhearsion.pid'
|
4
|
+
|
5
|
+
def ahnctl_command(action = :start)
|
6
|
+
"cd #{@app_path} && bundle exec ahnctl #{action} #{@app_path} --pid-file=#{@pid_file}"
|
7
|
+
end
|
8
|
+
|
9
|
+
God.watch do |w|
|
10
|
+
w.name = "<%= project_name %>-adhearsion"
|
11
|
+
w.group = "<%= project_name %>"
|
12
|
+
|
13
|
+
w.interval = 30.seconds
|
14
|
+
w.start_grace = 20.seconds
|
15
|
+
w.restart_grace = 20.seconds
|
16
|
+
|
17
|
+
w.dir = @app_path
|
18
|
+
|
19
|
+
w.start = ahnctl_command :start
|
20
|
+
w.stop = ahnctl_command :stop
|
21
|
+
w.restart = ahnctl_command :restart
|
22
|
+
|
23
|
+
w.pid_file = @pid_file
|
24
|
+
w.behavior :clean_pid_file
|
25
|
+
|
26
|
+
w.uid = "deploy"
|
27
|
+
w.gid = "deploy"
|
28
|
+
|
29
|
+
w.start_if do |start|
|
30
|
+
start.condition(:process_running) do |c|
|
31
|
+
c.interval = 5.seconds
|
32
|
+
c.running = false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
w.restart_if do |restart|
|
37
|
+
restart.condition(:memory_usage) do |c|
|
38
|
+
c.above = 150.megabytes
|
39
|
+
c.times = [3, 5] # 3 out of 5 intervals
|
40
|
+
end
|
41
|
+
|
42
|
+
restart.condition(:cpu_usage) do |c|
|
43
|
+
c.above = 50.percent
|
44
|
+
c.times = 5
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
w.lifecycle do |on|
|
49
|
+
on.condition(:flapping) do |c|
|
50
|
+
c.to_state = [:start, :restart]
|
51
|
+
c.times = 5
|
52
|
+
c.within = 5.minute
|
53
|
+
c.transition = :unmonitored
|
54
|
+
c.retry_in = 10.minutes
|
55
|
+
c.retry_times = 5
|
56
|
+
c.retry_within = 2.hours
|
57
|
+
c.notify = {:contacts => ['support'], :priority => 1, :category => 'adhearsion'}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
God::Contacts::Email.defaults do |d|
|
2
|
+
d.from_email = "status@mydomain.com"
|
3
|
+
d.from_name = "<%= project_name.titleize %> Status Monitor"
|
4
|
+
d.delivery_method = :sendmail
|
5
|
+
end
|
6
|
+
|
7
|
+
God.contact(:email) do |c|
|
8
|
+
c.name = "me"
|
9
|
+
c.to_email = "me@mydomain.com"
|
10
|
+
c.group = "support"
|
11
|
+
end
|
12
|
+
|
13
|
+
# load in all god configs
|
14
|
+
God.load File.join(File.dirname(__FILE__), 'god', '*.god')
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: ahn-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ben Langfeld
|
@@ -101,6 +101,17 @@ dependencies:
|
|
101
101
|
version: 1.3.1
|
102
102
|
type: :development
|
103
103
|
version_requirements: *id008
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
name: capistrano
|
106
|
+
prerelease: false
|
107
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: "0"
|
113
|
+
type: :development
|
114
|
+
version_requirements: *id009
|
104
115
|
description: Stretch rails beyond the browser, easily
|
105
116
|
email:
|
106
117
|
- ben@langfeld.me
|
@@ -118,6 +129,7 @@ files:
|
|
118
129
|
- Rakefile
|
119
130
|
- ahn-rails.gemspec
|
120
131
|
- features/app_generator.feature
|
132
|
+
- features/deployment_generator.feature
|
121
133
|
- features/step_definitions/rails_setup_steps.rb
|
122
134
|
- features/support/env.rb
|
123
135
|
- lib/ahn-rails.rb
|
@@ -129,6 +141,10 @@ files:
|
|
129
141
|
- lib/generators/ahn/app/templates/adhearsion.rb
|
130
142
|
- lib/generators/ahn/app/templates/adhearsion.yml
|
131
143
|
- lib/generators/ahn/app/templates/ahnrc
|
144
|
+
- lib/generators/ahn/deployment/USAGE
|
145
|
+
- lib/generators/ahn/deployment/deployment_generator.rb
|
146
|
+
- lib/generators/ahn/deployment/templates/adhearsion.god
|
147
|
+
- lib/generators/ahn/deployment/templates/general.god
|
132
148
|
has_rdoc: true
|
133
149
|
homepage: http://benlangfeld.github.com/ahn-rails
|
134
150
|
licenses: []
|
@@ -159,5 +175,6 @@ specification_version: 3
|
|
159
175
|
summary: Adhearsion helpers for Ruby on Rails
|
160
176
|
test_files:
|
161
177
|
- features/app_generator.feature
|
178
|
+
- features/deployment_generator.feature
|
162
179
|
- features/step_definitions/rails_setup_steps.rb
|
163
180
|
- features/support/env.rb
|