thundercat 0.0.6 → 0.0.7

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.
data/README.md CHANGED
@@ -4,6 +4,7 @@ ThunderCat is a ruby application container for Rack based applications. It is ve
4
4
  There is a web admin panel which lets you upload a .rap archive and also see which webapps are running and start/stop/remove them.
5
5
 
6
6
  [![Build Status](https://travis-ci.org/masterthought/thundercat.png?branch=master)](https://travis-ci.org/masterthought/thundercat)
7
+ [![thundercat Downloads](http://www.gemetric.me/images/thundercat.gif)](https://rubygems.org/gems/thundercat)
7
8
 
8
9
  ## Background
9
10
 
@@ -21,6 +21,8 @@ else
21
21
  FileUtils.mkpath("#{target_dir}/webapps")
22
22
  FileUtils.mkpath("#{target_dir}/log")
23
23
  FileUtils.mkpath("#{target_dir}/archive")
24
+ FileUtils.mkpath("#{target_dir}/standalone")
25
+ FileUtils.mkpath("#{target_dir}/standalone_archive")
24
26
  FileUtils.cp(rap, "#{target_dir}/webapps")
25
27
  FileUtils.cp(monitor, target_dir)
26
28
  FileUtils.cp(start_script, target_dir)
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+
4
+ name = ARGV[0]
5
+
6
+ if name.nil? or name.empty?
7
+ puts '[ThunderCat] Error you must supply a target directory containing an existing thundercat installation'
8
+ else
9
+
10
+ begin
11
+ target_dir = "#{name}"
12
+
13
+ rap_file = File.open(target_dir + '/webapps/thundercat/rap.yml')
14
+ existing_version = YAML::load(rap_file)[:version]
15
+
16
+ if existing_version < "0.0.256"
17
+ # create standalone and standalone_archive directories
18
+ FileUtils.mkpath("#{target_dir}/standalone") unless File.exists?("#{target_dir}/standalone")
19
+ FileUtils.mkpath("#{target_dir}/standalone_archive") unless File.exists?("#{target_dir}/standalone_archive")
20
+ rap = File.dirname(File.expand_path(__FILE__)) + '/../src/rap/thundercat.rap'
21
+ monitor = File.dirname(File.expand_path(__FILE__)) + '/../src/monitor/monitor.rb'
22
+
23
+ # remove old monitor and replace with new monitor
24
+ FileUtils.rm_rf("#{target_dir}/monitor.rb") if File.exists?("#{target_dir}/monitor.rb")
25
+ FileUtils.cp(monitor, target_dir)
26
+
27
+ # drop in new thundercat rap
28
+ FileUtils.cp(rap, "#{target_dir}/webapps")
29
+ end
30
+
31
+ puts "[ThunderCat] Successfully updated ThunderCat at: #{target_dir}"
32
+
33
+ rescue => e
34
+ puts "[ThunderCat] OOps something went wrong: #{e}"
35
+ end
36
+ end
37
+
38
+
@@ -24,6 +24,23 @@ class Decision
24
24
  `cd #{webapps_dir}/thundercat; ./start.sh`
25
25
  end
26
26
 
27
+ def standalone_decide(option, base, relative, type)
28
+ zip_file = base + '/' + relative
29
+ zip_dir = path_without_ext(zip_file, base)
30
+ if option == :create
31
+ clean_standalone(zip_dir, zip_file, base) if rap_already_deployed?(zip_dir)
32
+ deploy_standalone(zip_file, zip_dir, base)
33
+ end
34
+ end
35
+
36
+ def standalone_initial(standalone_dir)
37
+ Dir.entries(standalone_dir).each do |entry|
38
+ if entry.match(/.zip$/)
39
+ decide(:create, standalone_dir, entry, 'file')
40
+ end
41
+ end
42
+ end
43
+
27
44
  private
28
45
 
29
46
  def deploy_rap(rap_file, rap_dir, base)
@@ -45,13 +62,19 @@ class Decision
45
62
  end
46
63
  `cd #{rap_dir} ; ./#{start_script}`
47
64
  puts "[ThunderCat] Successfully deployed and started app at: #{rap_file}"
48
- archive_rap(rap_file,base)
65
+ archive_rap(rap_file, base)
49
66
  else
50
67
  puts '[ThunderCat] no rap file found so could not start app'
51
68
  end
52
69
 
53
70
  end
54
71
 
72
+ def deploy_standalone(zip_file, zip_dir, base)
73
+ Rappa.new(:input_archive => zip_file, :output_archive => base).standalone_expand
74
+ puts "[ThunderCat] Successfully deployed standalone zip archive at: #{zip_file}"
75
+ archive_zip(zip_file, base)
76
+ end
77
+
55
78
  def stop_app(rap_dir)
56
79
  rap_file = rap_dir + '/rap.yml'
57
80
  if File.exists?(rap_file)
@@ -68,11 +91,20 @@ class Decision
68
91
  FileUtils.mv(rap_dir, "#{base}/../archive/#{file_without_ext(rap_file)}.#{Time.now.to_i}")
69
92
  end
70
93
 
71
- def archive_rap(rap_file,base)
94
+ def archive_existing_standalone(zip_dir, zip_file, base)
95
+ FileUtils.mv(zip_dir, "#{base}/../standalone_archive/#{file_without_ext(zip_file)}.#{Time.now.to_i}")
96
+ end
97
+
98
+ def archive_rap(rap_file, base)
72
99
  FileUtils.mv(rap_file, "#{base}/../archive/#{file_without_ext(rap_file)}.#{Time.now.to_i}.rap")
73
100
  puts "[ThunderCat] archived rap file: #{rap_file}"
74
101
  end
75
102
 
103
+ def archive_zip(zip_file, base)
104
+ FileUtils.mv(zip_file, "#{base}/../standalone_archive/#{file_without_ext(zip_file)}.#{Time.now.to_i}.zip")
105
+ puts "[ThunderCat] archived standalone zip file: #{zip_file}"
106
+ end
107
+
76
108
  def rap_already_deployed?(rap_dir)
77
109
  File.exists?(rap_dir)
78
110
  end
@@ -82,6 +114,10 @@ class Decision
82
114
  archive_existing_app(rap_dir, rap_file, base)
83
115
  end
84
116
 
117
+ def clean_standalone(zip_dir, zip_file, base)
118
+ archive_existing_standalone(zip_dir, zip_file, base)
119
+ end
120
+
85
121
  def path_without_ext(file, base)
86
122
  base_name = File.basename(file)
87
123
  base + '/' + base_name.chomp(File.extname(base_name))
@@ -100,12 +136,22 @@ class Monitor
100
136
  def self.go
101
137
  begin
102
138
  webapps_dir = File.dirname(__FILE__) + '/webapps'
139
+ standalone_dir = File.dirname(__FILE__) + '/standalone'
103
140
  Decision.new.initial(webapps_dir)
141
+ Decision.new.standalone_initial(standalone_dir)
104
142
  FSSM.monitor(webapps_dir, '**/*.rap', :directories => true) do
105
143
  update { |base, relative, type| puts "updated #{base}, #{relative}, #{type}" }
106
- delete { |base, relative, type| puts "delete #{base}, #{relative}, #{type}" }
144
+ delete { |base, relative, type| puts "delete #{base}, #{relative}, #{type}" }
107
145
  create { |base, relative, type| Decision.new.decide(:create, base, relative, type) }
146
+
147
+ FSSM.monitor(standalone_dir, '**/*.zip', :directories => true) do
148
+ update { |dir, relative, type| puts "updated #{dir}, #{relative}, #{type}" }
149
+ delete { |dir, relative, type| puts "delete #{dir}, #{relative}, #{type}" }
150
+ create { |dir, relative, type| Decision.new.standalone_decide(:create, dir, relative, type) }
108
151
  end
152
+
153
+ end
154
+
109
155
  rescue => e
110
156
  puts "[ThunderCat] Monitor encountered an error: #{e}"
111
157
  end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thundercat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
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: 2013-07-12 00:00:00.000000000 Z
12
+ date: 2013-11-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
@@ -225,6 +225,7 @@ description: ! 'Easy way to deploy and monitor Rack applications as .rap archive
225
225
  email: kingsley@masterthought.net
226
226
  executables:
227
227
  - /thundercat
228
+ - /thundercat-upgrade
228
229
  extensions: []
229
230
  extra_rdoc_files:
230
231
  - README.md
@@ -235,6 +236,7 @@ files:
235
236
  - src/monitor/stop.sh
236
237
  - README.md
237
238
  - bin/thundercat
239
+ - bin/thundercat-upgrade
238
240
  homepage: https://github.com/masterthought/thundercat
239
241
  licenses:
240
242
  - Apache 2.0