capistrano_misc_recipes 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  *.swp
19
+ *.swo
data/README.md CHANGED
@@ -109,9 +109,11 @@ end
109
109
 
110
110
  `passenger.start`, `passenger.stop` and `passenger.restart` tasks can be used.
111
111
 
112
- ### Generate sample nginx config for application
112
+ ### Generate sample configs for god and nginx
113
113
 
114
- Task `cap passenger:nginx_config` prints sample nginx config and saves it in file application tmp dir
114
+ Task `cap passenger:config:god` generates sample _god_ config and stores it in application tmp dir
115
+
116
+ Task `cap passenger:config:nginx` generates sample _nginx_ config and stores it in file application tmp dir
115
117
 
116
118
  ## Contributing
117
119
 
@@ -15,9 +15,9 @@ module Capistrano
15
15
  _cset :passenger_port, 3000
16
16
  _cset :passenger_use_socket, false
17
17
 
18
-
19
- desc '[internal] Start passenger'
20
- task :start, roles: :app do
18
+ # command to start passenger
19
+ def start_command
20
+ # TODO try_sudo
21
21
 
22
22
  command = []
23
23
  command << "cd #{current_path}"
@@ -37,62 +37,54 @@ module Capistrano
37
37
  command << "--pid-file #{passenger_pid_file}"
38
38
  command << "--environment #{rails_env}"
39
39
  command << "--daemonize"
40
- run command.join ' '
40
+ command.join ' '
41
+ end
41
42
 
43
+ def stop_command
44
+ # TODO try_sudo
45
+ "cd #{current_path} && #{bundlify 'passenger'} stop --pid-file #{passenger_pid_file} ; true"
46
+ end
47
+
48
+ def restart_command
49
+ "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
50
+ end
51
+
52
+ desc '[internal] Start passenger'
53
+ task :start, roles: :app do
54
+ run start_command
42
55
  end
43
56
 
44
57
  desc '[internal] Stop passenger'
45
58
  task :stop, roles: :app do
46
- run "cd #{current_path} && #{bundlify 'passenger'} stop --pid-file #{passenger_pid_file} ; true"
59
+ run stop_command
47
60
  end
48
61
 
49
62
  desc '[internal] Restart passenger'
50
63
  task :restart, roles: :app, except: { no_release: true } do
51
- run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
64
+ run restart_command
52
65
  end
53
66
 
54
- desc 'generates nginx virtual host template file'
55
- task :nginx_config do
56
-
57
- proxy_pass = if passenger_use_socket
58
- "http://unix:#{passenger_socket_file}"
59
- else
60
- "http://#{passenger_address}:#{passenger_port}"
61
- end
62
-
63
- conf_file = <<CONF
67
+ namespace :config do
64
68
 
65
- # nginx virtual host file for
66
- # application: #{application}
67
- #{exists?(:stages) ? "# stage: #{stage}\n" : nil}
68
- server {
69
- listen 80;
70
- server_name #{application}
71
- root #{File.join current_path, 'public'};
72
- client_max_body_size 15M;
69
+ {
70
+ god: { extension: 'god' },
71
+ nginx: { extension: nil}
72
+ }.each do |key, data|
73
73
 
74
- location / {
75
- try_files /system/maintence.html
76
- $uri $uri/index.html $uri.html
77
- @passenger;
78
- }
74
+ desc "generates nginx #{key} file"
75
+ task key do
76
+ template_dir = Pathname.new(File.dirname(__FILE__)).join 'templates'
77
+ app_name = [application, exists?(:stages) ? stage : nil].compact.join(?_)
78
+ file_name = [app_name, data[:extension]].compact.join ?.
79
+ conf_file = ERB.new(File.read(template_dir.join "#{key}.erb"), nil, '-').result binding
79
80
 
80
- location @passenger {
81
- proxy_set_header Host $host;
82
- proxy_set_header X-Forwarded-For $remote_addr;
81
+ puts conf_file
82
+ # save file in application tmp dir
83
+ put conf_file, File.join(current_path, 'tmp', file_name).to_s
84
+ end
83
85
 
84
- proxy_pass #{proxy_pass};
85
- }
86
-
87
- error_page 500 502 503 504 /500.html;
88
- error_page 404 403 /404.html;
89
- }
90
-
91
- CONF
86
+ end
92
87
 
93
- puts conf_file
94
- # save file in application tmp dir
95
- put conf_file, Pathname.new(current_path).join('tmp', [application, exists?(:stages) ? stage : nil].compact.join(?_)).to_s
96
88
  end
97
89
 
98
90
  end
@@ -0,0 +1,14 @@
1
+ God.watch do |w|
2
+ w.name = <%= app_name.inspect %>
3
+ w.start = <%= "su -l #{ user } -c '#{ start_command }'".inspect %>
4
+ w.stop = <%= "su -l #{ user } -c '#{ stop_command }'".inspect %>
5
+ w.pid_file = <%= passenger_pid_file.to_s.inspect %>
6
+
7
+ w.behavior(:clean_pid_file)
8
+ w.start_if do |start|
9
+ start.condition(:process_running) do |c|
10
+ c.interval = 10.minutes
11
+ c.running = false
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,32 @@
1
+ # nginx virtual host file for
2
+ # application: <%= application %>
3
+ <% if exists? :stages -%>
4
+ # stage: <%#= stage %>
5
+ <% end -%>
6
+ #
7
+
8
+ server {
9
+ listen 80;
10
+ server_name <%= app_name %>;
11
+ root <%= File.join current_path, 'public' %>;
12
+ client_max_body_size 15M;
13
+
14
+ location / {
15
+ try_files /system/maintence.html
16
+ $uri $uri/index.html $uri.html
17
+ @passenger;
18
+ }
19
+
20
+ location @passenger {
21
+ proxy_set_header Host $host;
22
+ proxy_set_header X-Forwarded-For $remote_addr;
23
+ <% if passenger_use_socket -%>
24
+ proxy_pass "http://unix:<%= passenger_socket_file %>";
25
+ <% else -%>
26
+ proxy_pass "http://<% passenger_address %>:<% passenger_port %>";
27
+ <% end -%>
28
+ }
29
+
30
+ error_page 500 502 503 504 /500.html;
31
+ error_page 404 403 /404.html;
32
+ }
@@ -1,3 +1,3 @@
1
1
  module CapistranoMiscRecipes
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano_misc_recipes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-27 00:00:00.000000000 Z
12
+ date: 2013-06-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
@@ -75,13 +75,14 @@ files:
75
75
  - Rakefile
76
76
  - capistrano_misc_recipes.gemspec
77
77
  - lib/capistrano_misc_recipes.rb
78
- - lib/capistrano_misc_recipes/.passenger.rb.swo
79
78
  - lib/capistrano_misc_recipes/bundler.rb
80
79
  - lib/capistrano_misc_recipes/console.rb
81
80
  - lib/capistrano_misc_recipes/db_dump.rb
82
81
  - lib/capistrano_misc_recipes/dbfetch.rb
83
82
  - lib/capistrano_misc_recipes/passenger.rb
84
83
  - lib/capistrano_misc_recipes/tasks.rb
84
+ - lib/capistrano_misc_recipes/templates/god.erb
85
+ - lib/capistrano_misc_recipes/templates/nginx.erb
85
86
  - lib/capistrano_misc_recipes/version.rb
86
87
  homepage: http://github.com/corlinus/capistrano_misc_recipes
87
88
  licenses:
@@ -98,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
99
  version: '0'
99
100
  segments:
100
101
  - 0
101
- hash: -4105244698074156849
102
+ hash: 1047313683594404599
102
103
  required_rubygems_version: !ruby/object:Gem::Requirement
103
104
  none: false
104
105
  requirements:
@@ -107,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
108
  version: '0'
108
109
  segments:
109
110
  - 0
110
- hash: -4105244698074156849
111
+ hash: 1047313683594404599
111
112
  requirements: []
112
113
  rubyforge_project:
113
114
  rubygems_version: 1.8.25