uhl-cap-recipes 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Capfile +4 -0
- data/LICENSE +20 -0
- data/README.textile +586 -0
- data/Rakefile +61 -0
- data/VERSION.yml +5 -0
- data/bin/cap-recipes +4 -0
- data/cap-recipes.gemspec +128 -0
- data/config/deploy.rb +35 -0
- data/examples/advanced/deploy.rb +39 -0
- data/examples/advanced/deploy/experimental.rb +14 -0
- data/examples/advanced/deploy/production.rb +20 -0
- data/examples/simple/deploy.rb +36 -0
- data/lib/cap_recipes.rb +1 -0
- data/lib/cap_recipes/tasks/gitdeploy.rb +1 -0
- data/lib/cap_recipes/tasks/gitdeploy/setup.rb +180 -0
- data/lib/cap_recipes/tasks/http.rb +102 -0
- data/lib/cap_recipes/tasks/play.rb +201 -0
- data/lib/cap_recipes/tasks/sdpdeploy/autoinstall.rb +78 -0
- data/lib/cap_recipes/tasks/sdpdeploy/iis.rb +72 -0
- data/lib/cap_recipes/tasks/sdpdeploy/sft.rb +1 -0
- data/lib/cap_recipes/tasks/sdpdeploy/sfttask.rb +272 -0
- data/lib/cap_recipes/tasks/templates/hudson.erb +85 -0
- data/lib/cap_recipes/tasks/templates/mongod.conf.erb +89 -0
- data/lib/cap_recipes/tasks/templates/mongodb.init.erb +73 -0
- data/lib/cap_recipes/tasks/templates/mongodb.repo.erb +4 -0
- data/lib/cap_recipes/tasks/templates/mongos.init.erb +69 -0
- data/lib/cap_recipes/tasks/templates/tomcat.erb +95 -0
- data/lib/cap_recipes/tasks/uhljenkins.rb +217 -0
- data/lib/cap_recipes/tasks/utilities.rb +172 -0
- data/lib/capify.rb +35 -0
- data/lib/templates/Capfile.tt +4 -0
- data/lib/templates/deploy.rb.tt +30 -0
- data/spec/cap/all/Capfile +2 -0
- data/spec/cap/helper.rb +3 -0
- data/spec/cap_recipes_spec.rb +56 -0
- data/spec/spec_helper.rb +37 -0
- data/specs.watchr +35 -0
- data/test.rb +105 -0
- metadata +118 -0
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'net/https'
|
3
|
+
require 'uri' # there be bugs here
|
4
|
+
require "addressable/uri" # no more URI::InvalidURIError: bad URI(is not URI?)
|
5
|
+
|
6
|
+
class HTTP
|
7
|
+
class << self
|
8
|
+
def get(url, options = {})
|
9
|
+
execute(url, options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def post(url, options = {})
|
13
|
+
options = { :method => :post }.merge(options)
|
14
|
+
execute(url, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def encoding(response)
|
18
|
+
return $1.downcase if response['content-type'] =~ /charset=(.*)/i
|
19
|
+
return $1.downcase if response.body =~ /<meta.*?charset=([^"'>]+)/mi
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def proxy
|
25
|
+
http_proxy = ENV["http_proxy"]
|
26
|
+
Addressable::URI.parse(http_proxy) rescue nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_uri(url)
|
30
|
+
if !url.respond_to?(:scheme)
|
31
|
+
url = Addressable::URI.parse(url)
|
32
|
+
end
|
33
|
+
url
|
34
|
+
end
|
35
|
+
|
36
|
+
def execute(url, options = {})
|
37
|
+
options = { :parameters => {}, :debug => false, :follow_redirects => true,
|
38
|
+
:http_timeout => 60, :method => :get,
|
39
|
+
:headers => {}, :redirect_count => 0,
|
40
|
+
:max_redirects => 10 }.merge(options)
|
41
|
+
|
42
|
+
url = to_uri(url)
|
43
|
+
|
44
|
+
if proxy
|
45
|
+
http = Net::HTTP::Proxy(proxy.host, proxy.port).new(url.host, url.port)
|
46
|
+
else
|
47
|
+
http = Net::HTTP.new(url.host, url.port)
|
48
|
+
end
|
49
|
+
|
50
|
+
if url.scheme == 'https'
|
51
|
+
http.use_ssl = true
|
52
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
53
|
+
end
|
54
|
+
|
55
|
+
http.open_timeout = http.read_timeout = options[:http_timeout]
|
56
|
+
|
57
|
+
http.set_debug_output $stderr if options[:debug]
|
58
|
+
|
59
|
+
request = case options[:method]
|
60
|
+
when :post
|
61
|
+
request = Net::HTTP::Post.new(url.request_uri)
|
62
|
+
request.set_form_data(options[:parameters])
|
63
|
+
request
|
64
|
+
else
|
65
|
+
Net::HTTP::Get.new(url.request_uri)
|
66
|
+
end
|
67
|
+
|
68
|
+
options[:headers].each { |key, value| request[key] = value }
|
69
|
+
response = http.request(request)
|
70
|
+
|
71
|
+
# Handle redirection
|
72
|
+
if options[:follow_redirects] && response.kind_of?(Net::HTTPRedirection)
|
73
|
+
options[:redirect_count] += 1
|
74
|
+
|
75
|
+
if options[:redirect_count] > options[:max_redirects]
|
76
|
+
raise "Too many redirects (#{options[:redirect_count]}): #{url}"
|
77
|
+
end
|
78
|
+
|
79
|
+
redirect_url = redirect_url(response)
|
80
|
+
|
81
|
+
if redirect_url.start_with?('/')
|
82
|
+
url = to_uri("#{url.scheme}://#{url.host}#{redirect_url}")
|
83
|
+
else
|
84
|
+
url = to_uri(redirect_url)
|
85
|
+
end
|
86
|
+
|
87
|
+
response, url = execute(url, options)
|
88
|
+
end
|
89
|
+
|
90
|
+
[response, url.to_s]
|
91
|
+
end
|
92
|
+
|
93
|
+
# From http://railstips.org/blog/archives/2009/03/04/following-redirects-with-nethttp/
|
94
|
+
def redirect_url(response)
|
95
|
+
if response['location'].nil?
|
96
|
+
response.body.match(/<a href=\"([^>]+)\">/i)[1]
|
97
|
+
else
|
98
|
+
response['location']
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,201 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
Capistrano::Configuration.instance(true).load do |configuration|
|
3
|
+
set :use_sudo, true
|
4
|
+
|
5
|
+
_cset :deploy_to_parent, "/srv/applications"
|
6
|
+
_cset :branch, "master"
|
7
|
+
|
8
|
+
default_run_options[:pty] = true
|
9
|
+
|
10
|
+
# this is capistrano's default location.
|
11
|
+
# depending on the permissions of the server
|
12
|
+
# you may need to create it and chown it over
|
13
|
+
# to :user (e.g. chown -R robotuser:robotuser /u)
|
14
|
+
set :deploy_to do
|
15
|
+
"#{deploy_to_parent}/#{application}"
|
16
|
+
end
|
17
|
+
|
18
|
+
set :deploy_to_gitrepo do
|
19
|
+
"#{deploy_to}/repo"
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
set :local_base_dir do
|
24
|
+
"#{`pwd`}".strip
|
25
|
+
end
|
26
|
+
|
27
|
+
_cset :_config, Array.new
|
28
|
+
_cset :build_name, "ROOT"
|
29
|
+
_cset :build_path, "not set.war"
|
30
|
+
|
31
|
+
_cset :servers, ""
|
32
|
+
_cset :deploy_to, ""
|
33
|
+
|
34
|
+
set :local_git_dir do
|
35
|
+
"/tmp/localgit_#{application}"
|
36
|
+
end
|
37
|
+
set :local_gitrepo do
|
38
|
+
"#{local_git_dir}/#{application}"
|
39
|
+
end
|
40
|
+
|
41
|
+
role :app, :primary => true do
|
42
|
+
if servers.empty?
|
43
|
+
"1.1.1.1"
|
44
|
+
else
|
45
|
+
servers.split(/[,\s]+/)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
namespace :play do
|
50
|
+
|
51
|
+
desc "start service"
|
52
|
+
task :start_service do
|
53
|
+
run "sc start #{service_name}"
|
54
|
+
end
|
55
|
+
|
56
|
+
desc "stop service"
|
57
|
+
task :stop_service do
|
58
|
+
run "sc stop #{service_name}"
|
59
|
+
end
|
60
|
+
|
61
|
+
desc "stop and start service"
|
62
|
+
task :restart_service do
|
63
|
+
play.stop_service
|
64
|
+
play.start_service
|
65
|
+
end
|
66
|
+
|
67
|
+
desc "setup remote and locate play dir"
|
68
|
+
task :setup do
|
69
|
+
play.setup_remote
|
70
|
+
play.setup_local
|
71
|
+
end
|
72
|
+
|
73
|
+
desc "setup remote play dir"
|
74
|
+
task :setup_remote do
|
75
|
+
run clone_repository_command()
|
76
|
+
end
|
77
|
+
|
78
|
+
desc "setup locate play dir"
|
79
|
+
task :setup_local do
|
80
|
+
system clone_repository_local_command()
|
81
|
+
end
|
82
|
+
|
83
|
+
desc "just pull current build version, doesn't add tag."
|
84
|
+
task :pull do
|
85
|
+
play.setup_local
|
86
|
+
|
87
|
+
system "cd #{local_gitrepo}; git checkout #{branch}; git fetch; git rebase origin/#{branch};"
|
88
|
+
|
89
|
+
unless play_name.empty?
|
90
|
+
puts "name=#{play_name}, war=#{play_path}"
|
91
|
+
system update_repository_local_command(play_name, play_path)
|
92
|
+
else
|
93
|
+
if war_config.nil? or war_config.size == 0
|
94
|
+
raise 'NO war_config'
|
95
|
+
end
|
96
|
+
war_config.each do |config|
|
97
|
+
puts "name=#{config[:name]}, war=#{config[:war]}"
|
98
|
+
system update_repository_local_command(config[:name], config[:war])
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
build_msg = play_name.empty? ? "all" : play_name
|
103
|
+
system "cd #{local_gitrepo}; git add .; git commit -m 'build for #{build_msg}'"
|
104
|
+
|
105
|
+
# push tags and latest code
|
106
|
+
system "cd #{local_gitrepo}; git push origin #{branch}"
|
107
|
+
if $? != 0
|
108
|
+
raise "git push failed"
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
desc "tag build version. use -s tag=xxx to set tag's name"
|
114
|
+
task :tag do
|
115
|
+
play.setup_local
|
116
|
+
system "cd #{local_gitrepo}; git checkout #{branch}; git fetch; git rebase origin/#{branch};"
|
117
|
+
|
118
|
+
tag_name = configuration[:tag] || configuration[:build_version]
|
119
|
+
raise "NO tag. pls use -s tag=xxx set tag_name" if tag_name.nil?
|
120
|
+
|
121
|
+
system "cd #{local_gitrepo}; git tag #{tag_name};"
|
122
|
+
|
123
|
+
system "cd #{local_gitrepo}; git push origin #{branch} --tags"
|
124
|
+
if $? != 0
|
125
|
+
raise "git push --tags failed"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
desc "deploy. use -s tag=xxx to set tag's name, if NOT set tag, pull the repository's last version."
|
130
|
+
task :deploy do
|
131
|
+
play.setup_remote
|
132
|
+
tag_name = configuration[:tag] || configuration[:build_version]
|
133
|
+
unless tag_name.nil?
|
134
|
+
# raise "NO tag. pls use -s tag=xxx set tag_name"
|
135
|
+
run update_repository_remote_command(tag_name)
|
136
|
+
else
|
137
|
+
run pull_repository_remote_command(branch)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def self.clone_repository_local_command
|
142
|
+
[
|
143
|
+
"rm -Rf #{local_git_dir}",
|
144
|
+
"mkdir -p #{local_git_dir}",
|
145
|
+
"cd #{local_git_dir}",
|
146
|
+
"git clone #{repository} #{local_gitrepo}"
|
147
|
+
].join("; ")
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
def self.update_repository_local_command(name, path)
|
152
|
+
unless path.start_with?('/')
|
153
|
+
play_path = "#{local_base_dir}/#{path}"
|
154
|
+
else
|
155
|
+
play_path = path
|
156
|
+
end
|
157
|
+
[
|
158
|
+
"cd #{local_gitrepo}",
|
159
|
+
"if [ -e #{local_gitrepo}/#{name} ]",
|
160
|
+
"then git rm -rf #{local_gitrepo}/#{name}",
|
161
|
+
"fi",
|
162
|
+
"mkdir -p #{local_gitrepo}/#{name}",
|
163
|
+
"cd #{local_gitrepo}/#{name}",
|
164
|
+
"cp #{play_path} . -r"
|
165
|
+
].join("; ")
|
166
|
+
end
|
167
|
+
|
168
|
+
def self.clone_repository_command
|
169
|
+
[
|
170
|
+
"if [ ! -e #{deploy_to_gitrepo} ]",
|
171
|
+
"then sudo mkdir -p #{deploy_to}",
|
172
|
+
"sudo chown #{user} #{deploy_to}",
|
173
|
+
"cd #{deploy_to}",
|
174
|
+
"git clone #{repository} #{deploy_to_gitrepo}",
|
175
|
+
"fi"
|
176
|
+
].join("; ")
|
177
|
+
end
|
178
|
+
|
179
|
+
def self.update_repository_remote_command(tag_name)
|
180
|
+
[
|
181
|
+
# git reset --hard;git fetch;git reset --merge #{tag_name}
|
182
|
+
"cd #{deploy_to_gitrepo}",
|
183
|
+
"git reset --hard",
|
184
|
+
"git fetch",
|
185
|
+
"git reset --merge #{tag_name}",
|
186
|
+
].join("; ")
|
187
|
+
end
|
188
|
+
|
189
|
+
def self.pull_repository_remote_command(branch)
|
190
|
+
[
|
191
|
+
# git reset --hard;git fetch;git reset --merge #{tag_name}
|
192
|
+
"cd #{deploy_to_gitrepo}",
|
193
|
+
"git reset --hard",
|
194
|
+
"git fetch",
|
195
|
+
"git rebase origin/#{branch}",
|
196
|
+
].join("; ")
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
Capistrano::Configuration.instance(true).load do
|
2
|
+
namespace :autointall do
|
3
|
+
|
4
|
+
desc "GITgetgitDir_fromGitserver"
|
5
|
+
task :autoInstallfileGetorUpdate, :max_hosts=>1 do
|
6
|
+
run %{
|
7
|
+
mkdir -p /opt/applications/;mkdir /opt/logs;
|
8
|
+
mkdir -p /opt/autoinstalldir;cd /opt/autoinstalldir;pwd;
|
9
|
+
git init;
|
10
|
+
git remote add origin gituser@gitsource.shengpay.com:/opt/gitroot/autoinstalldir.git;
|
11
|
+
git remote -v;
|
12
|
+
git fetch;git fetch -t;git fetch;
|
13
|
+
git pull origin master;
|
14
|
+
ls -a;git status;
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
task :install_Nginx,:mas_hosts=>1 do
|
20
|
+
run %{
|
21
|
+
cd /opt/autoinstalldir; sh nginx-install.sh;
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
task :install_JDK,:mas_hosts=>1 do
|
26
|
+
run %{
|
27
|
+
cd /opt/autoinstalldir; sh java-install.sh;
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
task :install_jboss,:mas_hosts=>1 do
|
32
|
+
run %{
|
33
|
+
cd /opt/autoinstalldir; sh jboss-install.sh;
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
task :install_memcached,:mas_hosts=>1 do
|
38
|
+
run %{
|
39
|
+
cd /opt/autoinstalldir; sh memcached-install.sh;
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "for memcache "
|
44
|
+
task :install_ttserver,:mas_hosts=>1 do
|
45
|
+
run %{
|
46
|
+
cd /opt/autoinstalldir; sh tt-install.sh;
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
desc "tomcat install task"
|
51
|
+
task :tomcat_install, :max_hosts=>1 do
|
52
|
+
run %{
|
53
|
+
cd /opt/autoinstalldir; sh tomcat-install.sh ;
|
54
|
+
echo "usage sh createInstance.sh -d tcServer1 -n 10000 -a 8010 -h 8080 -s 8440 -j 6900 to create tomcat instance";
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
desc "tomcat instance create task"
|
59
|
+
task :tomcat_instance_create, :max_hosts=>1 do
|
60
|
+
run %{
|
61
|
+
cd /opt/autoinstalldir/templateHome/bin ;
|
62
|
+
pwd;
|
63
|
+
ls -lhrt createInstance.sh;
|
64
|
+
sh createInstance.sh -d #{instanceName} -n `expr 10000 + #{instanceNum}` -a `expr 8010 + #{instanceNum}` -h `expr 8080 + #{instanceNum}` -s `expr 8440 + #{instanceNum}` -j `expr 6900 + #{instanceNum}`;
|
65
|
+
chown tomcat:tomcat /opt/tomcat -R; chmod +x /opt/tomcat/*/bin/*
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
desc " cmd from web"
|
70
|
+
task :cmd_diy,:mas_hosts=>1 do
|
71
|
+
run %{
|
72
|
+
#{diy_cmd}
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
Capistrano::Configuration.instance(true).load do
|
2
|
+
namespace :atiiscmd do
|
3
|
+
|
4
|
+
desc "recycleApplicationPool"
|
5
|
+
task :recycleApplicationPool, :max_hosts=>1 do
|
6
|
+
run %{
|
7
|
+
cscript //Nologo "C:\\windows\\system32\\iisapp.vbs" /a #{iispool} /r
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "iis website status"
|
12
|
+
task :iis_site_status, :max_hosts=>1 do
|
13
|
+
run %{
|
14
|
+
cscript //Nologo "C:\\windows\\system32\\iisweb.vbs" /query #{iiswebsite}
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "iis website status all"
|
19
|
+
task :iis_site_status_all, :max_hosts=>1 do
|
20
|
+
run %{
|
21
|
+
cscript //Nologo "C:\\windows\\system32\\iisweb.vbs" /query
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "iis website start"
|
26
|
+
task :iis_site_start, :max_hosts=>1 do
|
27
|
+
run %{
|
28
|
+
cscript //Nologo "C:\\windows\\system32\\iisweb.vbs" /start #{iiswebsite}
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "iis website stop"
|
33
|
+
task :iis_site_stop, :max_hosts=>1 do
|
34
|
+
run %{
|
35
|
+
cscript //Nologo "C:\\windows\\system32\\iisweb.vbs" /stop #{iiswebsite}
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "iis iisreset stop"
|
40
|
+
task :iis_stop, :max_hosts=>1 do
|
41
|
+
run %{
|
42
|
+
iisreset /stop
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "iis iisreset start"
|
47
|
+
task :iis_start, :max_hosts=>1 do
|
48
|
+
run %{
|
49
|
+
iisreset /start
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "iis iisreset status"
|
54
|
+
task :iis_status, :max_hosts=>1 do
|
55
|
+
run %{
|
56
|
+
iisreset /status
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
desc "iis iisreset restart"
|
61
|
+
task :iis_restart, :max_hosts=>1 do
|
62
|
+
run %{
|
63
|
+
iisreset /restart
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
desc "iis website deploy dir"
|
68
|
+
task :iis_dp_dir_info, :max_hosts=>1 do
|
69
|
+
run " grep -nE 'ServerComment|Path' /cygdrive/c/WINDOWS/system32/inetsrv/MetaBase.xml |grep -vE 'tPath|rPath|默认|允许' "
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|