capitomcat 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +37 -0
- data/README.md +277 -0
- data/Rakefile +5 -0
- data/capitomcat.gemspec +24 -0
- data/examples/README.md +1 -0
- data/examples/multistage/Capfile +24 -0
- data/examples/multistage/README.md +1 -0
- data/examples/multistage/config/deploy/dev.rb +4 -0
- data/examples/multistage/config/deploy/prod.rb +4 -0
- data/examples/multistage/config/deploy/stg.rb +4 -0
- data/examples/multistage/config/deploy.rb +16 -0
- data/examples/multistage/template/context.xml.erb +1 -0
- data/examples/singlestage/Capfile +23 -0
- data/examples/singlestage/config/deploy.rb +16 -0
- data/examples/singlestage/template/context.xml.erb +1 -0
- data/lib/capitomcat.rb +106 -0
- metadata +89 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 05fb97e5443b9a5ed772b29b91acc43e45ebafb7
|
|
4
|
+
data.tar.gz: 7ac4dbeaaf93dfd4499cb598e9a7150a94d26c2a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 62dc7e70f831b737bf5539c381731d7b368fa32e110a69269d10142fd28353ee017156e6326ec2e10387650aa82695ddaf5f1b5ccd2fba5ec7f832a630e1805f
|
|
7
|
+
data.tar.gz: 259bc148df4060b929ca8606a902e6734aa4858cd542b03186499471f0d48743d16fe1d555bedcf5a645daf7281863a0393b8e1450c00519cb42a558304dde72
|
data/.gitignore
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# CVS Files #
|
|
2
|
+
.cvsignore
|
|
3
|
+
CVS
|
|
4
|
+
|
|
5
|
+
# Eclipse Project Files #
|
|
6
|
+
.settings
|
|
7
|
+
target
|
|
8
|
+
.classpath
|
|
9
|
+
.project
|
|
10
|
+
|
|
11
|
+
# Intellij Project Files #
|
|
12
|
+
.idea
|
|
13
|
+
*.iml
|
|
14
|
+
|
|
15
|
+
# Mac Directory #
|
|
16
|
+
.DS_Store
|
|
17
|
+
|
|
18
|
+
# Ruby
|
|
19
|
+
*.gem
|
|
20
|
+
*.rbc
|
|
21
|
+
.bundle
|
|
22
|
+
.config
|
|
23
|
+
coverage
|
|
24
|
+
InstalledFiles
|
|
25
|
+
lib/bundler/man
|
|
26
|
+
pkg
|
|
27
|
+
rdoc
|
|
28
|
+
spec/reports
|
|
29
|
+
test/tmp
|
|
30
|
+
test/version_tmp
|
|
31
|
+
tmp
|
|
32
|
+
|
|
33
|
+
# YARD artifacts
|
|
34
|
+
.yardoc
|
|
35
|
+
_yardoc
|
|
36
|
+
doc/
|
|
37
|
+
|
data/README.md
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
Capistrano Recipe for Tomcat
|
|
2
|
+
========================
|
|
3
|
+
|
|
4
|
+
##Installation
|
|
5
|
+
To use Capitomcat in your Capistrano script, you need install as RubyGem
|
|
6
|
+
|
|
7
|
+
###Install Ruby
|
|
8
|
+
Please refer to [Download Ruby](http://www.ruby-lang.org/en/downloads/) page on the Ruby official website.
|
|
9
|
+
###Install RubyGems
|
|
10
|
+
Please refer to [Download RubyGems](http://rubygems.org/pages/download) page on the RubyGems official website.
|
|
11
|
+
###Install Capistrano
|
|
12
|
+
<pre>
|
|
13
|
+
$ gem install capistrano
|
|
14
|
+
$ gem install capistrano-ext
|
|
15
|
+
</pre>
|
|
16
|
+
###Install Capitomcat
|
|
17
|
+
* Check-out the source code
|
|
18
|
+
<pre>
|
|
19
|
+
$ git clone git@github.com:sunggun-yu/capitomcat.git
|
|
20
|
+
</pre>
|
|
21
|
+
* Build gem
|
|
22
|
+
<pre>
|
|
23
|
+
$ cd capitomcat
|
|
24
|
+
$ gem build capitomcat.gemspec
|
|
25
|
+
</pre>
|
|
26
|
+
* Install gem
|
|
27
|
+
<pre>
|
|
28
|
+
$ gem install capitomcat
|
|
29
|
+
</pre>
|
|
30
|
+
|
|
31
|
+
##Configuration
|
|
32
|
+
You have to add the following options in your `Capfile` or `deploy.rb`
|
|
33
|
+
<pre>
|
|
34
|
+
role :app
|
|
35
|
+
set :user
|
|
36
|
+
set :password
|
|
37
|
+
set :tomcat_user
|
|
38
|
+
set :tomcat_cmd_user
|
|
39
|
+
set :tomcat_port
|
|
40
|
+
set :local_war_file
|
|
41
|
+
set :context_template_file
|
|
42
|
+
set :context_name`
|
|
43
|
+
set :remote_docBase
|
|
44
|
+
set :remote_context_file
|
|
45
|
+
set :remote_tomcat_cmd
|
|
46
|
+
set :remote_tomcat_work_dir
|
|
47
|
+
set :stages
|
|
48
|
+
</pre>
|
|
49
|
+
* `:app` - The application servers that you want to deploy
|
|
50
|
+
* `:user` - User name which is going to run Capistrano script.
|
|
51
|
+
* `:password` - Password of `:user`.
|
|
52
|
+
* `:tomcat_user` - The owner of Tomcat home directory.
|
|
53
|
+
* `:tomcat_cmd_user` - The user that runs tomcat scripts : ex) /etc/init.d/tomcat
|
|
54
|
+
* `:tomcat_port` - Port number of Tomcat server. this value is needed to check whether Tomcat process is running.
|
|
55
|
+
* `:local_war_file` - The WAR file which will upload to remote tomcat server.
|
|
56
|
+
* `:context_template_file` - Path for the template file in your local, which is application's Tomcat context. also, following ERB variable are should be included in the template file.
|
|
57
|
+
* context.xml.erb
|
|
58
|
+
<pre>
|
|
59
|
+
<Context path="/<%= context_name %>" docBase="<%= remote_docBase %>" />
|
|
60
|
+
</pre>
|
|
61
|
+
* `<%= context_name %>` - This variable is for the ***path*** attribute in the context file. It will be replaced to `:context_name`
|
|
62
|
+
* `<%= remote_docBase %>` - This variable is for the ***docBase*** attribute in the context file.It will be replaced to `:remote_docBase`
|
|
63
|
+
- `:context_name` - Root context name of application.
|
|
64
|
+
- `:remote_docBase` - The pathname to the web application archive file (if this web application is being executed directly from the WAR file)
|
|
65
|
+
- `:remote_context_file` - Application's context file path for Tomcat on your remote servers. basically, context file is located in `/your/tomcat/home/conf/Catalina/localhost/appname.xml`
|
|
66
|
+
- `:remote_tomcat_cmd` - Tomcat's star, stop command. for example, `/etc/init.d/tomcat` or `/your/tomcat/home/bin/catalina.sh` can be used. please make sure not to include `start` or `stop` parameter.
|
|
67
|
+
- `:remote_tomcat_work_dir` - Tomcat work directory for application. this directory will be used at `capitomcat:cleanWorkDir` task
|
|
68
|
+
|
|
69
|
+
### Multistage setting
|
|
70
|
+
If you want to use Multistage deployment, You should add following option in your `Capfile` or `deploy.rb`
|
|
71
|
+
also, please refer to [Multistage Extension](https://github.com/capistrano/capistrano/wiki/2.x-Multistage-Extension).
|
|
72
|
+
- `:stages` -
|
|
73
|
+
<pre>
|
|
74
|
+
# Application Stage Section
|
|
75
|
+
set :stages, %w(dev stg prod)
|
|
76
|
+
</pre>
|
|
77
|
+
|
|
78
|
+
### Examples
|
|
79
|
+
#### Single Stage
|
|
80
|
+
/your/capistrano/project/***Capfile***
|
|
81
|
+
```
|
|
82
|
+
require 'capitomcat'
|
|
83
|
+
|
|
84
|
+
# Application host section
|
|
85
|
+
role :app, "dev01", "dev02"
|
|
86
|
+
|
|
87
|
+
# User section
|
|
88
|
+
set :user, "stg"
|
|
89
|
+
set :password, "password"
|
|
90
|
+
set :tomcat_user, "tomcat"
|
|
91
|
+
set :tomcat_cmd_user, "root"
|
|
92
|
+
|
|
93
|
+
# Local file section
|
|
94
|
+
set :local_war_file, "/tmp/app.war"
|
|
95
|
+
set :context_template_file, "./template/context.xml.erb"
|
|
96
|
+
|
|
97
|
+
# Remote setting section
|
|
98
|
+
set :context_name, "app"
|
|
99
|
+
set :remote_docBase, "/tmp/test/earl/war/abc.war"
|
|
100
|
+
set :remote_context_file, "/tmp/test/tomcat/conf/Catalina/localhost/app.xml"
|
|
101
|
+
set :remote_tomcat_cmd, "/tmp/test/etc/init.d/tomcat7"
|
|
102
|
+
set :remote_tomcat_work_dir, "/opt/tomcat/work/Catalina/localhost/app"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
#### Multi Stage
|
|
106
|
+
Project structure.
|
|
107
|
+
```
|
|
108
|
+
/ your/capistrano/project/
|
|
109
|
+
|-- config
|
|
110
|
+
| |-- deploy
|
|
111
|
+
| | |-- dev.rb
|
|
112
|
+
| | |-- stg.rb
|
|
113
|
+
| | `-- prod.rb
|
|
114
|
+
| `-- deploy.rb
|
|
115
|
+
`-- Capfile
|
|
116
|
+
```
|
|
117
|
+
Also, the file name under config/deploy are should be matched in `set :stages`
|
|
118
|
+
|
|
119
|
+
* /your/capistrano/project/***Capfile***
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
require 'capitomcat'
|
|
123
|
+
require 'capistrano/ext/multistage'
|
|
124
|
+
|
|
125
|
+
# Application Stage Section
|
|
126
|
+
set :stages, %w(dev stg prod)
|
|
127
|
+
|
|
128
|
+
# User section
|
|
129
|
+
set :user, "stg"
|
|
130
|
+
set :password, "password"
|
|
131
|
+
set :tomcat_user, "tomcat"
|
|
132
|
+
set :tomcat_cmd_user, "root"
|
|
133
|
+
|
|
134
|
+
# Local file section
|
|
135
|
+
set :local_war_file, "/tmp/app.war"
|
|
136
|
+
set :context_template_file, "./template/context.xml.erb"
|
|
137
|
+
|
|
138
|
+
# Remote setting section
|
|
139
|
+
set :context_name, "app"
|
|
140
|
+
set :remote_docBase, "/tmp/test/earl/war/abc.war"
|
|
141
|
+
set :remote_context_file, "/tmp/test/tomcat/conf/Catalina/localhost/app.xml"
|
|
142
|
+
set :remote_tomcat_cmd, "/tmp/test/etc/init.d/tomcat7"
|
|
143
|
+
set :remote_tomcat_work_dir, "/opt/tomcat/work/Catalina/localhost/app"
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
* /your/capistrano/project/***config/deploy/dev.rb***
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
# Application host section for DEV
|
|
150
|
+
role :app, "dev-host-1", "dev-host-2"
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
* /your/capistrano/project/***config/deploy/stg.rb***
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
# Application host section for stg
|
|
157
|
+
role :app, "stg-host-1", "stg-host-2"
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
* /your/capistrano/project/***config/deploy/prod.rb***
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
# Application host section for Production
|
|
164
|
+
role :app, "prod-host-1", "prod-host-2"
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
##Available Tasks
|
|
168
|
+
To get a list of all capistrano tasks, run `cap -T` with user password:
|
|
169
|
+
<pre>
|
|
170
|
+
cap capitomcat:cleanWorkDir # Cleaning-up Tomcat work directory
|
|
171
|
+
cap capitomcat:start # Start capitomcat.
|
|
172
|
+
cap capitomcat:stop # Stop capitomcat.
|
|
173
|
+
cap capitomcat:updateContext # Update and upload context file
|
|
174
|
+
cap capitomcat:uploadWar # Upload WAR file
|
|
175
|
+
</pre>
|
|
176
|
+
|
|
177
|
+
### capitomcat:cleanWorkDir
|
|
178
|
+
This Task will remove Application's Tomcat work directory. Please make sure you should start/restart Tomcat after this task has executed.
|
|
179
|
+
### capitomcat:start
|
|
180
|
+
This Task will start your Tomcat server using `:remote_tomcat_cmd` command.
|
|
181
|
+
If you have `set :remote_tomcat_cmd, '/etc/init.d/tomcat7'` and `set :tomcat_cmd_user, 'root'` in your Capfile or deploy.rb file then the Task will execute `sudo -p <:password> -u root /etc/init.d/tomcat7 start` commnad on your remote servers which are setted in `role :app`.
|
|
182
|
+
### capitomcat:stop
|
|
183
|
+
This Task will stop your Tomcat server using `:remote_tomcat_cmd` command.
|
|
184
|
+
If you have `set :remote_tomcat_cmd, '/user/local/tomcat7/bin/catalina.sh'` and `set :tomcat_cmd_user, 'tomcat'` in your Capfile or deploy.rb file then the Task will execute `sudo -p <:password> -u tomcat /user/local/tomcat7/bin/catalina.sh stop` commnad on your remote servers which are setted in `role :app`.
|
|
185
|
+
### capitomcat:updateContext
|
|
186
|
+
This Task will generate context file from your context template file. and Upload the generated context file to `:remote_context_file`
|
|
187
|
+
### capitomcat:uploadWar
|
|
188
|
+
This Task will upload the `:local_war_file` to `:remote_docBase`
|
|
189
|
+
|
|
190
|
+
##Usage
|
|
191
|
+
To use capitomcat gem, You need to create your own Capistrano script.
|
|
192
|
+
You can create Capistrano project structure and default files from scratch to run `capify .`
|
|
193
|
+
```
|
|
194
|
+
$ mkdir -p /your/capistrano/project
|
|
195
|
+
$ cd /your/capistrano/project
|
|
196
|
+
$ capify .
|
|
197
|
+
$ tree
|
|
198
|
+
|
|
199
|
+
/ your/capistrano/project/
|
|
200
|
+
|-- config
|
|
201
|
+
| `-- deploy.rb
|
|
202
|
+
`-- Capfile
|
|
203
|
+
```
|
|
204
|
+
add settings into your Capfile or deploy.rb file. and you can execute capitomcat recipe like this.
|
|
205
|
+
```
|
|
206
|
+
$ cap capitomcat:stop
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Also, you can combine tasks as a one task by creating new task inside the your Capfile or deploy.rb file.
|
|
210
|
+
```
|
|
211
|
+
require 'capitomcat'
|
|
212
|
+
|
|
213
|
+
desc "Release Task for myjob"
|
|
214
|
+
namespace :myapp do
|
|
215
|
+
task :release, :roles => :app do
|
|
216
|
+
capitomcat.stop
|
|
217
|
+
capitomcat.uploadWar
|
|
218
|
+
capitomcat.updateContext
|
|
219
|
+
capitomcat.cleanWorkDir
|
|
220
|
+
capitomcat.start
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Execute tasks serially
|
|
226
|
+
Capistrano performs the task parallel, So in the above case, if you have multiple server each task will be performed for each servers.
|
|
227
|
+
```
|
|
228
|
+
# host1, host2
|
|
229
|
+
|
|
230
|
+
stop ==> host1
|
|
231
|
+
stop ==> host2
|
|
232
|
+
|
|
233
|
+
uploadWar ==> host1
|
|
234
|
+
uploadWar ==> host2
|
|
235
|
+
|
|
236
|
+
...
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
if you do perform release like below, use serial_task function.
|
|
240
|
+
```
|
|
241
|
+
# host1, host2
|
|
242
|
+
|
|
243
|
+
stop ==> host1
|
|
244
|
+
uploadWar ==> host1
|
|
245
|
+
updateContext ==> host1
|
|
246
|
+
start ==> host1
|
|
247
|
+
|
|
248
|
+
stop ==> host2
|
|
249
|
+
uploadWar ==> host2
|
|
250
|
+
updateContext ==> host2
|
|
251
|
+
start ==> host2
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
```
|
|
255
|
+
require 'capitomcat'
|
|
256
|
+
|
|
257
|
+
desc "Release Task for myjob"
|
|
258
|
+
namespace :myapp do
|
|
259
|
+
task :release, :roles => :app do
|
|
260
|
+
serial_task do
|
|
261
|
+
capitomcat.stop
|
|
262
|
+
capitomcat.uploadWar
|
|
263
|
+
capitomcat.updateContext
|
|
264
|
+
capitomcat.cleanWorkDir
|
|
265
|
+
capitomcat.start
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Perform multistage task
|
|
272
|
+
If you have multistage setting, you can perform the task as like below.
|
|
273
|
+
```
|
|
274
|
+
cap prod myapp:release
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
♥For more details, please refer to example projects.♥
|
data/Rakefile
ADDED
data/capitomcat.gemspec
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
# Author:: Sunggun Yu
|
|
4
|
+
|
|
5
|
+
$:.push File.expand_path("lib", __FILE__)
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |s|
|
|
8
|
+
s.name = "capitomcat"
|
|
9
|
+
s.version = "0.0.2"
|
|
10
|
+
|
|
11
|
+
s.authors = ["Sunggun Yu"]
|
|
12
|
+
s.email = ["sunggun.dev@gmail.com"]
|
|
13
|
+
s.licenses = ['Apache 2.0']
|
|
14
|
+
s.date = %q{2013-12-27}
|
|
15
|
+
s.homepage = "https://github.com/sunggun-yu/capitomcat"
|
|
16
|
+
s.summary = %q{Capistrano Recipe for Tomcat}
|
|
17
|
+
s.description = %q{You can deploy your war file to multiple remote tomcat servers through this Capistrano recipe.}
|
|
18
|
+
|
|
19
|
+
s.files = `git ls-files`.split("\n")
|
|
20
|
+
s.require_paths = ["lib"]
|
|
21
|
+
|
|
22
|
+
s.add_dependency('capistrano')
|
|
23
|
+
s.add_development_dependency('rake')
|
|
24
|
+
end
|
data/examples/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Sample project for single stage deployment
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Author:: Sunggun Yu
|
|
2
|
+
|
|
3
|
+
require 'capistrano/ext/multistage'
|
|
4
|
+
load 'config/deploy.rb'
|
|
5
|
+
|
|
6
|
+
# Application Stage Section
|
|
7
|
+
set :stages, %w(dev stg prod)
|
|
8
|
+
|
|
9
|
+
# User section
|
|
10
|
+
set :user, "deploy"
|
|
11
|
+
set :password, "#{password}" #Set password from parameter.
|
|
12
|
+
set :tomcat_user, "tomcat"
|
|
13
|
+
set :tomcat_cmd_user, "root"
|
|
14
|
+
|
|
15
|
+
# Local file section
|
|
16
|
+
set :local_war_file, "/tmp/app.war"
|
|
17
|
+
set :context_template_file, "./template/context.xml.erb"
|
|
18
|
+
|
|
19
|
+
# Remote setting section
|
|
20
|
+
set :context_name, "app"
|
|
21
|
+
set :remote_docBase, "/tmp/test/earl/war/abc.war"
|
|
22
|
+
set :remote_context_file, "/tmp/test/tomcat/conf/Catalina/localhost/app.xml"
|
|
23
|
+
set :remote_tomcat_cmd, "/tmp/test/etc/init.d/tomcat7"
|
|
24
|
+
set :remote_tomcat_work_dir, "/opt/tomcat/work/Catalina/localhost/app"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Sample project for multi stage deployment
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Author:: Sunggun Yu
|
|
2
|
+
|
|
3
|
+
require 'capitomcat'
|
|
4
|
+
|
|
5
|
+
desc "Release Task for myjob"
|
|
6
|
+
namespace :myapp do
|
|
7
|
+
task :release, :roles => :app do
|
|
8
|
+
serial_task do
|
|
9
|
+
capitomcat.uploadWar
|
|
10
|
+
capitomcat.stop
|
|
11
|
+
capitomcat.updateContext
|
|
12
|
+
capitomcat.cleanWorkDir
|
|
13
|
+
capitomcat.start
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<Context path="/<%= context_name %>" docBase="<%= remote_docBase %>" />
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Author:: Sunggun Yu
|
|
2
|
+
|
|
3
|
+
load 'config/deploy.rb'
|
|
4
|
+
|
|
5
|
+
# Application host section for DEV
|
|
6
|
+
role :app, "dev01"
|
|
7
|
+
|
|
8
|
+
# User section
|
|
9
|
+
set :user, "deploy"
|
|
10
|
+
set :password, "#{password}" #Set password from parameter.
|
|
11
|
+
set :tomcat_user, "tomcat"
|
|
12
|
+
set :tomcat_cmd_user, "root"
|
|
13
|
+
|
|
14
|
+
# Local file section
|
|
15
|
+
set :local_war_file, "/tmp/app.war"
|
|
16
|
+
set :context_template_file, "./template/context.xml.erb"
|
|
17
|
+
|
|
18
|
+
# Remote setting section
|
|
19
|
+
set :context_name, "app"
|
|
20
|
+
set :remote_docBase, "/tmp/test/earl/war/abc.war"
|
|
21
|
+
set :remote_context_file, "/tmp/test/tomcat/conf/Catalina/localhost/app.xml"
|
|
22
|
+
set :remote_tomcat_cmd, "/tmp/test/etc/init.d/tomcat7"
|
|
23
|
+
set :remote_tomcat_work_dir, "/opt/tomcat/work/Catalina/localhost/app"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Author:: Sunggun Yu
|
|
2
|
+
|
|
3
|
+
require 'capitomcat'
|
|
4
|
+
|
|
5
|
+
desc "Release Task for myjob"
|
|
6
|
+
namespace :myapp do
|
|
7
|
+
task :release, :roles => :app do
|
|
8
|
+
serial_task do
|
|
9
|
+
capitomcat.uploadWar
|
|
10
|
+
capitomcat.stop
|
|
11
|
+
capitomcat.updateContext
|
|
12
|
+
capitomcat.cleanWorkDir
|
|
13
|
+
capitomcat.start
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<Context path="/<%= context_name %>" docBase="<%= remote_docBase %>" />
|
data/lib/capitomcat.rb
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Author:: Sunggun Yu
|
|
2
|
+
|
|
3
|
+
configuration = Capistrano::Configuration.respond_to?(:instance) ?
|
|
4
|
+
Capistrano::Configuration.instance(:must_exist) :
|
|
5
|
+
Capistrano.configuration(:must_exist)
|
|
6
|
+
|
|
7
|
+
configuration.load do
|
|
8
|
+
|
|
9
|
+
default_run_options[:pty] = true
|
|
10
|
+
default_run_options[:shell] = '/bin/sh'
|
|
11
|
+
|
|
12
|
+
set :tmp_dir, "/tmp"
|
|
13
|
+
|
|
14
|
+
desc "Capistrano Recipe for Tomcat"
|
|
15
|
+
namespace :capitomcat do
|
|
16
|
+
desc "Stop Tomcat"
|
|
17
|
+
task :stop, :roles => :app do
|
|
18
|
+
run "#{sudo :as => tomcat_cmd_user} #{remote_tomcat_cmd} stop", :pty => true
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
desc "Start Tomcat"
|
|
22
|
+
task :start, :roles => :app do
|
|
23
|
+
run "echo `nohup #{sudo :as => tomcat_cmd_user} #{remote_tomcat_cmd} start&` && sleep 1", :pty => true
|
|
24
|
+
run("for i in {0..360}; do echo \"Waiting for Tomcat to start\"; if [[ \"\" != \"$\(netstat -an | grep #{tomcat_port}\)\" ]]; then break; fi; sleep 30; done")
|
|
25
|
+
run("netstat -an | grep #{tomcat_port}")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
desc "Upload WAR file"
|
|
29
|
+
task :uploadWar, :roles => :app do
|
|
30
|
+
set(:war_file_name) { File.basename(remote_docBase) }
|
|
31
|
+
set :tmp_war_file, "#{tmp_dir}/#{war_file_name}"
|
|
32
|
+
# Clean remote file before upload
|
|
33
|
+
remove_file_if_exist('root', tmp_war_file)
|
|
34
|
+
# Upload WAR file to temp dir
|
|
35
|
+
upload(local_war_file, tmp_war_file, :via => :scp, :pty => true)
|
|
36
|
+
begin
|
|
37
|
+
# Change uploaded WAR file's owner
|
|
38
|
+
run "#{sudo :as => 'root'} chown #{tomcat_user}:#{tomcat_user} #{tmp_war_file}"
|
|
39
|
+
# Move tmp WAR fiel to actual path
|
|
40
|
+
run "#{sudo :as => tomcat_user} cp #{tmp_war_file} #{remote_docBase}", :mode => 0644
|
|
41
|
+
# Clean remote file after task finished
|
|
42
|
+
remove_file_if_exist('root', tmp_war_file)
|
|
43
|
+
rescue
|
|
44
|
+
run "#{sudo :as => 'root'} rm #{tmp_war_file}"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
desc "Update and upload context file"
|
|
49
|
+
task :updateContext, :roles => :app do
|
|
50
|
+
set(:context_file_name) { File.basename(remote_context_file) }
|
|
51
|
+
set :tmp_context_file, "#{tmp_dir}/#{context_file_name}"
|
|
52
|
+
# Clean remote file before upload
|
|
53
|
+
remove_file_if_exist('root', tmp_context_file)
|
|
54
|
+
# Generate context file from template and upload to temp dir on the remote server
|
|
55
|
+
generate_config(context_template_file, tmp_context_file)
|
|
56
|
+
begin
|
|
57
|
+
# Change uploaded context file's owner
|
|
58
|
+
run "#{sudo :as => 'root'} chown #{tomcat_user}:#{tomcat_user} #{tmp_context_file}"
|
|
59
|
+
# Move tmp WAR fiel to actual path
|
|
60
|
+
run "#{sudo :as => tomcat_user} cp #{tmp_context_file} #{remote_context_file}", :mode => 0644
|
|
61
|
+
# Clean remote file after task finished
|
|
62
|
+
remove_file_if_exist('root', tmp_context_file)
|
|
63
|
+
rescue
|
|
64
|
+
run "#{sudo :as => 'root'} rm #{tmp_context_file}"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
desc "Cleaning-up Tomcat work directory"
|
|
69
|
+
task :cleanWorkDir, :roles => :app do
|
|
70
|
+
set :remote_tomcat_work_dir, "#{remote_tomcat_work_dir}"
|
|
71
|
+
run "#{sudo :as => tomcat_user} rm -rf #{remote_tomcat_work_dir}"
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Copy context.xml template to remote server
|
|
76
|
+
def parse_config(file)
|
|
77
|
+
require 'erb'
|
|
78
|
+
template=File.read(file)
|
|
79
|
+
return ERB.new(template).result(binding)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Generate config file from erb template
|
|
83
|
+
def generate_config(local_file,remote_file)
|
|
84
|
+
temp_file = '/tmp/' + File.basename(local_file)
|
|
85
|
+
buffer = parse_config(local_file)
|
|
86
|
+
File.open(temp_file, 'w+') { |f| f << buffer }
|
|
87
|
+
upload temp_file, remote_file, :via => :scp
|
|
88
|
+
`rm #{temp_file}`
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Remove file if exist
|
|
92
|
+
def remove_file_if_exist exc_user, file
|
|
93
|
+
run "if [ -e #{file} ]; then #{sudo :as => exc_user} rm -f #{file}; fi"
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Excute multiple task by serial
|
|
98
|
+
def serial_task(&block)
|
|
99
|
+
original = ENV['HOSTS']
|
|
100
|
+
find_servers_for_task(self.current_task).each do |server|
|
|
101
|
+
ENV['HOSTS'] = server.host
|
|
102
|
+
yield
|
|
103
|
+
end
|
|
104
|
+
ensure
|
|
105
|
+
ENV['HOSTS'] = original
|
|
106
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: capitomcat
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Sunggun Yu
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2013-12-27 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: capistrano
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - '>='
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - '>='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
description: You can deploy your war file to multiple remote tomcat servers through
|
|
42
|
+
this Capistrano recipe.
|
|
43
|
+
email:
|
|
44
|
+
- sunggun.dev@gmail.com
|
|
45
|
+
executables: []
|
|
46
|
+
extensions: []
|
|
47
|
+
extra_rdoc_files: []
|
|
48
|
+
files:
|
|
49
|
+
- .gitignore
|
|
50
|
+
- README.md
|
|
51
|
+
- Rakefile
|
|
52
|
+
- capitomcat.gemspec
|
|
53
|
+
- examples/README.md
|
|
54
|
+
- examples/multistage/Capfile
|
|
55
|
+
- examples/multistage/README.md
|
|
56
|
+
- examples/multistage/config/deploy.rb
|
|
57
|
+
- examples/multistage/config/deploy/dev.rb
|
|
58
|
+
- examples/multistage/config/deploy/prod.rb
|
|
59
|
+
- examples/multistage/config/deploy/stg.rb
|
|
60
|
+
- examples/multistage/template/context.xml.erb
|
|
61
|
+
- examples/singlestage/Capfile
|
|
62
|
+
- examples/singlestage/config/deploy.rb
|
|
63
|
+
- examples/singlestage/template/context.xml.erb
|
|
64
|
+
- lib/capitomcat.rb
|
|
65
|
+
homepage: https://github.com/sunggun-yu/capitomcat
|
|
66
|
+
licenses:
|
|
67
|
+
- Apache 2.0
|
|
68
|
+
metadata: {}
|
|
69
|
+
post_install_message:
|
|
70
|
+
rdoc_options: []
|
|
71
|
+
require_paths:
|
|
72
|
+
- lib
|
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
74
|
+
requirements:
|
|
75
|
+
- - '>='
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '0'
|
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - '>='
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
requirements: []
|
|
84
|
+
rubyforge_project:
|
|
85
|
+
rubygems_version: 2.0.3
|
|
86
|
+
signing_key:
|
|
87
|
+
specification_version: 4
|
|
88
|
+
summary: Capistrano Recipe for Tomcat
|
|
89
|
+
test_files: []
|