capricorn 0.2.00 → 0.2.01

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,8 +3,8 @@ class EngineGenerator < RubiGen::Base
3
3
 
4
4
  def initialize(runtime_args, runtime_options = {})
5
5
  super
6
- @destination_root = args.shift
7
- @engine_name = File.basename(File.expand_path(@destination_root)).underscore
6
+ @destination_root = File.expand_path('.')
7
+ @engine_name = args.shift.underscore
8
8
  end
9
9
 
10
10
  def manifest
@@ -23,15 +23,16 @@ class EngineGenerator < RubiGen::Base
23
23
  m.directory "rails"
24
24
  m.directory "tasks"
25
25
 
26
- m.template('config/routes.rb', "config/routes.rb")
27
- m.template('Gmfile', "Gmfile")
28
- m.template('rails/init.rb', "rails/init.rb")
29
- m.template('init.rb', "init.rb")
30
- m.template('tasks/engine_tasks.rake', "tasks/#{engine_name}_tasks.rake")
31
- m.template('README.rdoc', "README.rdoc")
32
- m.template('MIT-LICENSE.txt', "MIT-LICENSE.txt")
33
- m.template('lib/engine.rb', "lib/#{engine_name}.rb")
34
- m.template('gitignore', ".gitignore")
26
+ m.template('config/routes.rb', "config/routes.rb")
27
+ m.template('config/initializers/rails_init.rb', "config/initializers/rails_init.rb")
28
+ m.template('Gmfile', "Gmfile")
29
+ m.template('rails/init.rb', "rails/init.rb")
30
+ m.template('init.rb', "init.rb")
31
+ m.template('tasks/engine_tasks.rake', "tasks/#{engine_name}_tasks.rake")
32
+ m.template('README.rdoc', "README.rdoc")
33
+ m.template('MIT-LICENSE.txt', "MIT-LICENSE.txt")
34
+ m.template('lib/engine.rb', "lib/#{engine_name}.rb")
35
+ m.template('gitignore', ".gitignore")
35
36
 
36
37
  end
37
38
  end
@@ -4,7 +4,7 @@ specify do |s|
4
4
  s.summary = %q{Fix this}
5
5
  s.homepage = %q{Fix this}
6
6
 
7
- s.author = "Fix this"
7
+ s.author = "[AUTHOR]"
8
8
  s.email = %q{Fix this}
9
9
 
10
10
  s.ignore_files %r{^public/(\d{3}|index)\.html$}
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__)+'/../../init'
@@ -1,3 +1,9 @@
1
1
  *.gem
2
2
  rdoc
3
- .DS_Store
3
+ .DS_Store
4
+ log/*
5
+ tmp/*
6
+ lib/tasks/vendor/*
7
+ public/vendor/*
8
+ db/migrate/*create_lalala_assets*
9
+ db/schema*
@@ -71,7 +71,7 @@ module Capricorn
71
71
  gems_header = " # Gems added by engine_manager:\n \n"
72
72
 
73
73
  gsub_file('config/environment.rb') do |content|
74
- content.gsub! /^\s*config.gem.+\n/, ''
74
+ content.gsub!(/^\s*config.gem.+\n/, '')
75
75
  content.gsub! %r{#{Regexp.escape(rails_header)}(#{Regexp.escape(gems_header)})?},
76
76
  "#{rails_header}#{gems_header}"
77
77
 
@@ -105,7 +105,7 @@ module Capricorn
105
105
  FileUtils.mkdir_p("db/migrate", :verbose => true)
106
106
  unlinked_migrations.concat(Dir.glob("#{path}/*.rb"))
107
107
  linked_migrations.each do |migration, target|
108
- if target.starts_with? spec.full_gem_path
108
+ if target[0,spec.full_gem_path.size] == spec.full_gem_path
109
109
  unlinked_migrations.delete(target)
110
110
  unused_migrations.delete(migration)
111
111
  end
@@ -133,7 +133,14 @@ module Capricorn
133
133
  end
134
134
  system.as_user(system.web_user, system.web_group) do
135
135
  unlinked_migrations.each do |migration|
136
- FileUtils.ln_s(migration, "db/migrate/#{File.basename(migration)}", :verbose => true)
136
+
137
+ begin
138
+ FileUtils.ln_s(migration, "db/migrate/#{File.basename(migration)}", :verbose => true)
139
+ rescue
140
+ FileUtils.rm_rf("db/migrate/#{File.basename(migration)}", :verbose => true)
141
+ retry
142
+ end
143
+
137
144
  end
138
145
  end
139
146
 
@@ -171,18 +178,30 @@ module Capricorn
171
178
  # install a gem.
172
179
  def gem_install(name, options={})
173
180
  gem_cmd('install', name, options)
181
+ gem_refresh
182
+ end
183
+
184
+ def gem_refresh
185
+ original_paths = Gem.path
186
+ Gem.refresh
187
+ Gem.send(:set_paths, original_paths.compact.join(File::PATH_SEPARATOR))
174
188
  end
175
189
 
176
190
  # check if a gem is installed
177
191
  def gem_installed(name, options)
178
192
  version = options[:version] || '0.0.0'
179
193
  options = { :version => version, :installed => true }
180
- (gem_cmd('list', name, options).strip == 'true')
194
+ (gem_cmd('list', name, options).strip =~ /true/)
181
195
  end
182
196
 
183
197
  # update a gem
184
198
  def gem_update(name, options={})
185
- !(gem_cmd('update', name, options) =~ /Nothing to update/)
199
+ if !(gem_cmd('update', name, options) =~ /Nothing to update/)
200
+ gem_refresh
201
+ true
202
+ else
203
+ false
204
+ end
186
205
  end
187
206
 
188
207
  # ensure the presence of a gem
@@ -207,9 +226,7 @@ module Capricorn
207
226
  "--#{k}=#{v.inspect}"
208
227
  end
209
228
  end
210
- output = user_run(user, "#{gem_bin_path} #{cmd} #{args.join(' ')}")
211
- Gem.refresh
212
- output
229
+ user_run(user, "#{gem_bin_path} #{cmd} #{args.join(' ')}")
213
230
  end
214
231
 
215
232
  end
@@ -60,17 +60,30 @@ module Capricorn
60
60
  end
61
61
 
62
62
  def create_database
63
- db_name = satellite.domain.downcase.gsub(/[^a-z]+/, '_')[0,63]
63
+ db_name = database_name_for(satellite)
64
64
  db_user = db_name[0,13]
65
65
  db_pswd = (rand(1_000_000_000) + 10_000).to_s
66
66
 
67
- system.create_database(satellite.basedomain, "#{db_name}_d", "#{db_user}_ud", db_pswd)
68
- system.create_database(satellite.basedomain, "#{db_name}_t", "#{db_user}_ut", db_pswd)
69
- system.create_database(satellite.basedomain, "#{db_name}_p", "#{db_user}_up", db_pswd)
70
-
67
+ create_database_for(satellite, :d, db_name, db_user, db_pswd)
68
+ create_database_for(satellite, :t, db_name, db_user, db_pswd)
69
+ create_database_for(satellite, :p, db_name, db_user, db_pswd)
71
70
 
72
71
  system.as_user(system.web_user, system.web_group) do
73
- config = %{
72
+ db_file = File.join(system.satellite_root, 'config', 'database.yml')
73
+ write_database_config(db_file, db_name, db_user, db_pswd)
74
+ end
75
+ end
76
+
77
+ def drop_databases
78
+ db_name = satellite.domain.downcase.gsub(/[^a-z]+/, '_')[0,63]
79
+
80
+ system.drop_database("#{db_name}_d")
81
+ system.drop_database("#{db_name}_t")
82
+ system.drop_database("#{db_name}_p")
83
+ end
84
+
85
+ def write_database_config(db_file, db_name, db_user, db_pswd)
86
+ File.open(db_file, 'w+') { |f| f.write(%{
74
87
  development:
75
88
  adapter: mysql
76
89
  database: #{db_name}_d
@@ -97,19 +110,17 @@ production:
97
110
  host: localhost
98
111
  encoding: utf8
99
112
  socket: /var/lib/mysql/mysql.sock
100
- }
101
-
102
- db_file = File.join(system.satellite_root, 'config', 'database.yml')
103
- File.open(db_file, 'w+') { |f| f.write config }
104
- end
113
+ }) }
105
114
  end
106
115
 
107
- def drop_databases
108
- db_name = satellite.domain.downcase.gsub(/[^a-z]+/, '_')[0,63]
109
-
110
- system.drop_database("#{db_name}_d")
111
- system.drop_database("#{db_name}_t")
112
- system.drop_database("#{db_name}_p")
116
+ def database_name_for(satellite)
117
+ satellite.domain.downcase.gsub(/[^a-z]+/, '_')[0,63]
118
+ end
119
+
120
+ def create_database_for(satellite, environment, db_name, db_user, db_pswd)
121
+ db_name = "#{db_name}_#{environment}"
122
+ db_user = "#{db_user}_u#{environment}"
123
+ system.create_database(satellite.basedomain, db_name, db_user, db_pswd)
113
124
  end
114
125
 
115
126
  module Helper
@@ -25,7 +25,7 @@ module Capricorn
25
25
  (options[:all] || k.group_name == group) &&
26
26
  Thor::Util.constant_to_thor_path(k.name) =~ search
27
27
  end
28
- display_klasses(false, classes)
28
+ display_klasses(classes)
29
29
  end
30
30
  end
31
31
 
@@ -44,48 +44,37 @@ module Capricorn
44
44
 
45
45
  private
46
46
 
47
- def display_klasses(with_modules = false, klasses = Thor.subclasses)
48
- klasses -= [Thor, Capricorn::AppRunner] unless with_modules
49
- raise Error, "No Thor tasks available" if klasses.empty?
47
+ def display_klasses(klasses = Thor.subclasses)
48
+ klasses -= [Thor, Capricorn::AppRunner]
50
49
 
51
- if with_modules && !thor_yaml.empty?
52
- max_name = thor_yaml.max { |(xk, xv), (yk, yv)| xk.to_s.size <=> yk.to_s.size }.first.size
53
- modules_label = "Modules"
54
- namespaces_label = "Namespaces"
55
- column_width = [max_name + 4, modules_label.size + 1].max
56
-
57
- print "%-#{column_width}s" % modules_label
58
- puts namespaces_label
59
- print "%-#{column_width}s" % ("-" * modules_label.size)
60
- puts "-" * namespaces_label.size
50
+ if klasses.empty?
51
+ puts "\033[1;34mNo Thor tasks available\033[0m"
52
+ else
53
+ maxima = column_maxima_for(klasses)
61
54
 
62
- thor_yaml.each do |name, info|
63
- print "%-#{column_width}s" % name
64
- puts info[:constants].map { |c| Thor::Util.constant_to_thor_path(c) }.join(", ")
65
- end
66
-
67
- puts
55
+ puts # add some spacing
56
+ klasses.each { |k| display_tasks(k, maxima.first, maxima.last) }
68
57
  end
69
-
58
+ end
59
+
60
+ def column_maxima_for(klasses)
70
61
  # Calculate the largest base class name
71
- max_base = klasses.max do |x,y|
62
+ klass_with_longest_name = klasses.max do |x,y|
72
63
  Thor::Util.constant_to_thor_path(x.name).size <=> Thor::Util.constant_to_thor_path(y.name).size
73
- end.name.size
64
+ end
65
+ max_base = klass_with_longest_name.name.size
74
66
 
75
67
  # Calculate the size of the largest option description
76
68
  max_left_item = klasses.max do |x,y|
77
- (x.maxima.usage + x.maxima.opt).to_i <=> (y.maxima.usage + y.maxima.opt).to_i
69
+ total_x = (x.maxima.usage + x.maxima.opt).to_i
70
+ total_y = (y.maxima.usage + y.maxima.opt).to_i
71
+ total_x <=> total_y
78
72
  end
79
73
 
80
74
  max_left = max_left_item.maxima.usage + max_left_item.maxima.opt
81
75
 
82
- unless klasses.empty?
83
- puts # add some spacing
84
- klasses.each { |k| display_tasks(k, max_base, max_left); }
85
- else
86
- puts "\033[1;34mNo Thor tasks available\033[0m"
87
- end
88
- end
76
+ return [max_base, max_left]
77
+ end
89
78
 
90
79
  def display_tasks(klass, max_base, max_left)
91
80
  if klass.tasks.values.length > 1
@@ -4,10 +4,10 @@ module Capricorn
4
4
  module Apps # :nodoc:
5
5
 
6
6
  class Dev < Thor
7
- desc "activate DOMAIN", "turn an existing satelite into a development satelite"
8
- def activate(domain)
7
+ desc "activate DOMAIN NAME", "turn an existing satelite into a development satelite"
8
+ def activate(domain, name)
9
9
  Capricorn.runtime_gem('rubigen', Capricorn::RUBIGEN_VERSION)
10
- Capricorn.client.make_development_satellite(domain)
10
+ Capricorn.client.make_development_satellite(domain, name)
11
11
  end
12
12
  end
13
13
 
@@ -41,15 +41,10 @@ module Capricorn
41
41
  puts "Pid file #{PidFile.pid_file} already exists. Not starting."
42
42
  exit 1
43
43
  end
44
- Capricorn::Daemon::PidFile.store(Process.pid)
45
- Dir.chdir Capricorn.system.root
46
- File.umask 0000
47
44
 
48
- Capricorn::ExceptionHandler.redirect_std
45
+ setup_child
46
+ regitser_handlers(daemon, &block)
49
47
 
50
- trap("TERM") { daemon.stop; exit }
51
- at_exit { Capricorn::Daemon::PidFile.destroy if $master }
52
- at_exit(&block) if block
53
48
  daemon.start
54
49
  end
55
50
  puts "Daemon started."
@@ -66,6 +61,21 @@ module Capricorn
66
61
  puts "Pid file found, but process was not running. The daemon may have died."
67
62
  end
68
63
 
64
+ private
65
+
66
+ def self.setup_child
67
+ Capricorn::Daemon::PidFile.store(Process.pid)
68
+ Dir.chdir Capricorn.system.root
69
+ File.umask 0000
70
+ Capricorn::ExceptionHandler.redirect_std
71
+ end
72
+
73
+ def self.regitser_handlers(daemon, &block)
74
+ trap("TERM") { daemon.stop; exit }
75
+ at_exit { Capricorn::Daemon::PidFile.destroy if $master }
76
+ at_exit(&block) if block
77
+ end
78
+
69
79
  end
70
80
  end
71
81
  end
@@ -20,7 +20,7 @@ module Gem # :nodoc:
20
20
  alias_method :to_ruby_without_engines, :to_ruby # :nodoc:
21
21
  def to_ruby # :nodoc:
22
22
  code = to_ruby_without_engines
23
- code.gsub! /s\.engine_dependencies\s+[=]([^\n]+)/, 's.instance_variable_set(:@engine_dependencies,\1)'
23
+ code.gsub!(/s\.engine_dependencies\s+[=]([^\n]+)/, 's.instance_variable_set(:@engine_dependencies,\1)')
24
24
  code
25
25
  end
26
26
  end
@@ -21,7 +21,7 @@ module Thor::Util # :nodoc:
21
21
 
22
22
  def self.constant_to_thor_path(*args) # :nodoc:
23
23
  path = old_constant_to_thor_path(*args)
24
- path.sub! /^#{Thor.namespace}:/, '' if Thor.namespace
24
+ path.sub!(/^#{Thor.namespace}:/, '') if Thor.namespace
25
25
  path
26
26
  end
27
27
 
@@ -16,7 +16,8 @@ module Capricorn
16
16
  @worker = Thread.new(self) do |job_queue|
17
17
  while job_queue.running? or job_queue.peek
18
18
 
19
- if job = job_queue.peek
19
+ job = job_queue.peek
20
+ if job
20
21
  job.run(job_queue)
21
22
  job_queue.delete(job.id)
22
23
  else
@@ -21,7 +21,7 @@ module Capricorn
21
21
  @domain = domain
22
22
  @engines = {}
23
23
  end
24
- @domain.gsub! /^www\./, ''
24
+ @domain.gsub!(/^www\./, '')
25
25
  end
26
26
 
27
27
  def basedomain
@@ -61,10 +61,10 @@ module Capricorn
61
61
  end
62
62
  end
63
63
 
64
- def make_development_satellite(domain)
64
+ def make_development_satellite(domain, name)
65
65
  satellite = Capricorn.system.find_satellite(domain)
66
66
  if satellite
67
- Capricorn.system.make_development_satellite(satellite)
67
+ Capricorn.system.make_development_satellite(satellite, name)
68
68
  else
69
69
  Capricorn.log "Satellite not found (#{domain})"
70
70
  end
@@ -31,55 +31,50 @@ module Capricorn
31
31
  # start the failsafe runner.
32
32
  def start_with_failsafe
33
33
  $master = true
34
- stop_server = false
35
- wait_before_start = 0
36
34
  retries = 0
37
- until stop_server
38
- if wait_before_start > 0
39
- sleep(wait_before_start)
40
- wait_before_start = 0
41
- end
42
-
43
- pid = Process.fork { self.run_server }
35
+ loop do
36
+ pid = self.run_server
44
37
  return unless pid
45
38
  Process.waitpid(pid, 0)
39
+
46
40
  case $?.exitstatus
47
41
  when Capricorn::STOP_STATUS
48
- stop_server = true
49
- retries = 0
42
+ return
50
43
  when Capricorn::RESTART_STATUS
51
- wait_before_start = 2
52
- retries = 0
44
+ retries = 0
53
45
  when Capricorn::RELOAD_STATUS
54
- stop_server = true
55
- retries = 0
56
46
  Capricorn::Daemon::PidFile.destroy
57
47
  Capricorn.system.run %{#{Capricorn::BIN_PATH} #{ORIGINAL_ARGV.join(' ')}}
48
+ return
58
49
  else
59
50
  retries += 1
60
- stop_server = true if retries >= 3
51
+ return if retries >= 3
61
52
  end
53
+
54
+ sleep(2)
62
55
  end
63
56
  end
64
57
 
65
58
  # start the actual DRb server
66
59
  def run_server
67
- $master = false
68
- Dir.chdir(Capricorn.system.root)
69
-
70
- Capricorn.log "Server started"
71
- uri = "druby://#{Capricorn.system.server_hostname}:#{Capricorn.system.server_port}"
72
- DRb.start_service uri, self.proxy, self.options_for_server
73
- Capricorn.log "listening at #{self.construct_uri(uri)}"
74
- make_client_cert_public!
75
-
76
- at_exit do
77
- Capricorn.system.queue.stop!
78
- Capricorn.log "Server stopped"
60
+ Process.fork do
61
+ $master = false
62
+ Dir.chdir(Capricorn.system.root)
63
+
64
+ Capricorn.log "Server started"
65
+ uri = "druby://#{Capricorn.system.server_hostname}:#{Capricorn.system.server_port}"
66
+ DRb.start_service uri, self.proxy, self.options_for_server
67
+ Capricorn.log "listening at #{self.construct_uri(uri)}"
68
+ make_client_cert_public!
69
+
70
+ at_exit do
71
+ Capricorn.system.queue.stop!
72
+ Capricorn.log "Server stopped"
73
+ end
74
+
75
+ DRb.thread.join
76
+ exit($exitstatus || Capricorn::STOP_STATUS)
79
77
  end
80
-
81
- DRb.thread.join
82
- exit($exitstatus || Capricorn::STOP_STATUS)
83
78
  end
84
79
 
85
80
  end
@@ -36,21 +36,28 @@ module Capricorn
36
36
  FileUtils.mkdir_p('/tmp/quick_cert')
37
37
  File.chmod(0700, '/tmp/quick_cert')
38
38
 
39
- Dir.chdir('/tmp/quick_cert') do
40
- Capricorn.system.run "curl -O #{Capricorn::QUICK_CERT}"
41
- Capricorn.system.run "tar xzf QuickCert-1.0.2.tar.gz"
42
-
43
- Dir.chdir('/tmp/quick_cert/QuickCert-1.0.2') do
44
- Capricorn.system.run "#{Capricorn.system.ruby_path} ./setup.rb config"
45
- Capricorn.system.run "#{Capricorn.system.ruby_path} ./setup.rb setup"
46
- Capricorn.system.run "#{Capricorn.system.ruby_path} ./setup.rb install"
47
- end
48
- end
39
+ download_quick_cert!
40
+ build_quick_cert!
49
41
 
50
42
  FileUtils.rm_rf('/tmp/quick_cert')
51
43
  end
52
44
  end
53
45
 
46
+ def download_quick_cert!
47
+ Dir.chdir('/tmp/quick_cert') do
48
+ Capricorn.system.run "curl -O #{Capricorn::QUICK_CERT}"
49
+ Capricorn.system.run "tar xzf QuickCert-1.0.2.tar.gz"
50
+ end
51
+ end
52
+
53
+ def build_quick_cert!
54
+ Dir.chdir('/tmp/quick_cert/QuickCert-1.0.2') do
55
+ Capricorn.system.run "#{Capricorn.system.ruby_path} ./setup.rb config"
56
+ Capricorn.system.run "#{Capricorn.system.ruby_path} ./setup.rb setup"
57
+ Capricorn.system.run "#{Capricorn.system.ruby_path} ./setup.rb install"
58
+ end
59
+ end
60
+
54
61
  def dump_quick_cert_config!
55
62
  return if File.file? Capricorn.system.path('quick_cert', 'qc_config')
56
63
 
@@ -88,18 +88,16 @@ module Capricorn
88
88
  end
89
89
  end
90
90
 
91
- def make_development_satellite(satellite)
91
+ def make_development_satellite(satellite, name)
92
92
  if satellite
93
93
  Capricorn.runtime_gem('rubigen', Capricorn::RUBIGEN_VERSION)
94
94
  resolve_options_with satellite do
95
95
  as_user(web_user, web_group) do
96
- Dir.chdir(File.dirname(satellite_root)) do
96
+ Dir.chdir(satellite_root) do
97
97
 
98
- name = File.basename(satellite_root)
99
-
100
- FileUtils.rm_r("#{name}/doc", :verbose => true) rescue nil
101
- FileUtils.rm_r("#{name}/README", :verbose => true) rescue nil
102
- FileUtils.rm_r("#{name}/public/javascripts", :verbose => true) rescue nil
98
+ FileUtils.rm_r("doc", :verbose => true) rescue nil
99
+ FileUtils.rm_r("README", :verbose => true) rescue nil
100
+ FileUtils.rm_r("public/javascripts", :verbose => true) rescue nil
103
101
 
104
102
  require 'rubigen/scripts/generate'
105
103
  RubiGen::Base.use_application_sources!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capricorn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.00
4
+ version: 0.2.01
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Menke
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-20 00:00:00 +02:00
12
+ date: 2009-06-16 00:00:00 +02:00
13
13
  default_executable: capricorn
14
14
  dependencies: []
15
15
 
@@ -66,14 +66,15 @@ files:
66
66
  - lib/capricorn.rb
67
67
  - lib/rubygems_plugin.rb
68
68
  - app_generators/engine/engine_generator.rb
69
- - app_generators/engine/templates/Gmfile
70
- - app_generators/engine/templates/MIT-LICENSE.txt
71
- - app_generators/engine/templates/README.rdoc
69
+ - app_generators/engine/templates/config/initializers/rails_init.rb
72
70
  - app_generators/engine/templates/config/routes.rb
73
71
  - app_generators/engine/templates/gitignore
72
+ - app_generators/engine/templates/Gmfile
74
73
  - app_generators/engine/templates/init.rb
75
74
  - app_generators/engine/templates/lib/engine.rb
75
+ - app_generators/engine/templates/MIT-LICENSE.txt
76
76
  - app_generators/engine/templates/rails/init.rb
77
+ - app_generators/engine/templates/README.rdoc
77
78
  - app_generators/engine/templates/tasks/engine_tasks.rake
78
79
  has_rdoc: true
79
80
  homepage: http://github.com/simonmenke/capricorn
@@ -99,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
100
  requirements: []
100
101
 
101
102
  rubyforge_project:
102
- rubygems_version: 1.3.5
103
+ rubygems_version: 1.3.3
103
104
  signing_key:
104
105
  specification_version: 3
105
106
  summary: Manage satellites