capitomcat 1.1.0 → 1.1.1

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  SHA1:
3
3
  metadata.gz: !binary |-
4
- YTQ2ZTRhNGVmMTMxMGRhZjNiNjcyOWU3MGU3YWJlOGFjYjAyYWQzMQ==
4
+ MzJkY2Q4NjZjYmQ4OTJhMzQ5OGZjNTg3OWQwZWVjNTFlMTJhOTBhOA==
5
5
  data.tar.gz: !binary |-
6
- ZThmODg3M2E4YzBhNTIzMjQ3OWNjNWVmNTBiOTIyNGEyOGY5YzA0Mg==
6
+ MDgzODQ5ZjA1YzIxM2M3MmE4NWY3ZmNkZTEyOGYyNjc4OGE0YjliNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDFkM2Q5NGMxYTRlOTk0NTlkZDc5ZTNmMmNiNDhlNjk4MTEyZGQ0NjU4ZDYy
10
- YjM2ZGNjMzBkMjBlZjQxNzU4YWUzZTJhNzliNTgyOGIyODA0MjVkOGYxYWFh
11
- YzVhZmJiYmUwYjhlNWFkMjI2YjMyNzA1ZGZiOWU5NGYwZmE5NzY=
9
+ OTAzYzRiOTg4M2E5OTU0MjdlOWFiODk3NDI4M2MwM2FhOTkxNzAxYmFjN2Qx
10
+ MzQxMGFhNmYwOWRiYzQwYTY5N2RkYzBhYWJiYWQwMjdjN2ZmM2Y3MzE5YTRj
11
+ NzljNjg4NmQxMzE2ODdjNWI5MjZjODI1MWIzZWFlZmFkYjM2YTE=
12
12
  data.tar.gz: !binary |-
13
- NWY5Y2U4NTA4MGY4YjhiMGNiYzVkMWU3NDE0OGRkNWUxMzU5MDcwMjRmYTA3
14
- NjlmYzM1OTQwYTRkOWExNzU0NjI5YTU4ZmQ3MzMxNTFkMjgxOTg4NWI1Mzlh
15
- ZjhiMDUzNDljNDFjYThmMDkwMzI4ZjA5YzkxOTYxMzlhZGNiYzE=
13
+ NTY3MWY1ZjFkZGQ2YTM3ODVlNDhmMWEwMDY1MDE3MzE2Mjg3MGY5MjhjMGQ4
14
+ NzhmZDljZWM2M2VjYzg2OTY2ZGQzYTYxZjk5MjkwOTVkZmIwYjA2YjFmOWFk
15
+ YzFkZjUxN2FlMTFkYWE0MDM2ZTg2ZGZhOTljNjZkOTYxNDU4Mjg=
data/CHANGES.md ADDED
@@ -0,0 +1,25 @@
1
+ # Changes
2
+ [1.1.1]: https://github.com/sunggun-yu/capitomcat/releases/tag/v1.1.1
3
+ [1.1.0]: https://github.com/sunggun-yu/capitomcat/releases/tag/v1.1.0
4
+ [1.0.1]: https://github.com/sunggun-yu/capitomcat/releases/tag/v1.0.1
5
+ [1.0.0]: https://github.com/sunggun-yu/capitomcat/releases/tag/v1.0.0
6
+ [0.0.3]: https://github.com/sunggun-yu/capitomcat/releases/tag/v0.0.3
7
+
8
+ ## [v1.1.1][1.1.1]
9
+ * File uploading strategy changing.
10
+ * Modifying tomcat starting check script.
11
+ * Adding tomcat stopping check script.
12
+
13
+ ## [v1.1.0][1.1.0]
14
+ * Update Capistrano dependency to v3.1.0
15
+ * Raise an exception instead of using exit command when local war file or context.xml template file does not exist.
16
+ * The example for 'native' has changed because Capistrano do not allow load_imports in Capistrano class since they update to v3.1.0
17
+
18
+ ## [v1.0.1][1.0.1]
19
+ * Remove Unnecessary dependency
20
+
21
+ ## [v1.0.0][1.0.0]
22
+ * Support Capistrano 3
23
+
24
+ ## [v0.0.3][0.0.3]
25
+ * Support Capistrano 2
data/README.md CHANGED
@@ -4,29 +4,10 @@
4
4
  Capitomcat is library for creating Capistrano Tomcat recipe.
5
5
  Capitomcat includes basic tasks for Tomcat deployment. You can create easily your own Capistrano 3 recipe for Tomcat with Capitomcat.
6
6
 
7
- ## Changes
8
- [1.1.0]: https://github.com/sunggun-yu/capitomcat/releases/tag/v1.1.0
9
- [1.0.1]: https://github.com/sunggun-yu/capitomcat/releases/tag/v1.0.1
10
- [1.0.0]: https://github.com/sunggun-yu/capitomcat/releases/tag/v1.0.0
11
- [0.0.3]: https://github.com/sunggun-yu/capitomcat/releases/tag/v0.0.3
12
- ### [v1.1.0][1.1.0]
13
- * Update Capistrano dependency to v3.1.0
14
- * Raise an exception instead of using exit command when local war file or context.xml template file does not exist.
15
- * The example for 'native' has changed because Capistrano do not allow load_imports in Capistrano class since they update to v3.1.0
16
-
17
- ### [v1.0.1][1.0.1]
18
- * Remove Unnecessary dependency
19
-
20
- ### [v1.0.0][1.0.0]
21
- * Support Capistrano 3
22
-
23
- ### [v0.0.3][0.0.3]
24
- * Support Capistrano 2
25
-
26
7
  ##See Also
27
8
  ### Capitomcat Jenkins Plugin
28
9
  * Home page : https://wiki.jenkins-ci.org/display/JENKINS/Capitomcat+Plugin
29
- * Source : https://github.com/jenkinsci/capitomcat-plugin
10
+ * Source Repo: https://github.com/jenkinsci/capitomcat-plugin
30
11
 
31
12
  ##Requirement
32
13
  ###Gem Dependency
@@ -1,4 +1,5 @@
1
1
  require 'capistrano'
2
+ require 'sshkit/backends/netssh'
2
3
 
3
4
  # Author:: Sunggun Yu
4
5
 
@@ -37,6 +38,7 @@ namespace :capitomcat do
37
38
 
38
39
  info 'Stop Tomcat'
39
40
  stop_tomcat
41
+ check_tomcat_stopped
40
42
 
41
43
  info 'Update Context'
42
44
  upload_context_file
@@ -50,6 +52,7 @@ namespace :capitomcat do
50
52
  else
51
53
  info 'Stop Tomcat'
52
54
  stop_tomcat
55
+ check_tomcat_stopped
53
56
 
54
57
  info 'Upload WAR file'
55
58
  upload_war_file
@@ -68,25 +71,47 @@ namespace :capitomcat do
68
71
  def start_tomcat
69
72
  # local variables
70
73
  tomcat_cmd = fetch(:tomcat_cmd)
71
-
72
- puts capture(:sudo, get_sudo_user_tomcat_cmd, "#{tomcat_cmd} start")
74
+ execute(:sudo, get_sudo_user_tomcat_cmd, "#{tomcat_cmd} start")
73
75
  end
74
76
 
75
- # Check status whether started
77
+ # Check status whether Tomcat started
76
78
  def check_tomcat_started
77
79
  # local variables
78
80
  tomcat_port = fetch(:tomcat_port)
81
+ _times = 0
82
+ begin
83
+ _times = _times + 1
84
+ info("Check and wait until Tomcat starting up ... #{_times}")
85
+ _netstat = capture("netstat -an | grep \"#{tomcat_port}\" | grep \"LISTEN\" ; echo \"\"")
86
+ info (_netstat)
87
+ sleep(1)
88
+ end until _times > 180 || (_netstat != nil && _netstat.to_s.length > 1)
89
+ if _times > 180
90
+ raise 'Starting Tomcat has failed - timed out'
91
+ end
92
+ end
79
93
 
80
- execute "for i in {0..180}; do echo \"Waiting for Tomcat to start\"; if [ \"\" != \"$(netstat -an | grep #{tomcat_port})\" ]; then break; fi; sleep 30; done"
81
- puts capture("netstat -an | grep #{tomcat_port}")
94
+ # Check status whether Tomcat stopped
95
+ def check_tomcat_stopped
96
+ # local variables
97
+ tomcat_port = fetch(:tomcat_port)
98
+ _times = 0
99
+ begin
100
+ _times = _times + 1
101
+ info("Check and wait until Tomcat stopping ... #{_times}")
102
+ _netstat = capture("netstat -an | grep \"#{tomcat_port}\" | grep \"LISTEN\" ; echo \"\"")
103
+ sleep(1)
104
+ end until _times > 180 || _netstat == nil || _netstat.to_s.length == 0
105
+ if _times > 180
106
+ raise 'Stopping Tomcat has failed - timed out'
107
+ end
82
108
  end
83
109
 
84
110
  # Stop Tomcat server
85
111
  def stop_tomcat
86
112
  # local variables
87
113
  tomcat_cmd = fetch(:tomcat_cmd)
88
-
89
- puts capture(:sudo, get_sudo_user_tomcat_cmd, "#{tomcat_cmd} stop")
114
+ execute(:sudo, get_sudo_user_tomcat_cmd, "#{tomcat_cmd} stop")
90
115
  end
91
116
 
92
117
  # Upload the WAR file
@@ -96,20 +121,19 @@ namespace :capitomcat do
96
121
  local_war_file = fetch(:local_war_file)
97
122
  tomcat_war_file = fetch(:tomcat_war_file)
98
123
  tomcat_user = fetch(:tomcat_user)
99
- tomcat_user_group = fetch(:tomcat_user_group)
100
124
 
101
125
  if File.exists?(local_war_file)
102
126
  # Setup file name
103
127
  temp_dir = Pathname.new('/tmp')
104
128
  temp_file = File.basename(tomcat_war_file)
105
129
  tmp_war_file = temp_dir.join(temp_file)
106
-
130
+ tmp_war_file = timestamp_filename(tmp_war_file)
107
131
  # Clean remote file before uploading
108
132
  remove_file_if_exist(upload_user, tmp_war_file)
109
133
  # Upload WAR file into temp dir
110
134
  upload! local_war_file, tmp_war_file
111
135
  # Move tmp WAR file to actual path
112
- change_owner_and_move(tmp_war_file, tomcat_war_file, tomcat_user, tomcat_user_group)
136
+ clean_after_copy(tmp_war_file, tomcat_war_file, tomcat_user)
113
137
  else
114
138
  raise("Local WAR file does not existing. : #{local_war_file}")
115
139
  end
@@ -140,14 +164,14 @@ namespace :capitomcat do
140
164
  upload_user = fetch(:user)
141
165
  tomcat_context_file = fetch(:tomcat_context_file)
142
166
  tomcat_user = fetch(:tomcat_user)
143
- tomcat_user_group = fetch(:tomcat_user_group)
144
167
  context_template = get_context_template
145
168
 
146
169
  temp_upload_file = '/tmp/' + File.basename(tomcat_context_file)
170
+ temp_upload_file = timestamp_filename(temp_upload_file)
147
171
  remove_file_if_exist upload_user, temp_upload_file
148
172
  contents = StringIO.new(context_template)
149
173
  upload! contents, temp_upload_file
150
- change_owner_and_move(temp_upload_file, tomcat_context_file, tomcat_user, tomcat_user_group)
174
+ clean_after_copy(temp_upload_file, tomcat_context_file, tomcat_user)
151
175
  end
152
176
 
153
177
  # Clean-up work directory
@@ -185,29 +209,29 @@ namespace :capitomcat do
185
209
  end
186
210
  end
187
211
 
188
- # Change owner and move file
189
- # @param [String] file
190
- # @param [String] destination file name with its path
191
- # @param [String] user
192
- # @param [String] group
193
- def change_owner_and_move (file, destination, user, group)
194
- # Change file's owner
195
- puts user
196
- execute :sudo, :chown, "#{user}:#{group}", file
212
+ # Copy the file and remove after copy
213
+ def clean_after_copy (file, destination, sudo_user)
214
+ # Change permission
215
+ execute :chmod, '666', file
197
216
 
198
- # Move file to destination
217
+ # Copy file to destination
199
218
  target_dir = File.dirname(destination)
200
219
  if test "[ -d #{target_dir} ]"
201
220
  within target_dir do
202
- execute :sudo, '-u', user, :mv, '-f', file, destination
221
+ execute :sudo, '-u', sudo_user, :cp, file, destination
203
222
  end
204
223
  else
205
224
  warn("Target directory is not existing. Capitomcat will try mkdir for target directory. : #{target_dir}")
206
- execute :sudo, '-u', user, :mkdir, '-p', target_dir
225
+ execute :sudo, '-u', sudo_user, :mkdir, '-p', target_dir
207
226
  within(target_dir) do
208
- execute :sudo, '-u', user, :mv, '-f', file, destination
227
+ execute :sudo, '-u', sudo_user, :cp, file, destination
209
228
  end
210
229
  end
230
+ if test "[ -e #{file} ]"
231
+ execute :rm, '-f', file
232
+ else
233
+ warn('File to remove is not existing.')
234
+ end
211
235
  end
212
236
 
213
237
  # Remove file if exist
@@ -221,4 +245,13 @@ namespace :capitomcat do
221
245
  warn('Target file to remove is not existing.')
222
246
  end
223
247
  end
248
+
249
+ # Add timestamp to filename
250
+ def timestamp_filename(file)
251
+ dir = File.dirname(file)
252
+ base = File.basename(file, '.*')
253
+ time = Time.now.to_i
254
+ ext = File.extname(file)
255
+ File.join(dir, "#{base}-#{time}#{ext}")
256
+ end
224
257
  end
@@ -1,3 +1,3 @@
1
1
  module Capitomcat
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capitomcat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sunggun Yu
@@ -32,6 +32,7 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - ".gitignore"
35
+ - CHANGES.md
35
36
  - Gemfile
36
37
  - LICENSE.md
37
38
  - README.md