capricorn 0.2.25 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. data/LICENSE +19 -0
  2. data/README.md +1 -0
  3. data/bin/capricorn-app-scaffolder +27 -0
  4. data/bin/capricorn-gem-spec +33 -0
  5. data/bin/capricornctl +12 -0
  6. data/bin/capricornd +31 -0
  7. data/erlang/lib/bert/doc/overview.edoc +4 -0
  8. data/erlang/lib/bert/ebin/bert.app +9 -0
  9. data/erlang/lib/bert/rebar.config +3 -0
  10. data/erlang/lib/bert/src/bert.erl +69 -0
  11. data/erlang/lib/bertio/doc/overview.edoc +4 -0
  12. data/erlang/lib/bertio/ebin/bertio.app +9 -0
  13. data/erlang/lib/bertio/rebar.config +3 -0
  14. data/erlang/lib/bertio/src/bertio.erl +28 -0
  15. data/erlang/lib/bertrpc/doc/overview.edoc +4 -0
  16. data/erlang/lib/bertrpc/ebin/bertrpc.app +12 -0
  17. data/erlang/lib/bertrpc/include/bertrpc.hrl +1 -0
  18. data/erlang/lib/bertrpc/rebar.config +5 -0
  19. data/erlang/lib/bertrpc/src/bertrpc.erl +471 -0
  20. data/erlang/lib/bertrpc/src/bertrpc_hello_world.erl +148 -0
  21. data/erlang/lib/bertrpc/src/fd_tcp.erl +376 -0
  22. data/erlang/lib/capricorn/doc/overview.edoc +4 -0
  23. data/erlang/lib/capricorn/ebin/capricorn.app +56 -0
  24. data/erlang/lib/capricorn/include/capricorn.hrl +76 -0
  25. data/erlang/lib/capricorn/rebar.config +3 -0
  26. data/erlang/lib/capricorn/src/cap_application.erl +170 -0
  27. data/erlang/lib/capricorn/src/cap_cluster.erl +121 -0
  28. data/erlang/lib/capricorn/src/cap_cluster_gems.erl +422 -0
  29. data/erlang/lib/capricorn/src/cap_config.erl +25 -0
  30. data/erlang/lib/capricorn/src/cap_dets_updater.erl +26 -0
  31. data/erlang/lib/capricorn/src/cap_event_sup.erl +35 -0
  32. data/erlang/lib/capricorn/src/cap_events.erl +24 -0
  33. data/erlang/lib/capricorn/src/cap_external_api.erl +87 -0
  34. data/erlang/lib/capricorn/src/cap_external_apps_api.erl +125 -0
  35. data/erlang/lib/capricorn/src/cap_external_gems_api.erl +85 -0
  36. data/erlang/lib/capricorn/src/cap_external_machines_api.erl +18 -0
  37. data/erlang/lib/capricorn/src/cap_gem_utils.erl +111 -0
  38. data/erlang/lib/capricorn/src/cap_internal_api.erl +69 -0
  39. data/erlang/lib/capricorn/src/cap_internal_apps_api.erl +38 -0
  40. data/erlang/lib/capricorn/src/cap_log.erl +113 -0
  41. data/erlang/lib/capricorn/src/cap_machine.erl +338 -0
  42. data/erlang/lib/capricorn/src/cap_machine_apps.erl +410 -0
  43. data/erlang/lib/capricorn/src/cap_machine_apps_sup.erl +57 -0
  44. data/erlang/lib/capricorn/src/cap_sup.erl +200 -0
  45. data/erlang/lib/capricorn/src/cap_util.erl +278 -0
  46. data/erlang/lib/capricorn/src/capricorn.erl +45 -0
  47. data/erlang/lib/capricorn/src/capricorn_app.erl +36 -0
  48. data/erlang/lib/emq/ebin/emq.app +17 -0
  49. data/erlang/lib/emq/src/emq.erl +261 -0
  50. data/erlang/lib/emq/src/emq_app.erl +11 -0
  51. data/erlang/lib/emq/src/emq_pool.erl +178 -0
  52. data/erlang/lib/emq/src/emq_queue.erl +332 -0
  53. data/erlang/lib/emq/src/emq_status.erl +148 -0
  54. data/erlang/lib/emq/src/emq_sup.erl +132 -0
  55. data/erlang/lib/gcd/ebin/gcd.app +18 -0
  56. data/erlang/lib/gcd/include/gcd.hrl +5 -0
  57. data/erlang/lib/gcd/rebar.config +3 -0
  58. data/erlang/lib/gcd/src/gcd.erl +51 -0
  59. data/erlang/lib/gcd/src/gcd_app.erl +13 -0
  60. data/erlang/lib/gcd/src/gcd_event.erl +39 -0
  61. data/erlang/lib/gcd/src/gcd_server.erl +30 -0
  62. data/erlang/lib/gcd/src/gcd_srv.erl +186 -0
  63. data/erlang/lib/gcd/src/gcd_sup.erl +18 -0
  64. data/erlang/rebar +0 -0
  65. data/erlang/rebar.config +9 -0
  66. data/erlang/rel/overlay/bin/capricornd +146 -0
  67. data/erlang/rel/overlay/erts-vsn/bin/erl +34 -0
  68. data/erlang/rel/overlay/erts-vsn/bin/nodetool +80 -0
  69. data/erlang/rel/overlay/etc/capricorn/app.config +59 -0
  70. data/erlang/rel/overlay/etc/capricorn/cluster-vm.args +21 -0
  71. data/erlang/rel/overlay/etc/capricorn/machine-vm.args +21 -0
  72. data/erlang/rel/reltool.config +43 -0
  73. data/ext/Makefile +2 -0
  74. data/ext/extconf.rb +1 -0
  75. data/lib/capricorn-client.rb +86 -0
  76. data/lib/capricorn-client/cli/applications.rb +256 -0
  77. data/lib/capricorn-client/cli/gems.rb +57 -0
  78. data/lib/capricorn-client/cli/machines.rb +9 -0
  79. data/lib/capricorn-client/helpers.rb +62 -0
  80. data/lib/capricorn.rb +5 -99
  81. data/lib/capricorn/driver.rb +86 -0
  82. data/lib/capricorn/recipes/apache-debian.rb +112 -0
  83. data/lib/capricorn/recipes/centos-plesk.rb +162 -0
  84. data/lib/capricorn/recipes/macports.rb +54 -0
  85. data/lib/capricorn/system_context.rb +49 -0
  86. data/lib/capricorn/version.rb +5 -0
  87. metadata +233 -74
  88. data/app_generators/engine/engine_generator.rb +0 -40
  89. data/app_generators/engine/templates/Gmfile +0 -20
  90. data/app_generators/engine/templates/MIT-LICENSE.txt +0 -20
  91. data/app_generators/engine/templates/README.rdoc +0 -7
  92. data/app_generators/engine/templates/config/initializers/rails_init.rb +0 -1
  93. data/app_generators/engine/templates/config/routes.rb +0 -2
  94. data/app_generators/engine/templates/gitignore +0 -9
  95. data/app_generators/engine/templates/init.rb +0 -1
  96. data/app_generators/engine/templates/lib/engine.rb +0 -4
  97. data/app_generators/engine/templates/rails/init.rb +0 -1
  98. data/app_generators/engine/templates/tasks/engine_tasks.rake +0 -4
  99. data/bin/capricorn +0 -20
  100. data/lib/capricorn/actor.rb +0 -23
  101. data/lib/capricorn/actor/actions.rb +0 -76
  102. data/lib/capricorn/actors/apache_actor.rb +0 -56
  103. data/lib/capricorn/actors/base_actor.rb +0 -335
  104. data/lib/capricorn/actors/host_file_actor.rb +0 -77
  105. data/lib/capricorn/actors/mysql_actor.rb +0 -20
  106. data/lib/capricorn/actors/passenger_actor.rb +0 -28
  107. data/lib/capricorn/actors/plesk_actor.rb +0 -228
  108. data/lib/capricorn/actors/sqlite3_actor.rb +0 -44
  109. data/lib/capricorn/app_runner.rb +0 -108
  110. data/lib/capricorn/apps/dev.rb +0 -15
  111. data/lib/capricorn/apps/engines.rb +0 -33
  112. data/lib/capricorn/apps/jobs.rb +0 -35
  113. data/lib/capricorn/apps/satellite.rb +0 -68
  114. data/lib/capricorn/apps/server.rb +0 -73
  115. data/lib/capricorn/client.rb +0 -48
  116. data/lib/capricorn/client/auth_token.rb +0 -98
  117. data/lib/capricorn/daemon.rb +0 -81
  118. data/lib/capricorn/exception_handler.rb +0 -79
  119. data/lib/capricorn/extentions/rubygems_plugin.rb +0 -27
  120. data/lib/capricorn/extentions/thor_extentions.rb +0 -32
  121. data/lib/capricorn/job_queue.rb +0 -203
  122. data/lib/capricorn/satellite.rb +0 -52
  123. data/lib/capricorn/satellite/actions.rb +0 -55
  124. data/lib/capricorn/satellite/dependency_loader.rb +0 -82
  125. data/lib/capricorn/satellite/persistence.rb +0 -50
  126. data/lib/capricorn/server.rb +0 -144
  127. data/lib/capricorn/server/daemon.rb +0 -83
  128. data/lib/capricorn/server/proxy.rb +0 -25
  129. data/lib/capricorn/server/security.rb +0 -120
  130. data/lib/capricorn/system.rb +0 -218
  131. data/lib/capricorn/system/config.rb +0 -49
  132. data/lib/capricorn/system/helper.rb +0 -21
  133. data/lib/capricorn/system/options.rb +0 -79
  134. data/lib/capricorn/system/process_user.rb +0 -73
  135. data/lib/capricorn/system/satellites.rb +0 -44
  136. data/lib/capricorn/system/shell.rb +0 -80
  137. data/lib/rubygems_plugin.rb +0 -1
  138. data/spec/actor/actions_spec.rb +0 -13
  139. data/spec/spec_helper.rb +0 -1
@@ -1,40 +0,0 @@
1
- class EngineGenerator < RubiGen::Base
2
- attr_reader :engine_name
3
-
4
- def initialize(runtime_args, runtime_options = {})
5
- super
6
- @destination_root = File.expand_path('.')
7
- @engine_name = args.shift.underscore
8
- end
9
-
10
- def manifest
11
- record do |m|
12
-
13
- m.directory "app/controllers"
14
- m.directory "app/models"
15
- m.directory "app/views"
16
- m.directory "app/helpers"
17
- m.directory "config"
18
- m.directory "db/migrate"
19
- m.directory "lib"
20
- m.directory "public/images"
21
- m.directory "public/javascripts"
22
- m.directory "public/stylesheets"
23
- m.directory "rails"
24
- m.directory "tasks"
25
-
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")
36
-
37
- end
38
- end
39
-
40
- end
@@ -1,20 +0,0 @@
1
- specify do |s|
2
- s.name = %q{<%= engine_name %>}
3
- s.version = "0.0.1"
4
- s.summary = %q{Fix this}
5
- s.homepage = %q{Fix this}
6
-
7
- s.author = "[AUTHOR]"
8
- s.email = "[EMAIL]"
9
-
10
- s.ignore_files %r{^public/(\d{3}|index)\.html$}
11
- s.ignore_files %r{^public/favicon.ico$}
12
- s.ignore_files %r{^public/robots.txt$}
13
- s.ignore_files %r{^public/images/rails\.png$}
14
- s.ignore_files %r{^lib/tasks}
15
- s.ignore_files %r{^config/(boot|database|environment|initializers)}
16
- s.ignore_files %r{^app/controllers/application_controller.rb}
17
- s.ignore_files %r{^app/helpers/application_helper.rb}
18
- s.ignore_files %r{^db/schema.rb}
19
- s.ignore_files %r{^public/system}
20
- end
@@ -1,20 +0,0 @@
1
- Copyright (c) 2009 [AUTHOR]
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,7 +0,0 @@
1
- = <%= engine_name.humanize %>
2
-
3
-
4
- == Example
5
-
6
-
7
- Copyright (c) 2009 [AUTHOR], released under the MIT license
@@ -1 +0,0 @@
1
- require File.dirname(__FILE__)+'/../../init'
@@ -1,2 +0,0 @@
1
- ActionController::Routing::Routes.draw do |map|
2
- end
@@ -1,9 +0,0 @@
1
- *.gem
2
- rdoc
3
- .DS_Store
4
- log/*
5
- tmp/*
6
- lib/tasks/vendor/*
7
- public/vendor/*
8
- db/migrate/*create_lalala_assets*
9
- db/schema*
@@ -1 +0,0 @@
1
- require File.dirname(__FILE__)+'/rails/init'
@@ -1,4 +0,0 @@
1
- # <%= engine_name.camelize %>
2
-
3
- module <%= engine_name.camelize %>
4
- end
@@ -1 +0,0 @@
1
- # Include hook code here
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :<%= engine_name %> do
3
- # # Task goes here
4
- # end
data/bin/capricorn DELETED
@@ -1,20 +0,0 @@
1
- #!/usr/bin/env ruby
2
- begin
3
- require File.dirname(__FILE__)+'/../lib/capricorn'
4
- rescue LoadError
5
- require 'rubygems'
6
- require 'capricorn'
7
- end
8
-
9
- module Capricorn
10
- BIN_PATH = File.expand_path($PROGRAM_NAME)
11
- ORIGINAL_ARGV = ARGV.dup
12
- end
13
-
14
- Capricorn::AppRunner.use :Server
15
- Capricorn::AppRunner.use :Satellite
16
- Capricorn::AppRunner.use :Engines
17
- Capricorn::AppRunner.use :Jobs
18
- Capricorn::AppRunner.use :Dev
19
- Capricorn::AppRunner.namespace = 'capricorn:apps'
20
- Capricorn::AppRunner.start
@@ -1,23 +0,0 @@
1
-
2
- module Capricorn
3
-
4
- # The actor class provides the mechanisme for scheduling the execution of seperate tasks.
5
- class Actor
6
-
7
- autoload :Actions, File.dirname(__FILE__)+'/actor/actions'
8
-
9
- include Capricorn::Actor::Actions
10
-
11
- attr_reader :system, :satellite
12
-
13
- action :install_satellite, :uninstall_satellite, :link_satellite
14
- action :install_engine, :uninstall_engine, :update_engine
15
-
16
- # create a new actor for the provided system and satellite
17
- def initialize(system, satellite)
18
- @system = system
19
- @satellite = satellite
20
- end
21
-
22
- end
23
- end
@@ -1,76 +0,0 @@
1
-
2
- module Capricorn
3
- class Actor
4
- module Actions
5
-
6
- def self.included(base)
7
- base.extend Capricorn::Actor::Actions::ClassMethods
8
- end
9
-
10
- # run the callbacks registerd to <tt>action</tt>. the will run the <tt>before</tt>, <tt>on</tt> and <tt>after</tt> fases.
11
- def run_callbacks!(action)
12
- action = action.to_sym
13
- run_callbacks_in_fase! action, :before
14
- run_callbacks_in_fase! action, :on
15
- run_callbacks_in_fase! action, :after
16
- end
17
-
18
- # run the callbacks registerd to <tt>action</tt> in the +fase+
19
- def run_callbacks_in_fase!(action, fase)
20
- action = action.to_sym
21
- fase = fase.to_sym
22
- self.class.methods_for(action, fase).each { |meth| self.send(meth) }
23
- end
24
-
25
- module ClassMethods
26
-
27
- # register a callback to be run <tt>before</tt> the <tt>action</tt>.
28
- def before(action, meth)
29
- methods_for(action, :before).push(meth.to_sym)
30
- end
31
-
32
- # register a callback to be run <tt>on</tt> the <tt>action</tt>.
33
- def on(action, meth)
34
- methods_for(action, :on).push(meth.to_sym)
35
- end
36
-
37
- # register a callback to be run <tt>after</tt> the <tt>action</tt>.
38
- def after(action, meth)
39
- methods_for(action, :after).push(meth.to_sym)
40
- end
41
-
42
- # get the registered callbacks for the +action+ and +face+.
43
- def methods_for(action, fase)
44
- action = action.to_sym
45
- fase = fase.to_sym
46
-
47
- @actions ||= {}
48
- @actions[action] ||= {}
49
- @actions[action][fase] ||= []
50
- @actions[action][fase]
51
- end
52
-
53
- # define one or more actions.
54
- def action(*names)
55
- names.each do |name|
56
- module_eval %{
57
- def self.before_#{name}(meth)
58
- before(:#{name}, meth)
59
- end
60
- def self.on_#{name}(meth)
61
- on(:#{name}, meth)
62
- end
63
- def self.after_#{name}(meth)
64
- after(:#{name}, meth)
65
- end
66
- def run_#{name}_callbacks!
67
- run_callbacks!(:#{name})
68
- end
69
- }
70
- end
71
- end
72
-
73
- end
74
- end
75
- end
76
- end
@@ -1,56 +0,0 @@
1
-
2
- module Capricorn
3
- module Actors # :nodoc:
4
- class ApacheActor < Capricorn::Actor
5
-
6
- on_install_satellite :write_config_file
7
- after_install_satellite :restart
8
-
9
- on_uninstall_satellite :remove_config_file
10
- after_uninstall_satellite :restart
11
-
12
- # restart the apache server
13
- def restart
14
- system.run "#{system.apachectl_path} -k restart"
15
- end
16
-
17
- # write the vhost config file (needs apache restart)
18
- def write_config_file
19
- config = %{<VirtualHost *>
20
- ServerName #{satellite.domain}
21
-
22
- ErrorLog logs/#{satellite.domain}.error.log
23
- CustomLog logs/#{satellite.domain}.access.log common
24
- DocumentRoot #{system.satellite_root}/public
25
- <Directory "#{system.satellite_root}/public">
26
- Options All
27
- AllowOverride All
28
- Order allow,deny
29
- Allow from all
30
- </Directory>
31
- </VirtualHost>}
32
- File.open(system.apache_conf_path, 'w+') { |f| f.write config }
33
- end
34
-
35
- # remove the vhost config file (needs apache restart)
36
- def remove_config_file
37
- File.unlink(system.apache_conf_path) if File.exist? system.apache_conf_path
38
- end
39
-
40
- module Config
41
-
42
- # path to the apachectl tool
43
- def apachectl_path(&block)
44
- option(:apachectl_path, block) { |v| v or find_bin('apache2ctl', 'apachectl') }
45
- end
46
-
47
- # path to the vhost specific config files
48
- def apache_conf_path(&block)
49
- satellite_option(:apache_conf_path, block) { |s,v| v or "/opt/local/apache2/conf/apps/#{s.domain}.conf" }
50
- end
51
-
52
- end
53
-
54
- end
55
- end
56
- end
@@ -1,335 +0,0 @@
1
-
2
- module Capricorn
3
- module Actors # :nodoc:
4
- class BaseActor < Capricorn::Actor
5
-
6
- on_install_satellite :create_rails_app
7
- on_link_satellite :link_engines
8
- on_uninstall_satellite :destroy_rails_app
9
-
10
- # create a new rails app for the current satellite
11
- def create_rails_app
12
- system.as_user(system.web_user, system.web_group) do
13
- FileUtils.mkdir_p(File.dirname(system.satellite_root), :verbose => true)
14
- FileUtils.mkdir_p(system.shared_root, :verbose => true)
15
- end
16
-
17
- Dir.chdir(File.dirname(system.satellite_root)) do
18
- system.user_run system.web_user, "rails --force #{system.satellite_root}"
19
- end
20
-
21
- system.as_user(system.web_user, system.web_group) do
22
- Dir.chdir(File.dirname(system.satellite_root)) do
23
- link(File.join(system.shared_root, 'public'),
24
- File.join(system.satellite_root, 'public', 'system'))
25
- link(File.join(system.shared_root, 'private'),
26
- File.join(system.satellite_root, 'db', 'system'))
27
- link(File.join(system.shared_root, 'log'),
28
- File.join(system.satellite_root, 'log'))
29
- link(File.join(system.shared_root, 'settings'),
30
- File.join(system.satellite_root, 'config', 'settings'))
31
- end
32
-
33
- end
34
- end
35
-
36
- # destroy the rails app for the current satellite
37
- def destroy_rails_app
38
- FileUtils.rm_rf system.satellite_root, :verbose => true
39
- end
40
-
41
- # link the required engines for the current satellite
42
- def link_engines
43
- Dir.chdir(system.satellite_root) do
44
- system.as_user(system.web_user, system.web_group) do
45
-
46
- clean_index_html_file
47
- write_environment
48
- clean_links
49
- @dependecies.reverse_each do |spec|
50
- link_engine(spec)
51
- end
52
-
53
- FileUtils.symlink(
54
- File.join(system.satellite_root, "public"),
55
- File.join(system.satellite_root, "public/vendor", satellite.module_name),
56
- :verbose => true) rescue nil
57
-
58
- if File.exist? 'public/crossdomain.xml'
59
- File.unlink 'public/crossdomain.xml'
60
- end
61
- File.open('public/crossdomain.xml', 'w+') do |f|
62
- f.write %{<?xml version="1.0" encoding="UTF-8"?>
63
- <cross-domain-policy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.adobe.com/xml/schemas/PolicyFile.xsd">
64
- <allow-access-from domain="*" />
65
- <site-control permitted-cross-domain-policies="master-only"/>
66
- <allow-http-request-headers-from domain="*" headers="*" secure="false"/>
67
- </cross-domain-policy>}
68
- end
69
-
70
- end
71
- run_migrations
72
- end
73
- end
74
-
75
- private
76
-
77
- def clean_index_html_file
78
- index_html = File.join(system.satellite_root, 'public', 'index.html')
79
- if File.file?(index_html)
80
- FileUtils.rm_f(index_html, :verbose => true) rescue nil
81
- end
82
- end
83
-
84
- def link(src, dst)
85
- FileUtils.mkdir_p(File.dirname(dst), :verbose => true)
86
- FileUtils.mkdir_p(src, :verbose => true)
87
- FileUtils.rm_rf dst, :verbose => true
88
- FileUtils.symlink(src, dst, :verbose => true)
89
- end
90
-
91
- def write_environment
92
- @dependecies = Capricorn::Satellite::DependencyLoader.load_for(satellite.engines)
93
- @dependecies.engines
94
-
95
- rails_header = "Rails::Initializer.run do |config|\n"
96
- gems_header = " # Gems added by engine_manager:\n \n"
97
-
98
- gsub_file('config/environment.rb') do |content|
99
- content.gsub!(/^\s*config.gem.+\n/, '')
100
- content.gsub! %r{#{Regexp.escape(rails_header)}(#{Regexp.escape(gems_header)})?},
101
- "#{rails_header}#{gems_header}"
102
-
103
- @dependecies.reverse_each do |spec|
104
- gem_options = @dependecies.engines[spec.name] || {}
105
- content.gsub! "engine_manager:\n",
106
- "engine_manager:\n config.gem #{spec.name.inspect}, #{gem_options.inspect}\n"
107
- end
108
- end
109
- end
110
-
111
- def link_engine(spec)
112
- Capricorn.log "linking: #{spec.name}..."
113
- path = File.join(spec.full_gem_path, 'public')
114
- if File.directory?(path)
115
- FileUtils.mkdir_p('public/vendor', :verbose => true)
116
- FileUtils.ln_s(path, "public/vendor/#{spec.name}", :verbose => true)
117
- end
118
-
119
- path = File.join(spec.full_gem_path, 'tasks')
120
- if File.directory?(path)
121
- FileUtils.mkdir_p("lib/tasks/vendor/#{spec.name}", :verbose => true)
122
- Dir.glob("#{path}/*.rake").each do |rake_file|
123
- FileUtils.ln_s(rake_file,
124
- "lib/tasks/vendor/#{spec.name}/#{File.basename(rake_file)}", :verbose => true)
125
- end
126
- end
127
-
128
- path = File.join(spec.full_gem_path, 'config/locales')
129
- if File.directory?(path)
130
- FileUtils.mkdir_p("config/locales", :verbose => true)
131
- Dir.glob("#{path}/*.{rb,yml,yaml}").each do |locale_file|
132
- FileUtils.ln_s(locale_file, "config/locales/#{File.basename(locale_file)}",
133
- :verbose => true) rescue nil
134
- end
135
- end
136
-
137
- path = File.join(spec.full_gem_path, 'db', 'migrate')
138
- if File.directory?(path)
139
- FileUtils.mkdir_p("db/migrate", :verbose => true)
140
- unlinked_migrations.concat(Dir.glob("#{path}/*.rb"))
141
- linked_migrations.each do |migration, target|
142
- if target[0,spec.full_gem_path.size] == spec.full_gem_path
143
- unlinked_migrations.delete(target)
144
- unused_migrations.delete(migration)
145
- end
146
- end
147
- end
148
- end
149
-
150
- def clean_links
151
- Dir.glob("config/locales/*").each do |path|
152
- FileUtils.rm_rf(path) if File.symlink?(path)
153
- end
154
- FileUtils.rm_rf("lib/tasks/vendor", :verbose => true)
155
- FileUtils.rm_rf("public/vendor", :verbose => true)
156
- end
157
-
158
- def run_migrations
159
- Capricorn.log "running your migrations..." unless unlinked_migrations.empty? and unused_migrations.empty?
160
-
161
- unlinked_migration_targets = unlinked_migrations.collect{ |migration|
162
- File.basename(migration) }
163
-
164
- unused_migrations.each do |migration, target|
165
- unless unlinked_migration_targets.include? File.basename(migration)
166
- migration =~ /(\d+)_[^.]+\.rb/
167
- system.user_run(system.web_user, "cd #{system.satellite_root} ; rake db:migrate:down RAILS_ENV=#{system.rails_environment} VERSION=#{$1}")
168
- end
169
- FileUtils.rm_rf(migration, :verbose => true)
170
- end
171
- system.as_user(system.web_user, system.web_group) do
172
- unlinked_migrations.each do |migration|
173
-
174
- begin
175
- FileUtils.ln_s(migration, "db/migrate/#{File.basename(migration)}", :verbose => true)
176
- rescue
177
- FileUtils.rm_rf("db/migrate/#{File.basename(migration)}", :verbose => true)
178
- retry
179
- end
180
-
181
- end
182
- end
183
-
184
- unless unlinked_migrations.empty?
185
- system.user_run(system.web_user, "cd #{system.satellite_root} ; rake db:migrate RAILS_ENV=#{system.rails_environment}")
186
- end
187
- end
188
-
189
- def gsub_file(path, pattern=nil, replace=nil, &block)
190
- if File.exist? path
191
- content = File.read(path)
192
- if block
193
- block.call(content)
194
- else
195
- return false unless content.gsub!(pattern, replace)
196
- end
197
- File.open(path, 'w+') { |f| f.write content }
198
- end
199
- end
200
-
201
- def linked_migrations
202
- @linked_migrations ||= Dir.glob('db/migrate/*.rb').select { |migration| File.symlink?(migration) }.inject({}) { |m, migration| m[migration] = File.readlink(migration) ; m }
203
- end
204
-
205
- def unused_migrations
206
- @unused_migrations ||= linked_migrations.dup
207
- end
208
-
209
- def unlinked_migrations
210
- @unlinked_migrations ||= []
211
- end
212
-
213
- module Helper
214
-
215
- # install a gem.
216
- def gem_install(name, options={})
217
- gem_cmd('install', name, options)
218
- gem_refresh
219
- end
220
-
221
- def gem_refresh
222
- original_paths = [Gem.path].flatten
223
- Gem.refresh
224
- Gem.send(:set_paths, original_paths.compact.join(File::PATH_SEPARATOR))
225
- end
226
-
227
- # check if a gem is installed
228
- def gem_installed(name, options)
229
- version = options[:version] || '0.0.0'
230
- options = { :version => version, :installed => true }
231
- (gem_cmd('list', name, options).strip =~ /true/)
232
- end
233
-
234
- # update a gem
235
- def gem_update(name, options={})
236
- output = if name == :all
237
- gem_cmd('update', nil, options)
238
- else
239
- gem_cmd('update', name, options)
240
- end
241
- if !(output =~ /Nothing to update/)
242
- gem_refresh
243
- true
244
- else
245
- false
246
- end
247
- end
248
-
249
- # ensure the presence of a gem
250
- def ensure_presence_of_gem(name, options={})
251
- if !gem_installed(name, options)
252
- gem_install(name, options)
253
- end
254
- end
255
-
256
- private
257
-
258
- def gem_cmd(cmd, args, options={})
259
- user = options.delete(:user)
260
- user ||= (install_gems_with_web_user ? web_user : system_user)
261
-
262
- args = [args].flatten.compact
263
- args.collect! { |a| (a and a.inspect) || '' }
264
- args += options.map do |k,v|
265
- if TrueClass === v
266
- "--#{k}"
267
- else
268
- "--#{k}=#{v.inspect}"
269
- end
270
- end
271
- user_run(user, "#{gem_bin_path} #{cmd} #{args.join(' ')}")
272
- end
273
-
274
- end
275
-
276
- module Config
277
-
278
- # set the path to the ruby executable.
279
- def ruby_path(&block)
280
- option(:ruby_path, block) { |s, v| v or find_bin('ruby', 'ruby1.8', 'ruby18') }
281
- end
282
-
283
- # set the path to the gem executable.
284
- def gem_bin_path(&block)
285
- option(:gem_bin_path, block) { |s, v| v or find_bin('gem', 'gem1.8', 'gem18') }
286
- end
287
-
288
- # set the path to the rails executable.
289
- def rails_path(&block)
290
- option(:rails_path, block) do |v|
291
- user = (install_gems_with_web_user ? web_user : system_user)
292
- v or user_find_bin(user, 'rails')
293
- end
294
- end
295
-
296
- # set the owner group of the current satellite.
297
- def web_group(&block)
298
- satellite_option(:web_group, block)
299
- end
300
-
301
- # set the owner of the current satellite.
302
- def web_user(&block)
303
- satellite_option(:web_user, block)
304
- end
305
-
306
- # set the system user (the user which runs the capricorn server).
307
- def system_user(&block)
308
- option(:system_user, block) { |v| v or 'root' }
309
- end
310
-
311
- # set whether gems should be installed with the web user.
312
- def install_gems_with_web_user(&block)
313
- option(:install_gems_with_web_user, block)
314
- end
315
-
316
- # set the path to the satellite's root path
317
- def satellite_root(&block)
318
- satellite_option(:satellite_root, block)
319
- end
320
-
321
- # set the path to the satellite's shared path
322
- def shared_root(&block)
323
- satellite_option(:shared_root, block)
324
- end
325
-
326
- # set the rails environment.
327
- def rails_environment(&block)
328
- satellite_option(:rails_environment, block) { |s,v| v or 'development' }
329
- end
330
-
331
- end
332
-
333
- end
334
- end
335
- end