capistrano-toolbox 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ require 'capistrano-toolbox/check'
2
+ require 'capistrano-toolbox/config'
3
+ require 'capistrano-toolbox/nginx'
4
+ require 'capistrano-toolbox/unicorn'
@@ -0,0 +1,47 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ namespace :check do
3
+ desc "Make sure we deploy what we expect"
4
+ task :revision do
5
+ unless @ignore_checks
6
+ here = `git rev-parse #{branch}`.chomp
7
+ there = `git ls-remote #{repository} #{branch}`.split.first
8
+ unless here == there
9
+ puts ""
10
+ puts " \033[1;33m**************************************************\033[0m"
11
+ puts " \033[1;33m* WARNING: #{branch} is not the same as origin/#{branch}\033[0m"
12
+ puts " \033[1;33m* local: #{here}\033[0m"
13
+ puts " \033[1;33m* origin: #{there}\033[0m"
14
+ puts " \033[1;33m**************************************************\033[0m"
15
+ puts ""
16
+
17
+ exit
18
+ end
19
+ end
20
+ end
21
+
22
+ desc "Make sure we don't linger in a deploy branch"
23
+ task :not_in_deploy do
24
+ unless @ignore_checks || branch == 'master'
25
+ head = `git rev-parse HEAD`.chomp
26
+ deploy = `git rev-parse #{branch}`.chomp
27
+ if head == deploy
28
+ puts ""
29
+ puts " \033[1;33m**********************************************************************\033[0m"
30
+ puts " \033[1;33m* Step out of '#{branch}' to avoid shooting yourself in the foot.\033[0m"
31
+ puts " \033[1;33m**********************************************************************\033[0m"
32
+ puts ""
33
+
34
+ exit
35
+ end
36
+ end
37
+ end
38
+
39
+ task :schema_version, :roles => :db, :only => { :primary => true } do
40
+ unless @ignore_checks
41
+ rails_env = fetch(:rails_env, "production")
42
+ # If there are pending migrations, there will be a message on STDERR which is enough to abort.
43
+ run "cd #{release_path}; bundle exec rake -s RAILS_ENV=#{rails_env} db:abort_if_pending_migrations"
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,10 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ namespace :deploy do
3
+ namespace :config do
4
+ desc "Copy config files"
5
+ task :copy_files do
6
+ run "cp #{shared_path}/config/* #{release_path}/config/"
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,29 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ def put_as_root(contents, target)
3
+ tempfile = Tempfile.new(File.basename(target))
4
+ tempfile.write(contents)
5
+ tempfile.close
6
+ rootscp(tempfile.path, target)
7
+ surun "chmod 644 #{target}"
8
+ tempfile.unlink
9
+ end
10
+
11
+ def rootscp(from, to)
12
+ servers = find_servers_for_task(current_task)
13
+ servers.each do |server|
14
+ command = "scp #{from} root@#{server}:#{to}"
15
+ puts " * \033[1;33mexecuting \"#{command}\"\033[0m"
16
+ system command
17
+ end
18
+ end
19
+
20
+ def surun (command)
21
+ puts " * \033[1;33mexecuting sudo \"#{command}\"\033[0m"
22
+ servers = find_servers_for_task(current_task)
23
+ puts " servers: #{servers.inspect}"
24
+ servers.each do |server|
25
+ puts " [#{server}] executing command"
26
+ `ssh #{server} -l root "#{command.gsub('"','\\"')}"`
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,34 @@
1
+ require 'capistrano-toolbox/helpers'
2
+
3
+ Capistrano::Configuration.instance(:must_exist).load do
4
+ namespace :deploy do
5
+ namespace :nginx do
6
+ after "update_config", "reload"
7
+
8
+ desc "Updates nginx config"
9
+ task :update_config do
10
+ config_dir = fetch(:nginx_remote_config_dir)
11
+
12
+ config = fetch(:nginx_config)
13
+ if config
14
+ available_path = File.join(config_dir, "#{application}.conf")
15
+ put_as_root(config, available_path)
16
+ surun "nxensite #{application}.conf"
17
+ end
18
+
19
+ ssl_config = fetch(:nginx_ssl_config)
20
+ if ssl_config
21
+ available_ssl_path = File.join(config_dir, "#{application}-ssl.conf")
22
+ put_as_root(ssl_config, available_ssl_path)
23
+ surun "nxensite #{application}-ssl.conf"
24
+ end
25
+ end
26
+
27
+ desc "Reload nginx config"
28
+ task :reload, :roles => :app, :except => { :no_release => true } do
29
+ surun "service nginx reload"
30
+ end
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,14 @@
1
+ require 'capistrano-toolbox/helpers'
2
+
3
+ Capistrano::Configuration.instance(:must_exist).load do
4
+ namespace :deploy do
5
+ namespace :unicorn do
6
+ task :restart, :roles => :app, :except => { :no_release => true } do
7
+ cmd = "if [ -f #{unicorn_pid} ]; then kill -s USR2 `cat #{unicorn_pid}` ; else /etc/init.d/unicorn start ; fi"
8
+ # Not specifying a shell would make it run with rvm-shell which would make "unicorn start" loop forever:
9
+ run cmd, :shell => '/bin/bash'
10
+ end
11
+ end
12
+ end
13
+
14
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-toolbox
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Jean-Louis Giordano
13
+ - Magnus Rex
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-06-25 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: capistrano
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: Some useful capistrano tools, such as unicorn restart, nginx config etc.
35
+ email: dev@spnab.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files: []
41
+
42
+ files:
43
+ - lib/capistrano-toolbox.rb
44
+ - lib/capistrano-toolbox/check.rb
45
+ - lib/capistrano-toolbox/config.rb
46
+ - lib/capistrano-toolbox/nginx.rb
47
+ - lib/capistrano-toolbox/unicorn.rb
48
+ - lib/capistrano-toolbox/helpers.rb
49
+ has_rdoc: true
50
+ homepage: http://github.com/spnab/
51
+ licenses: []
52
+
53
+ post_install_message:
54
+ rdoc_options: []
55
+
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ requirements: []
75
+
76
+ rubyforge_project:
77
+ rubygems_version: 1.3.7
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Some useful capistrano tools.
81
+ test_files: []
82
+