mina-rails-tools 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +11 -0
- data/Rakefile +1 -0
- data/lib/mina/extras/apt.rb +66 -0
- data/lib/mina/extras/brew.rb +8 -0
- data/lib/mina/extras/extra.rb +111 -0
- data/lib/mina/extras/gem.rb +64 -0
- data/lib/mina/extras/god.rb +67 -0
- data/lib/mina/extras/local.rb +12 -0
- data/lib/mina/extras/methods.rb +194 -0
- data/lib/mina/extras/mysql.rb +12 -0
- data/lib/mina/extras/nginx.rb +44 -0
- data/lib/mina/extras/osx.rb +6 -0
- data/lib/mina/extras/platform.rb +29 -0
- data/lib/mina/extras/puma.rb +5 -0
- data/lib/mina/extras/rails.rb +11 -0
- data/lib/mina/extras/rainbows.rb +63 -0
- data/lib/mina/extras/redis.rb +9 -0
- data/lib/mina/extras/system.rb +11 -0
- data/lib/mina/extras/templates/global.god.erb +23 -0
- data/lib/mina/extras/templates/god.sh.erb +39 -0
- data/lib/mina/extras/templates/nginx.conf.erb +33 -0
- data/lib/mina/extras/templates/unicorn.god.erb +69 -0
- data/lib/mina/extras/templates/unicorn.rb.erb +41 -0
- data/lib/mina/extras/templates/unicorn_init.sh.erb +66 -0
- data/lib/mina/extras/ubuntu.rb +103 -0
- data/lib/mina/extras/unicorn.rb +86 -0
- data/lib/mina/extras/version.rb +5 -0
- data/lib/mina/extras.rb +10 -0
- data/mina-rails-tools.gemspec +33 -0
- data/samples/osx/config/deploy/shared/global.god.erb +23 -0
- data/samples/osx/config/deploy/shared/god.sh.erb +41 -0
- data/samples/osx/config/deploy.rb +46 -0
- data/samples/osx/prepare.sh +7 -0
- data/samples/ubuntu/config/deploy/shared/global.god.erb +23 -0
- data/samples/ubuntu/config/deploy/shared/god.sh.erb +41 -0
- data/samples/ubuntu/config/deploy.rb +51 -0
- data/samples/ubuntu/prepare.sh +24 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6b5242ae48aecf33e80ed2ba1b510cc4ceafa441
|
4
|
+
data.tar.gz: 7f3f5b31c827d4a5c6bd9455317840ecda4225eb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3b3c616152026bc8f56da7ac4143d00c017ea91390b82b60cb0d2bb21b340582ee4bdc762810a7769cece5fa183ff12a01cfa3843778edcc470c7a2b43fa151c
|
7
|
+
data.tar.gz: fb0ff6b8dfc7a740fa41a55a18f4e65a539d6211e137f6107659456af62110beefe92cab3c6da023fc7c36efa34accea3491fc6adf0779eed4941b85cc8b7a43
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Joey Lin
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# Mina::Extras
|
2
|
+
|
3
|
+
## Contributing
|
4
|
+
|
5
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/andyss/mina-rails-tools.
|
6
|
+
|
7
|
+
|
8
|
+
## License
|
9
|
+
|
10
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
11
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,66 @@
|
|
1
|
+
set_default :apt_source, :us
|
2
|
+
|
3
|
+
def apt_get(package)
|
4
|
+
queue echo_cmd "sudo apt-get install #{package} -y"
|
5
|
+
end
|
6
|
+
|
7
|
+
namespace :apt do
|
8
|
+
namespace :get do
|
9
|
+
|
10
|
+
task :install do
|
11
|
+
apt_get("#{ENV["i"]}")
|
12
|
+
end
|
13
|
+
|
14
|
+
task :update do
|
15
|
+
queue "sudo apt-get update"
|
16
|
+
end
|
17
|
+
|
18
|
+
task :nginx do
|
19
|
+
apt_get("nginx")
|
20
|
+
end
|
21
|
+
|
22
|
+
task :git do
|
23
|
+
apt_get("git-core")
|
24
|
+
end
|
25
|
+
|
26
|
+
task :redis do
|
27
|
+
apt_get("redis-server")
|
28
|
+
end
|
29
|
+
|
30
|
+
task :mysql do
|
31
|
+
apt_get("mysql-server-5.5")
|
32
|
+
end
|
33
|
+
|
34
|
+
task :"build-essential" do
|
35
|
+
apt_get("build-essential")
|
36
|
+
end
|
37
|
+
|
38
|
+
task :"libmysqlclient-dev" do
|
39
|
+
apt_get("libmysqlclient-dev")
|
40
|
+
end
|
41
|
+
|
42
|
+
task :"libssl-dev" do
|
43
|
+
apt_get("libssl-dev")
|
44
|
+
end
|
45
|
+
|
46
|
+
task :"libreadline-dev" do
|
47
|
+
apt_get("libreadline-dev")
|
48
|
+
end
|
49
|
+
|
50
|
+
task :"libsqlite3-dev" do
|
51
|
+
apt_get("libsqlite3-dev")
|
52
|
+
end
|
53
|
+
|
54
|
+
task :"python-setuptools" do
|
55
|
+
apt_get("python-setuptools")
|
56
|
+
end
|
57
|
+
|
58
|
+
task :imagemagick do
|
59
|
+
apt_get("imagemagick")
|
60
|
+
end
|
61
|
+
|
62
|
+
task :"libmagickwand-dev" do
|
63
|
+
apt_get("libmagickwand-dev")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require "mina/extras"
|
2
|
+
|
3
|
+
set_default :sudoer, "root"
|
4
|
+
task :sudo do
|
5
|
+
# set :user, sudoer
|
6
|
+
set :sudo, true
|
7
|
+
set :term_mode, :system
|
8
|
+
end
|
9
|
+
|
10
|
+
task :user do
|
11
|
+
# set :user, user
|
12
|
+
set :sudo, false
|
13
|
+
set :term_mode, :system
|
14
|
+
end
|
15
|
+
|
16
|
+
task :setup => :environment do
|
17
|
+
invoke :"extra:create_shared_paths"
|
18
|
+
invoke :"extra:upload"
|
19
|
+
|
20
|
+
invoke :"nginx:upload"
|
21
|
+
|
22
|
+
if use_unicorn
|
23
|
+
invoke :'unicorn:upload'
|
24
|
+
|
25
|
+
if use_god
|
26
|
+
invoke :'unicorn:god:upload'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
queue %{echo "-----> (!!!) You now need to run 'mina sudoer_setup' to run the parts that require sudoer user (!!!)"}
|
31
|
+
|
32
|
+
# if sudoer?
|
33
|
+
# queue %{echo "-----> (!!!) You now need to run 'mina sudoer_setup' to run the parts that require sudoer user (!!!)"}
|
34
|
+
# else
|
35
|
+
# invoke :sudoer_setup
|
36
|
+
# end
|
37
|
+
end
|
38
|
+
|
39
|
+
task :sudoer_setup do
|
40
|
+
invoke :sudo
|
41
|
+
invoke :'nginx:link'
|
42
|
+
invoke :'nginx:restart'
|
43
|
+
|
44
|
+
if use_unicorn
|
45
|
+
invoke :'unicorn:link'
|
46
|
+
|
47
|
+
if use_god
|
48
|
+
invoke :'unicorn:god:link'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
namespace :extra do
|
54
|
+
task :create_shared_paths do
|
55
|
+
folders = shared_paths.map do |path|
|
56
|
+
path.gsub(/\/\S+\.\S+\Z/, "")
|
57
|
+
end.uniq
|
58
|
+
|
59
|
+
folders.map do |dir|
|
60
|
+
queue echo_cmd %{mkdir -p "#{deploy_to}/shared/#{dir}"}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
task :upload do
|
65
|
+
base = File.join(Dir.pwd, "config", "deploy", "shared")
|
66
|
+
|
67
|
+
Dir[File.join(base, "*")].map do |path|
|
68
|
+
# File.directory?
|
69
|
+
next if File.file?(path)
|
70
|
+
|
71
|
+
upload_shared_folder(path, base)
|
72
|
+
end
|
73
|
+
|
74
|
+
base = File.join(Dir.pwd, "config", "deploy", "#{server}")
|
75
|
+
|
76
|
+
Dir[File.join(base, "*")].map do |path|
|
77
|
+
# File.directory?
|
78
|
+
next if File.file?(path)
|
79
|
+
|
80
|
+
upload_shared_folder(path, base)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
# Allow to run some tasks as different (sudoer) user when sudo required
|
87
|
+
module Mina
|
88
|
+
module SshHelpers
|
89
|
+
def ssh_command
|
90
|
+
args = domain!
|
91
|
+
args = if settings[:sudo] && sudoer?
|
92
|
+
"#{sudoer}@#{args}"
|
93
|
+
elsif user?
|
94
|
+
"#{user}@#{args}"
|
95
|
+
end
|
96
|
+
args << " -i #{identity_file}" if identity_file?
|
97
|
+
args << " -p #{port}" if port?
|
98
|
+
args << " -t"
|
99
|
+
"ssh #{args}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
module Mina
|
106
|
+
module Helpers
|
107
|
+
def clean_commands!
|
108
|
+
@commands = nil
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
def gem_install(package, options=nil)
|
2
|
+
queue echo_cmd "sudo gem install #{package} #{options} --no-rdoc --no-ri"
|
3
|
+
end
|
4
|
+
|
5
|
+
namespace :gem do
|
6
|
+
|
7
|
+
task :install do
|
8
|
+
gem_install("#{ENV["i"]}", "#{ENV["o"]}")
|
9
|
+
end
|
10
|
+
|
11
|
+
namespace :source do
|
12
|
+
task :prepare do
|
13
|
+
if in_china?
|
14
|
+
queue echo_cmd "sudo gem source -a http://ruby.taobao.org/"
|
15
|
+
queue echo_cmd "sudo gem source -r https://rubygems.org/"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
task :list do
|
20
|
+
queue echo_cmd "sudo gem source"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
namespace :install do
|
25
|
+
task :rails do
|
26
|
+
gem_install("rails")
|
27
|
+
end
|
28
|
+
|
29
|
+
task :mysql2 do
|
30
|
+
# invoke :"ubuntu:install:libmysqlclient-dev"
|
31
|
+
gem_install("mysql2")
|
32
|
+
end
|
33
|
+
|
34
|
+
task :unicorn do
|
35
|
+
gem_install("unicorn")
|
36
|
+
end
|
37
|
+
|
38
|
+
task :mina do
|
39
|
+
gem_install("mina")
|
40
|
+
end
|
41
|
+
|
42
|
+
task :god do
|
43
|
+
gem_install("god")
|
44
|
+
end
|
45
|
+
|
46
|
+
task :rmagick do
|
47
|
+
# invoke :"ubuntu:install:imagemagick"
|
48
|
+
# invoke :"ubuntu:install:libmagickwand-dev"
|
49
|
+
gem_install("rmagick")
|
50
|
+
end
|
51
|
+
|
52
|
+
task :nokogiri do
|
53
|
+
gem_install("nokogiri")
|
54
|
+
end
|
55
|
+
|
56
|
+
task :sqlite3 do
|
57
|
+
gem_install("sqlite3")
|
58
|
+
end
|
59
|
+
|
60
|
+
task :paperclip do
|
61
|
+
gem_install("paperclip")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
set_default :god_path, "/etc/god"
|
2
|
+
set_default :god_user, "root"
|
3
|
+
set_default :god_group, "root"
|
4
|
+
set_default :god_service_path, "/etc/init.d"
|
5
|
+
set_default :god_pid_path, "/var/run"
|
6
|
+
set_default :god_log_path, "/var/log"
|
7
|
+
|
8
|
+
set :use_god, true
|
9
|
+
|
10
|
+
namespace :god do
|
11
|
+
|
12
|
+
task :setup do
|
13
|
+
queue echo_cmd "sudo mkdir -p #{god_path}/conf"
|
14
|
+
end
|
15
|
+
|
16
|
+
task :link do
|
17
|
+
extra_echo "Relocate god script file"
|
18
|
+
queue echo_cmd %{sudo rm -rf "#{god_service_path}/god"}
|
19
|
+
queue echo_cmd "sudo mkdir -p #{god_path}/conf"
|
20
|
+
queue echo_cmd "sudo chown -R #{user} #{god_path}"
|
21
|
+
queue echo_cmd %{sudo cp "#{god_path}/god.sh" "#{god_service_path}/god"}
|
22
|
+
queue echo_cmd %{sudo chown #{god_user}:#{god_group} "#{god_service_path}/god"}
|
23
|
+
queue echo_cmd %{sudo chmod +x "#{god_service_path}/god"}
|
24
|
+
queue echo_cmd "sudo chown -R #{god_user}:#{god_group} #{god_path}"
|
25
|
+
queue echo_cmd "sudo update-rc.d god defaults"
|
26
|
+
end
|
27
|
+
|
28
|
+
task :tmp_add_permission do
|
29
|
+
queue echo_cmd "sudo chown -R #{user} #{god_path}"
|
30
|
+
end
|
31
|
+
|
32
|
+
task :set_permission do
|
33
|
+
queue echo_cmd "sudo chown -R #{god_user}:#{god_group} #{god_path}"
|
34
|
+
end
|
35
|
+
|
36
|
+
task :upload => [:'upload:script', :'upload:global']
|
37
|
+
|
38
|
+
namespace :upload do
|
39
|
+
task :script do
|
40
|
+
queue echo_cmd "sudo mkdir -p #{god_path}/conf"
|
41
|
+
queue echo_cmd "sudo chown -R #{user} #{god_path}"
|
42
|
+
upload_file "god.sh", "#{god_path}/god.sh"
|
43
|
+
queue echo_cmd "sudo chown -R #{god_user}:#{god_group} #{god_path}"
|
44
|
+
end
|
45
|
+
|
46
|
+
task :global do
|
47
|
+
queue echo_cmd "sudo mkdir -p #{god_path}/conf"
|
48
|
+
queue echo_cmd "sudo chown -R #{user} #{god_path}"
|
49
|
+
upload_file 'global.god', "#{god_path}/global.god"
|
50
|
+
queue echo_cmd "sudo chown -R #{god_user}:#{god_group} #{god_path}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
%w(stop start restart status).each do |action|
|
55
|
+
desc "#{action.capitalize} God"
|
56
|
+
task action.to_sym do
|
57
|
+
invoke :sudo
|
58
|
+
queue %{echo "-----> #{action.capitalize} God"}
|
59
|
+
queue echo_cmd "sudo #{god_service_path}/god #{action}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
task :log do
|
64
|
+
invoke :sudo
|
65
|
+
queue %{sudo tail -f #{god_log_path}/god.log -n #{ENV["n"] || 200}}
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# set_default :ssh_pub_key_path, "/home/"
|
2
|
+
# set_default :ssh_key_path, "/home/"
|
3
|
+
#
|
4
|
+
namespace :local do
|
5
|
+
task :check_ssh_key do
|
6
|
+
check_key = check_file_exist?(ssh_pub_key_path!) && check_file_exist?(ssh_key_path!)
|
7
|
+
|
8
|
+
unless check_key
|
9
|
+
queue "ssh-keygen -t rsa"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
def mv_config(source, destination)
|
2
|
+
queue %{mv #{deploy_to}/shared/config/#{source} #{deploy_to}/shared/config/#{destination}}
|
3
|
+
end
|
4
|
+
|
5
|
+
def extra_echo(desc)
|
6
|
+
queue "echo '--------> #{desc}'"
|
7
|
+
end
|
8
|
+
|
9
|
+
def extra_echo!(desc)
|
10
|
+
queue! "echo '--------> #{desc}'"
|
11
|
+
end
|
12
|
+
|
13
|
+
def scp_file(desc, source, destination)
|
14
|
+
to :after_hook do
|
15
|
+
extra_echo("Put #{desc} file to #{destination}")
|
16
|
+
|
17
|
+
command = "scp "
|
18
|
+
command << source
|
19
|
+
command << " #{user}@#{domain!}:#{destination}"
|
20
|
+
|
21
|
+
extra_echo("#{command}")
|
22
|
+
|
23
|
+
result = %x[#{command}]
|
24
|
+
puts result unless result == ""
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def upload_shared_file(filename)
|
29
|
+
src = custom_conf_path(filename)
|
30
|
+
|
31
|
+
if src
|
32
|
+
upload_template src, "#{deploy_to}/shared/#{filename}"
|
33
|
+
else
|
34
|
+
upload_default_template filename, "#{deploy_to}/shared/#{filename}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def upload_file(filename, destination)
|
39
|
+
src = custom_conf_path(filename)
|
40
|
+
|
41
|
+
if src
|
42
|
+
upload_template src, destination
|
43
|
+
else
|
44
|
+
upload_default_template filename, destination
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def append_template(source, destination)
|
49
|
+
desc = File.basename(destination)
|
50
|
+
|
51
|
+
if source =~ /erb$/
|
52
|
+
contents = parse_template(source)
|
53
|
+
else
|
54
|
+
contents = File.read(source)
|
55
|
+
end
|
56
|
+
|
57
|
+
extra_echo("Put #{desc} file to #{destination}")
|
58
|
+
|
59
|
+
script = <<EOF
|
60
|
+
script=$(cat <<'EOFF'
|
61
|
+
#{contents}
|
62
|
+
EOFF
|
63
|
+
)
|
64
|
+
EOF
|
65
|
+
|
66
|
+
queue %{#{script}}
|
67
|
+
queue %{echo "$script" >> #{destination}}
|
68
|
+
queue check_exists(destination)
|
69
|
+
end
|
70
|
+
|
71
|
+
def upload_template(source, destination)
|
72
|
+
desc = File.basename(destination)
|
73
|
+
|
74
|
+
if source =~ /erb$/
|
75
|
+
contents = parse_template(source)
|
76
|
+
else
|
77
|
+
contents = parse_template(source)
|
78
|
+
end
|
79
|
+
|
80
|
+
extra_echo("Put #{desc} file to #{destination}")
|
81
|
+
|
82
|
+
script = <<EOF
|
83
|
+
script=$(cat <<'EOFF'
|
84
|
+
#{contents}
|
85
|
+
EOFF
|
86
|
+
)
|
87
|
+
EOF
|
88
|
+
|
89
|
+
queue %{#{script}}
|
90
|
+
queue %{echo "$script" > #{destination}}
|
91
|
+
queue check_exists(destination)
|
92
|
+
end
|
93
|
+
|
94
|
+
def upload_default_template(tpl, destination)
|
95
|
+
desc = File.basename(destination)
|
96
|
+
|
97
|
+
source = File.join(File.dirname(__FILE__), "templates", "#{tpl}.erb")
|
98
|
+
|
99
|
+
contents = parse_template(source)
|
100
|
+
|
101
|
+
extra_echo("Put #{desc} file to #{destination}")
|
102
|
+
|
103
|
+
script = <<EOF
|
104
|
+
script=$(cat <<'EOFF'
|
105
|
+
#{contents}
|
106
|
+
EOFF
|
107
|
+
)
|
108
|
+
EOF
|
109
|
+
|
110
|
+
queue %{#{script}}
|
111
|
+
queue %{echo "$script" > #{destination}}
|
112
|
+
queue check_exists(destination)
|
113
|
+
end
|
114
|
+
|
115
|
+
def upload_shared_folder(folder, base)
|
116
|
+
Dir[File.join(folder, "*")].map do |path|
|
117
|
+
if File.directory?(path)
|
118
|
+
upload_shared_folder(path)
|
119
|
+
else
|
120
|
+
filename = File.basename(path)
|
121
|
+
shared_folder = path.gsub(base, "").gsub(filename, "").gsub(/\A\//, "").gsub(/\/\Z/, "")
|
122
|
+
des = "#{deploy_to}/shared/#{shared_folder}/#{filename.gsub(/\.erb$/, "")}"
|
123
|
+
upload_template path, des
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
def parse_template(file)
|
130
|
+
erb(file)
|
131
|
+
end
|
132
|
+
|
133
|
+
def check_response
|
134
|
+
'then echo "-----> SUCCESS"; else echo "-----> FAILED"; fi'
|
135
|
+
end
|
136
|
+
|
137
|
+
def check_exists(destination)
|
138
|
+
%{if [[ -s "#{destination}" ]]; #{check_response}}
|
139
|
+
end
|
140
|
+
|
141
|
+
def check_ownership(u, g, destination)
|
142
|
+
%{
|
143
|
+
file_info=(`ls -l #{destination}`)
|
144
|
+
if [[ -s "#{destination}" ]] && [[ ${file_info[2]} == '#{u}' ]] && [[ ${file_info[3]} == '#{g}' ]]; #{check_response}
|
145
|
+
}
|
146
|
+
end
|
147
|
+
|
148
|
+
def check_exec_and_ownership(u, g, destination)
|
149
|
+
%{
|
150
|
+
file_info=(`ls -l #{destination}`)
|
151
|
+
if [[ -s "#{destination}" ]] && [[ -x "#{destination}" ]] && [[ ${file_info[2]} == '#{u}' ]] && [[ ${file_info[3]} == '#{g}' ]]; #{check_response}
|
152
|
+
}
|
153
|
+
end
|
154
|
+
|
155
|
+
def check_symlink(destination)
|
156
|
+
%{if [[ -h "#{destination}" ]]; #{check_response}}
|
157
|
+
end
|
158
|
+
|
159
|
+
def custom_conf?(conf)
|
160
|
+
Dir[File.join(Dir.pwd, "config", "deploy", "#{server}", "*")].map do |file|
|
161
|
+
filename = File.basename(file)
|
162
|
+
if filename.gsub(/.erb\Z/, "") == conf.to_s
|
163
|
+
return true
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
false
|
168
|
+
end
|
169
|
+
|
170
|
+
def custom_conf_path(conf)
|
171
|
+
Dir[File.join(Dir.pwd, "config", "deploy", "#{server}", "*")].map do |file|
|
172
|
+
filename = File.basename(file)
|
173
|
+
if filename.gsub(/.erb\Z/, "") == conf.to_s
|
174
|
+
return file
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
Dir[File.join(Dir.pwd, "config", "deploy", "shared", "*")].map do |file|
|
179
|
+
filename = File.basename(file)
|
180
|
+
if filename.gsub(/.erb\Z/, "") == conf.to_s
|
181
|
+
return file
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
false
|
186
|
+
end
|
187
|
+
|
188
|
+
def queue_echo(s)
|
189
|
+
queue %{echo '#{s}'}
|
190
|
+
end
|
191
|
+
|
192
|
+
def check_file_exist?(file)
|
193
|
+
File.exist?(file)
|
194
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "mina/extras"
|
2
|
+
|
3
|
+
set_default :nginx_conf_path, "/etc/nginx/sites-enabled"
|
4
|
+
set_default :nginx_port, 80
|
5
|
+
set_default :nginx_default, false
|
6
|
+
|
7
|
+
namespace :nginx do
|
8
|
+
|
9
|
+
# desc "Nginx: Setup config files"
|
10
|
+
# task :setup => [:upload, :link]
|
11
|
+
|
12
|
+
desc "Nginx: Parses config file and uploads it to server"
|
13
|
+
task :upload do
|
14
|
+
upload_shared_file("nginx.conf")
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Nginx: Symlink config file"
|
18
|
+
task :link do
|
19
|
+
invoke :sudo
|
20
|
+
extra_echo("Nginx: Symlink config file")
|
21
|
+
|
22
|
+
queue echo_cmd %{sudo ln -fs "#{deploy_to}/shared/nginx.conf" "#{nginx_conf_path}/#{app!}.conf"}
|
23
|
+
# queue check_symlink nginx_conf_path
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "Current nginx config"
|
27
|
+
task :config do
|
28
|
+
invoke :sudo
|
29
|
+
|
30
|
+
queue_echo("#"*80)
|
31
|
+
queue_echo("# File: #{nginx_conf_path}/#{app!}.conf")
|
32
|
+
queue %{sudo cat "#{nginx_conf_path}/#{app!}.conf"}
|
33
|
+
queue_echo("#"*80)
|
34
|
+
end
|
35
|
+
|
36
|
+
%w(stop start restart reload status).each do |action|
|
37
|
+
desc "#{action.capitalize} Nginx"
|
38
|
+
task action.to_sym do
|
39
|
+
invoke :sudo
|
40
|
+
extra_echo("Nginx: #{action.capitalize}")
|
41
|
+
queue echo_cmd "sudo service nginx #{action}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
set_default :platform, :ubuntu
|
2
|
+
set_default :webserver, :unicorn
|
3
|
+
|
4
|
+
namespace :platform do
|
5
|
+
desc 'List support platforms'
|
6
|
+
task :list do
|
7
|
+
p ["ubuntu", "OS X"].join(", ")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "Roll backs the lates release"
|
12
|
+
task :rollback => :environment do
|
13
|
+
extra_echo!("Rolling back to previous release for instance: #{domain}")
|
14
|
+
queue! %[echo "-----> Rolling back to previous release for instance: #{domain}"]
|
15
|
+
|
16
|
+
# remove latest release folder (active release)
|
17
|
+
extra_echo("Deleting active release: ")
|
18
|
+
|
19
|
+
queue %[ls "#{deploy_to}/releases" -Art | sort | tail -n 1]
|
20
|
+
queue! %[ls "#{deploy_to}/releases" -Art | sort | tail -n 1 | xargs -I active rm -rf "#{deploy_to}/releases/active"]
|
21
|
+
|
22
|
+
# delete existing sym link and create a new symlink pointing to the previous release
|
23
|
+
extra_echo("Creating new symlink from the previous release: ")
|
24
|
+
queue %[ls "#{deploy_to}/releases" -Art | sort | tail -n 1]
|
25
|
+
queue! %[rm "#{deploy_to}/current"]
|
26
|
+
queue! %[ls -Art "#{deploy_to}/releases" | sort | tail -n 1 | xargs -I active ln -s "#{deploy_to}/releases/active" "#{deploy_to}/current"]
|
27
|
+
|
28
|
+
invoke :'unicorn:restart'
|
29
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
set_default :log_line, 200
|
2
|
+
|
3
|
+
desc "Rails Log"
|
4
|
+
task :log => :environment do
|
5
|
+
queue echo_cmd("cd #{deploy_to}/current && tail -f log/production.log -n #{ENV["n"] || log_line}")
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "Rails Console"
|
9
|
+
task :console => :environment do
|
10
|
+
queue echo_cmd("cd #{deploy_to}/current && RAILS_ENV=production bundle exec rails c")
|
11
|
+
end
|