ms_deploy 0.2.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,7 +27,7 @@ Capistrano::Configuration.instance.load do
27
27
  run "sudo /etc/init.d/nginx restart"
28
28
  end
29
29
 
30
- task :setup do
30
+ task :setup, :roles => :web do
31
31
  protocol = fetch(:protocol, nil).to_s
32
32
  template_path = File.expand_path('../../templates/vhost.erb', __FILE__)
33
33
  vars = {
@@ -50,32 +50,61 @@ Capistrano::Configuration.instance.load do
50
50
  if protocol.nil? or protocol == 'http' or protocol == 'both'
51
51
  config_path = "#{shared_path}/config/#{application}_vhost.conf"
52
52
 
53
- put(render_erb_template(template_path, vars), config_path)
54
- sudo "rm -f /etc/nginx/sites-enabled/#{application}_#{stage}.conf"
55
- sudo "ln -s #{config_path} /etc/nginx/sites-enabled/#{application}_#{stage}.conf"
56
- end
57
- if protocol == 'https' or protocol == 'both'
58
- vars.merge!({'protocol' => 'https'})
53
+ sites_path = fetch(:nginx_sites_enabled_path, "/etc/nginx/sites-enabled")
54
+
55
+ if protocol.nil? or protocol == 'http' or protocol == 'both'
56
+ config_path = "#{shared_path}/config/#{application}_vhost.conf"
57
+
58
+ put(render_erb_template(template_path, vars), config_path)
59
+
60
+ with_user(fetch(:setup_user, user)) do
61
+ try_sudo "rm -f #{sites_path}/#{application}_#{stage}.conf"
62
+ try_sudo "ln -s #{config_path} #{sites_path}/#{application}_#{stage}.conf"
63
+ end
64
+ end
65
+ if protocol == 'https' or protocol == 'both'
66
+ vars.merge!({'protocol' => 'https'})
67
+
68
+ config_path = "#{shared_path}/config/#{application}_ssl_vhost.conf"
59
69
 
60
- config_path = "#{shared_path}/config/#{application}_ssl_vhost.conf"
70
+ put(render_erb_template(template_path, vars), config_path)
61
71
 
62
- put(render_erb_template(template_path, vars), config_path)
63
- sudo "rm -f /etc/nginx/sites-enabled/#{application}_#{stage}_ssl.conf"
64
- sudo "ln -s #{config_path} /etc/nginx/sites-enabled/#{application}_#{stage}_ssl.conf"
72
+ with_user(fetch(:setup_user, user)) do
73
+ try_sudo "rm -f #{sites_path}/#{application}_#{stage}_ssl.conf"
74
+ try_sudo "ln -s #{config_path} #{sites_path}/#{application}_#{stage}_ssl.conf"
75
+ end
76
+ end
65
77
  end
66
78
  end
67
79
 
68
80
  task :uninstall do
69
81
  protocol = fetch(:protocol, nil)
82
+ sites_path = fetch(:nginx_sites_enabled_path, "/etc/nginx/sites-enabled")
70
83
 
71
- if protocol.blank? or protocol == 'http' or protocol == 'both'
72
- sudo "rm -f /etc/nginx/sites-enabled/#{application}_#{stage}.conf"
73
- elsif protocol == 'https' or protocol == 'both'
74
- sudo "rm -f /etc/nginx/sites-enabled/#{application}_#{stage}_ssl.conf"
84
+ with_user(fetch(:setup_user, user)) do
85
+ if protocol.blank? or protocol == 'http' or protocol == 'both'
86
+ try_sudo "rm -f #{sites_path}/#{application}_#{stage}.conf"
87
+ elsif protocol == 'https' or protocol == 'both'
88
+ try_sudo "rm -f #{sites_path}/#{application}_#{stage}_ssl.conf"
89
+ end
75
90
  end
76
91
  end
77
92
  end
78
93
 
79
94
  after :"deploy:setup", :"nginx:setup";
80
95
 
96
+ def with_user(new_user, &block)
97
+ old_user = user
98
+ set :user, new_user
99
+ close_sessions
100
+ yield
101
+ set :user, old_user
102
+ close_sessions
103
+ end
104
+
105
+ def close_sessions
106
+ sessions.values.each { |session| session.close }
107
+ sessions.clear
108
+ end
109
+
81
110
  end
@@ -2,6 +2,6 @@ Capistrano::Configuration.instance.load do
2
2
  abort "You must set :user before using defaults" unless fetch(:user)
3
3
 
4
4
  set :default_environment, {
5
- 'PATH' => "/home/#{user}/.rbenv/shims:/home/#{user}/.rbenv/bin:$PATH"
5
+ 'PATH' => "/home/#{fetch(:user)}/.rbenv/shims:/home/#{fetch(:user)}/.rbenv/bin:$PATH"
6
6
  }
7
7
  end
@@ -2,7 +2,7 @@ Capistrano::Configuration.instance.load do
2
2
 
3
3
  namespace :deploy do
4
4
  namespace :prepare do
5
- task :create_config_files do
5
+ task :create_config_files, :roles => :app do
6
6
  run "mkdir -p #{shared_path}/config/"
7
7
  config_file_to_setup.each do |config_file|
8
8
  put(File.read(config_file_path(config_file)), "#{shared_path}/config/#{config_file}", :via => :scp)
@@ -10,11 +10,11 @@ Capistrano::Configuration.instance.load do
10
10
  end
11
11
 
12
12
  desc "Set up shared directory structure"
13
- task :create_shared_folders do
13
+ task :create_shared_folders, :roles => :app do
14
14
  directories_to_create.each { |directory| run "mkdir -p #{directory}" }
15
15
  end
16
16
 
17
- task :database do
17
+ task :database, :roles => :db do
18
18
  _cset :db_admin_user, 'root'
19
19
  _cset :db_admin_password, Capistrano::CLI.password_prompt("Type your mysql password for user '#{db_admin_user}' (not set if empty): ")
20
20
  _cset :db_name, application.gsub(/\W+/, '')[0..5] + '_' + rails_env.to_s
@@ -11,7 +11,7 @@ Capistrano::Configuration.instance.load do
11
11
 
12
12
  namespace :unicorn do
13
13
  desc "Setup unicorn"
14
- task :setup, :except => { :no_release => true } do
14
+ task :setup, :roles => :app, :except => { :no_release => true } do
15
15
  run "mkdir -p \"#{shared_path}/config/unicorn\""
16
16
  config_path = "#{shared_path}/config/unicorn/#{stage}.rb"
17
17
  template_path = File.expand_path('../../templates/unicorn/unicorn.rb.erb', __FILE__)
@@ -30,4 +30,14 @@ Capistrano::Configuration.instance.load do
30
30
  end
31
31
 
32
32
  after :"deploy:setup", :"unicorn:setup";
33
+
34
+ namespace :deploy do
35
+ task :start, :roles => :app do
36
+ unicorn.start
37
+ end
38
+
39
+ task :stop, :roles => :app do
40
+ unicorn.stop
41
+ end
42
+ end
33
43
  end
@@ -1,3 +1,3 @@
1
1
  module MsDeploy
2
- VERSION = "0.2.5"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ms_deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.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: 2012-08-18 00:00:00.000000000 Z
12
+ date: 2012-09-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gemcutter