capistrano_misc_recipes 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Capistrano Misc Recipes
2
2
 
3
- This gem provides several capistrano tasks to help to access rails application environment and log files.
3
+ This gem provides several capistrano tasks to help to access rails application environment and log files, fetch db dump from server and manage passenger process.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'capistrano_misc_recipies'
9
+ gem 'capistrano_misc_recipies', group: :development
10
10
 
11
11
  And then execute:
12
12
 
@@ -18,9 +18,13 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
+ ### Console commands
22
+
21
23
  Add to your Capfile:
22
24
 
23
- require 'capistrano_misc_recipies/console'
25
+ ```ruby
26
+ require 'capistrano_misc_recipies/console'
27
+ ```
24
28
 
25
29
  To open rails db console on first application server:
26
30
 
@@ -42,6 +46,73 @@ To get 1000 string from application log file from server:
42
46
 
43
47
  $ cap console:tail_log1000
44
48
 
49
+ ### Fetch database dump from server
50
+
51
+ Add to your Capfile:
52
+
53
+ ```ruby
54
+ require 'capistrano_misc_recipies/dbfetch'
55
+ ```
56
+
57
+ To fetch db dump from server run:
58
+
59
+ $ cap dbfetch
60
+
61
+ Gem also includes rake task to make dump of local database:
62
+
63
+ $ rake db:sqldump
64
+
65
+ ### Passenger standalone manage tasks
66
+
67
+ Add to your Capfile:
68
+
69
+ ```ruby
70
+ require 'capistrano_misc_recipies/passenger'
71
+ ```
72
+
73
+ Now you have `deploy:start`, `deploy:stop` and `deploy:restart` tasks which manage passenger process.
74
+ Passenger starts on _127.0.0.1:3000_ by default. Add next directives to your config/deploy.rb file to
75
+ override default:
76
+
77
+ ```ruby
78
+ set :passenger_address, '127.0.0.1'
79
+ set :passenger_port, 3000
80
+ ```
81
+
82
+ Also you may bind passenger to Unix domain socket instead of TCP socket:
83
+
84
+ ```ruby
85
+ set :passenger_use_socket, true
86
+ ```
87
+
88
+ Socket file default location (`#{Rails.root}/tmp/pids/#{Rails.env}.sock` by default) can be changed:
89
+
90
+ ```ruby
91
+ set :passenger_socket_file, '/path/to/file.sock'
92
+ ```
93
+
94
+ To customise deploy task override it in `config/deploy.rb` file:
95
+
96
+ ```ruby
97
+ namespace :deploy do
98
+ task :start do
99
+
100
+ # some logic...
101
+
102
+ passenger.start
103
+
104
+ # some other logic...
105
+
106
+ end
107
+ end
108
+ ```
109
+
110
+ `passenger.start`, `passenger.stop` and `passenger.restart` tasks can be used.
111
+
112
+ ### Generate sample nginx config for application
113
+
114
+ Task `cap passenger:nginx_config` prints sample nginx config and saves it in file application tmp dir
115
+
45
116
  ## Contributing
46
117
 
47
118
  1. Fork it
@@ -0,0 +1,7 @@
1
+ module CapistranoMiscRecipes
2
+ module Bundler
3
+ def bundlify command
4
+ return defined?(Bundler) ? "bundle exec #{command}" : command
5
+ end
6
+ end
7
+ end
@@ -1,8 +1,12 @@
1
1
  # Recipes for run somoe useful console commands on server
2
2
 
3
+ require 'capistrano_misc_recipes/bundler'
4
+
3
5
  module Capistrano
4
6
  module Console
7
+
5
8
  Configuration.instance(true).load do
9
+ extend ::CapistranoMiscRecipes::Bundler
6
10
 
7
11
  def execute_ssh_locally cmd=''
8
12
  hostname = find_servers_for_task(current_task).first
@@ -32,7 +36,7 @@ module Capistrano
32
36
  task :rails, roles: :app do
33
37
 
34
38
  console_command = "rails console %s" % rails_env
35
- console_command = "bundle exec #{console_command}" if defined? Bundler
39
+ console_command = bundlify console_command
36
40
 
37
41
  execute_ssh_locally console_command
38
42
  end
@@ -40,7 +44,7 @@ module Capistrano
40
44
  desc "Open a rails db console the first app server"
41
45
  task :db, roles: :app do
42
46
  console_command = "rails dbconsole %s" % rails_env
43
- console_command = "bundle exec #{console_command}" if defined? Bundler
47
+ console_command = bundlify console_command
44
48
 
45
49
  execute_ssh_locally console_command
46
50
  end
@@ -38,6 +38,7 @@ module CapistranoMiscRecipes
38
38
  # TODO password
39
39
 
40
40
  else
41
+ # TODO handle error capistrano and rake way
41
42
  abort "Unknown command-line client for #{options['database']}"
42
43
  end
43
44
 
@@ -17,7 +17,7 @@ module Capistrano
17
17
  config = begin
18
18
  YAML.load(ERB.new(database_yml).result)[rails_env]
19
19
  rescue
20
- # TODO error report if database.yml not exists unreachable!
20
+ # TODO error report if database.yml not reachable!
21
21
  end
22
22
 
23
23
  dump_file = "/tmp/#{ capture("hostname").chomp }-#{ config['database'] }-#{ Time.now.strftime('%Y-%m-%d-%H-%M-%S') }.sql.bz2"
@@ -0,0 +1,126 @@
1
+ # Recipe for manage passenger
2
+
3
+ require 'capistrano_misc_recipes/bundler'
4
+
5
+ module Capistrano
6
+ module Passenger
7
+ Configuration.instance(true).load do
8
+ namespace :passenger do
9
+ extend ::CapistranoMiscRecipes::Bundler
10
+
11
+ _cset :passenger_pids_dir, Pathname.new(current_path).join('tmp', 'pids')
12
+ _cset :passenger_pid_file, passenger_pids_dir.join("#{rails_env}.pid")
13
+ _cset :passenger_socket_file, passenger_pids_dir.join("#{rails_env}.sock")
14
+ _cset :passenger_address, '127.0.0.1'
15
+ _cset :passenger_port, 3000
16
+ _cset :passenger_use_socket, false
17
+
18
+
19
+ desc '[internal] Start passenger'
20
+ task :start, roles: :app do
21
+
22
+ command = []
23
+ command << "cd #{current_path}"
24
+ command << "&&"
25
+ command << "rm -f #{passenger_socket_file}" # if passenger was finished ubnormally
26
+ command << "&&"
27
+ command << "#{bundlify 'passenger'} start"
28
+ command << current_path
29
+
30
+ if fetch :passenger_use_socket
31
+ command << "--socket #{passenger_socket_file}"
32
+ else
33
+ command << "--address #{passenger_address}"
34
+ command << "--port #{passenger_port}"
35
+ end
36
+
37
+ command << "--pid-file #{passenger_pid_file}"
38
+ command << "--environment #{rails_env}"
39
+ command << "--daemonize"
40
+ run command.join ' '
41
+
42
+ end
43
+
44
+ desc '[internal] Stop passenger'
45
+ task :stop, roles: :app do
46
+ run "cd #{current_path} && #{bundlify 'passenger'} stop --pid-file #{passenger_pid_file} ; true"
47
+ end
48
+
49
+ desc '[internal] Restart passenger'
50
+ task :restart, roles: :app, except: { no_release: true } do
51
+ run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
52
+ end
53
+
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
64
+
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;
73
+
74
+ location / {
75
+ try_files /system/maintence.html
76
+ $uri $uri/index.html $uri.html
77
+ @passenger;
78
+ }
79
+
80
+ location @passenger {
81
+ proxy_set_header Host $host;
82
+ proxy_set_header X-Forwarded-For $remote_addr;
83
+
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
92
+
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
+ end
97
+
98
+ end
99
+
100
+ namespace :deploy do
101
+ desc 'Starts application server'
102
+ task :start do
103
+ passenger.start
104
+ end
105
+
106
+ desc 'Stops application server'
107
+ task :stop do
108
+ passenger.stop
109
+ end
110
+
111
+ desc 'Restarts application server'
112
+ task :restart do
113
+ passenger.restart
114
+ end
115
+
116
+ desc 'Deploys your project and runs the migrate rake task'
117
+ task :full do
118
+ stop
119
+ update
120
+ migrate
121
+ restart
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
@@ -1,3 +1,3 @@
1
1
  module CapistranoMiscRecipes
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.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.0.2
4
+ version: 0.1.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-24 00:00:00.000000000 Z
12
+ date: 2013-06-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
@@ -75,9 +75,12 @@ 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
+ - lib/capistrano_misc_recipes/bundler.rb
78
80
  - lib/capistrano_misc_recipes/console.rb
79
81
  - lib/capistrano_misc_recipes/db_dump.rb
80
82
  - lib/capistrano_misc_recipes/dbfetch.rb
83
+ - lib/capistrano_misc_recipes/passenger.rb
81
84
  - lib/capistrano_misc_recipes/tasks.rb
82
85
  - lib/capistrano_misc_recipes/version.rb
83
86
  homepage: http://github.com/corlinus/capistrano_misc_recipes
@@ -95,7 +98,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
98
  version: '0'
96
99
  segments:
97
100
  - 0
98
- hash: 873591735516740147
101
+ hash: -4105244698074156849
99
102
  required_rubygems_version: !ruby/object:Gem::Requirement
100
103
  none: false
101
104
  requirements:
@@ -104,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
107
  version: '0'
105
108
  segments:
106
109
  - 0
107
- hash: 873591735516740147
110
+ hash: -4105244698074156849
108
111
  requirements: []
109
112
  rubyforge_project:
110
113
  rubygems_version: 1.8.25