simonmenke-capricorn 0.2.00
Sign up to get free protection for your applications and to get access to all the features.
- data/app_generators/engine/engine_generator.rb +39 -0
- data/app_generators/engine/templates/config/routes.rb +2 -0
- data/app_generators/engine/templates/init.rb +1 -0
- data/app_generators/engine/templates/lib/engine.rb +1 -0
- data/app_generators/engine/templates/rails/init.rb +1 -0
- data/bin/capricorn +20 -0
- data/lib/capricorn/actor/actions.rb +76 -0
- data/lib/capricorn/actor.rb +23 -0
- data/lib/capricorn/actors/apache_actor.rb +56 -0
- data/lib/capricorn/actors/base_actor.rb +276 -0
- data/lib/capricorn/actors/mysql_actor.rb +20 -0
- data/lib/capricorn/actors/passenger_actor.rb +19 -0
- data/lib/capricorn/actors/plesk_actor.rb +210 -0
- data/lib/capricorn/actors/sqlite3_actor.rb +44 -0
- data/lib/capricorn/app_runner.rb +119 -0
- data/lib/capricorn/apps/dev.rb +24 -0
- data/lib/capricorn/apps/engines.rb +33 -0
- data/lib/capricorn/apps/jobs.rb +35 -0
- data/lib/capricorn/apps/satellite.rb +32 -0
- data/lib/capricorn/apps/server.rb +67 -0
- data/lib/capricorn/client/auth_token.rb +98 -0
- data/lib/capricorn/client.rb +48 -0
- data/lib/capricorn/daemon.rb +71 -0
- data/lib/capricorn/exception_handler.rb +78 -0
- data/lib/capricorn/extentions/rubygems_plugin.rb +27 -0
- data/lib/capricorn/extentions/thor_extentions.rb +32 -0
- data/lib/capricorn/job_queue.rb +199 -0
- data/lib/capricorn/satellite/actions.rb +35 -0
- data/lib/capricorn/satellite/dependency_loader.rb +78 -0
- data/lib/capricorn/satellite/persistence.rb +50 -0
- data/lib/capricorn/satellite.rb +49 -0
- data/lib/capricorn/server/daemon.rb +88 -0
- data/lib/capricorn/server/proxy.rb +25 -0
- data/lib/capricorn/server/security.rb +113 -0
- data/lib/capricorn/server.rb +113 -0
- data/lib/capricorn/system/config.rb +49 -0
- data/lib/capricorn/system/helper.rb +21 -0
- data/lib/capricorn/system/options.rb +79 -0
- data/lib/capricorn/system/process_user.rb +73 -0
- data/lib/capricorn/system/satellites.rb +44 -0
- data/lib/capricorn/system/shell.rb +80 -0
- data/lib/capricorn/system.rb +159 -0
- data/lib/capricorn.rb +100 -0
- data/lib/rubygems_plugin.rb +1 -0
- data/spec/actor/actions_spec.rb +13 -0
- data/spec/spec_helper.rb +1 -0
- metadata +99 -0
@@ -0,0 +1,159 @@
|
|
1
|
+
|
2
|
+
module Capricorn
|
3
|
+
class System
|
4
|
+
include DRbUndumped
|
5
|
+
|
6
|
+
autoload :Shell, File.dirname(__FILE__)+'/system/shell'
|
7
|
+
autoload :Config, File.dirname(__FILE__)+'/system/config'
|
8
|
+
autoload :Helper, File.dirname(__FILE__)+'/system/helper'
|
9
|
+
autoload :Options, File.dirname(__FILE__)+'/system/options'
|
10
|
+
autoload :Satellites, File.dirname(__FILE__)+'/system/satellites'
|
11
|
+
autoload :ProcessUser, File.dirname(__FILE__)+'/system/process_user'
|
12
|
+
|
13
|
+
include Capricorn::System::Shell
|
14
|
+
include Capricorn::System::Config
|
15
|
+
include Capricorn::System::Helper
|
16
|
+
include Capricorn::System::Options
|
17
|
+
include Capricorn::System::Satellites
|
18
|
+
include Capricorn::System::ProcessUser
|
19
|
+
|
20
|
+
# get the shared system. this will also set the shared system if you pass a new system as its argument.
|
21
|
+
def self.shared(system=nil)
|
22
|
+
@system = system if system
|
23
|
+
@system
|
24
|
+
end
|
25
|
+
|
26
|
+
# load the shared system
|
27
|
+
def self.load!(root=nil)
|
28
|
+
@system = new(root)
|
29
|
+
end
|
30
|
+
|
31
|
+
def initialize(root=nil)
|
32
|
+
unless root
|
33
|
+
if get_user_name == 'root'
|
34
|
+
root = Capricorn::DEFAULT_ROOT_SYSTEM_DIR
|
35
|
+
else
|
36
|
+
root = Capricorn::DEFAULT_USER_SYSTEM_DIR
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
@root = File.expand_path(root)
|
41
|
+
@actors = []
|
42
|
+
@options = {}
|
43
|
+
@option_descriptors = []
|
44
|
+
@satellite_options = {}
|
45
|
+
@satellite_option_descriptors = []
|
46
|
+
|
47
|
+
system_file = self.path('system.rb')
|
48
|
+
unless File.file? system_file
|
49
|
+
Capricorn.log "No system file found (#{system_file})"
|
50
|
+
exit(1)
|
51
|
+
end
|
52
|
+
|
53
|
+
Capricorn::ExceptionHandler.setup(self.path('ServerNormal.log'), self.path('ServerError.log'))
|
54
|
+
|
55
|
+
use :BaseActor
|
56
|
+
self.instance_eval File.read(system_file)
|
57
|
+
self.resolve_options!
|
58
|
+
end
|
59
|
+
|
60
|
+
attr_accessor :current_satellite, :root
|
61
|
+
|
62
|
+
def queue
|
63
|
+
@queue ||= Capricorn::JobQueue.new
|
64
|
+
end
|
65
|
+
|
66
|
+
def path(*args)
|
67
|
+
File.join(@root, *args)
|
68
|
+
end
|
69
|
+
|
70
|
+
def install_satellite(domain)
|
71
|
+
self.queue.enqueue("install new satellite #{domain}", :domain => domain) do |options|
|
72
|
+
satellite = Capricorn::Satellite.new(options[:domain])
|
73
|
+
|
74
|
+
run_action_on :install_satellite, satellite
|
75
|
+
run_action_on :link_satellite, satellite
|
76
|
+
save_satellite! satellite
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def uninstall_satellite(satellite)
|
81
|
+
if satellite
|
82
|
+
self.queue.enqueue("uninstall #{satellite.domain}", :satellite => satellite) do |options|
|
83
|
+
run_action_on :uninstall_satellite, options[:satellite]
|
84
|
+
destroy_satellite! options[:satellite]
|
85
|
+
end
|
86
|
+
else
|
87
|
+
false
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def install_engine(satellite, name, options={})
|
92
|
+
if satellite
|
93
|
+
self.queue.enqueue("install #{satellite.domain}: #{name} #{options.inspect}",
|
94
|
+
:satellite => satellite, :name => name, :options => options) do |options|
|
95
|
+
|
96
|
+
satellite, name, options = options[:satellite], options[:name], options[:options]
|
97
|
+
ensure_presence_of_gem(name, options)
|
98
|
+
if satellite.add_engine(name, options)
|
99
|
+
run_action_on :install_engine, satellite
|
100
|
+
run_action_on :link_satellite, satellite
|
101
|
+
save_satellite! satellite
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
else
|
106
|
+
false
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def update_engine(satellite, name, options={})
|
111
|
+
if satellite
|
112
|
+
self.queue.enqueue("update #{satellite.domain}: #{name} #{options.inspect}",
|
113
|
+
:satellite => satellite, :name => name, :options => options) do |options|
|
114
|
+
|
115
|
+
satellite, name, options = options[:satellite], options[:name], options[:options]
|
116
|
+
ensure_presence_of_gem(name, options)
|
117
|
+
if satellite.update_engine(name, options)
|
118
|
+
run_action_on :update_engine, satellite
|
119
|
+
run_action_on :link_satellite, satellite
|
120
|
+
save_satellite! satellite
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
else
|
125
|
+
false
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def uninstall_engine(satellite, name)
|
130
|
+
if satellite
|
131
|
+
self.queue.enqueue("uninstall #{satellite.domain}: #{name}",
|
132
|
+
:satellite => satellite, :name => name) do |options|
|
133
|
+
|
134
|
+
satellite, name = options[:satellite], options[:name]
|
135
|
+
if satellite.remove_engine(name)
|
136
|
+
run_action_on :uninstall_engine, satellite
|
137
|
+
run_action_on :link_satellite, satellite
|
138
|
+
save_satellite! satellite
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
else
|
143
|
+
false
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
private
|
148
|
+
|
149
|
+
def run_action_on(action, satellite)
|
150
|
+
resolve_options_with satellite do
|
151
|
+
actors = @actors.collect { |actor_klass| actor_klass.new(self, satellite) }
|
152
|
+
actors.each { |actor| actor.run_callbacks_in_fase! action, :before }
|
153
|
+
actors.each { |actor| actor.run_callbacks_in_fase! action, :on }
|
154
|
+
actors.each { |actor| actor.run_callbacks_in_fase! action, :after }
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
end
|
data/lib/capricorn.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
autoload :URI, 'uri'
|
4
|
+
autoload :Etc, 'etc'
|
5
|
+
autoload :DRb, 'drb'
|
6
|
+
autoload :TSort, 'tsort'
|
7
|
+
autoload :Logger, 'logger'
|
8
|
+
autoload :OpenSSL, 'drb/ssl'
|
9
|
+
autoload :FileUtils, 'fileutils'
|
10
|
+
autoload :DRbUndumped, 'drb'
|
11
|
+
|
12
|
+
module Capricorn
|
13
|
+
base = File.expand_path(File.dirname(__FILE__))
|
14
|
+
|
15
|
+
autoload :Actor, (base+'/capricorn/actor')
|
16
|
+
autoload :Server, (base+'/capricorn/server')
|
17
|
+
autoload :Client, (base+'/capricorn/client')
|
18
|
+
autoload :System, (base+'/capricorn/system')
|
19
|
+
autoload :Daemon, (base+'/capricorn/daemon')
|
20
|
+
autoload :JobQueue, (base+'/capricorn/job_queue')
|
21
|
+
autoload :Satellite, (base+'/capricorn/satellite')
|
22
|
+
autoload :AppRunner, (base+'/capricorn/app_runner')
|
23
|
+
autoload :ExceptionHandler, (base+'/capricorn/exception_handler')
|
24
|
+
|
25
|
+
module Actors
|
26
|
+
base = File.expand_path(File.dirname(__FILE__))
|
27
|
+
|
28
|
+
autoload :BaseActor, (base+'/capricorn/actors/base_actor')
|
29
|
+
autoload :MysqlActor, (base+'/capricorn/actors/mysql_actor')
|
30
|
+
autoload :PleskActor, (base+'/capricorn/actors/plesk_actor')
|
31
|
+
autoload :ApacheActor, (base+'/capricorn/actors/apache_actor')
|
32
|
+
autoload :Sqlite3Actor, (base+'/capricorn/actors/sqlite3_actor')
|
33
|
+
autoload :PassengerActor, (base+'/capricorn/actors/passenger_actor')
|
34
|
+
end
|
35
|
+
|
36
|
+
module Apps
|
37
|
+
base = File.expand_path(File.dirname(__FILE__))
|
38
|
+
|
39
|
+
autoload :Dev, (base+'/capricorn/apps/dev')
|
40
|
+
autoload :Jobs, (base+'/capricorn/apps/jobs')
|
41
|
+
autoload :Server, (base+'/capricorn/apps/server')
|
42
|
+
autoload :Engines, (base+'/capricorn/apps/engines')
|
43
|
+
autoload :Satellite, (base+'/capricorn/apps/satellite')
|
44
|
+
end
|
45
|
+
|
46
|
+
DEFAULT_ROOT_SYSTEM_DIR = '/var/capricorn'
|
47
|
+
DEFAULT_USER_SYSTEM_DIR = '~/.capricorn'
|
48
|
+
STOP_STATUS = 101
|
49
|
+
RESTART_STATUS = 102
|
50
|
+
RELOAD_STATUS = 103
|
51
|
+
QUICK_CERT = "http://segment7.net/projects/ruby/QuickCert/QuickCert-1.0.2.tar.gz"
|
52
|
+
|
53
|
+
THOR_VERSION = '>= 0.9.9'
|
54
|
+
RUBIGEN_VERSION = '>= 1.5.2'
|
55
|
+
|
56
|
+
Capricorn::ExceptionHandler.setup
|
57
|
+
extend ExceptionHandler
|
58
|
+
|
59
|
+
def self.client(token=nil)
|
60
|
+
unless @client
|
61
|
+
@client = Capricorn::Client.current(token)
|
62
|
+
unless @client
|
63
|
+
puts "Failed to connect to the capricorn!"
|
64
|
+
exit(1)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
@client
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.system
|
71
|
+
@system ||= Capricorn::System.shared
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.version
|
75
|
+
unless @version
|
76
|
+
if __FILE__ =~ /\/capricorn-([^\/]+)\//
|
77
|
+
@version = $1
|
78
|
+
else
|
79
|
+
@version = 'edge'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
@version
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.server?(value=nil)
|
86
|
+
@is_server = value unless value.nil?
|
87
|
+
@is_server
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.runtime_gem(gem, version='>= 0.0.0', lib=nil)
|
91
|
+
begin
|
92
|
+
gem(gem, version)
|
93
|
+
require(lib || gem)
|
94
|
+
rescue LoadError
|
95
|
+
puts "You must install #{gem} (#{version}) to use this.\nPlease run: [sudo] gem install #{gem}"
|
96
|
+
exit(1)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'capricorn/extentions/rubygems_plugin'
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__)+'/../lib/capricorn'
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simonmenke-capricorn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.00
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Simon Menke
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-06-03 00:00:00 -07:00
|
13
|
+
default_executable: capricorn
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Manage satellites
|
17
|
+
email: simon.menke@gmail.com
|
18
|
+
executables:
|
19
|
+
- capricorn
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- spec/actor/actions_spec.rb
|
26
|
+
- spec/spec_helper.rb
|
27
|
+
- bin/capricorn
|
28
|
+
- lib/capricorn/actor/actions.rb
|
29
|
+
- lib/capricorn/actor.rb
|
30
|
+
- lib/capricorn/actors/apache_actor.rb
|
31
|
+
- lib/capricorn/actors/base_actor.rb
|
32
|
+
- lib/capricorn/actors/mysql_actor.rb
|
33
|
+
- lib/capricorn/actors/passenger_actor.rb
|
34
|
+
- lib/capricorn/actors/plesk_actor.rb
|
35
|
+
- lib/capricorn/actors/sqlite3_actor.rb
|
36
|
+
- lib/capricorn/app_runner.rb
|
37
|
+
- lib/capricorn/apps/dev.rb
|
38
|
+
- lib/capricorn/apps/engines.rb
|
39
|
+
- lib/capricorn/apps/jobs.rb
|
40
|
+
- lib/capricorn/apps/satellite.rb
|
41
|
+
- lib/capricorn/apps/server.rb
|
42
|
+
- lib/capricorn/client/auth_token.rb
|
43
|
+
- lib/capricorn/client.rb
|
44
|
+
- lib/capricorn/daemon.rb
|
45
|
+
- lib/capricorn/exception_handler.rb
|
46
|
+
- lib/capricorn/extentions/rubygems_plugin.rb
|
47
|
+
- lib/capricorn/extentions/thor_extentions.rb
|
48
|
+
- lib/capricorn/job_queue.rb
|
49
|
+
- lib/capricorn/satellite/actions.rb
|
50
|
+
- lib/capricorn/satellite/dependency_loader.rb
|
51
|
+
- lib/capricorn/satellite/persistence.rb
|
52
|
+
- lib/capricorn/satellite.rb
|
53
|
+
- lib/capricorn/server/daemon.rb
|
54
|
+
- lib/capricorn/server/proxy.rb
|
55
|
+
- lib/capricorn/server/security.rb
|
56
|
+
- lib/capricorn/server.rb
|
57
|
+
- lib/capricorn/system/config.rb
|
58
|
+
- lib/capricorn/system/helper.rb
|
59
|
+
- lib/capricorn/system/options.rb
|
60
|
+
- lib/capricorn/system/process_user.rb
|
61
|
+
- lib/capricorn/system/satellites.rb
|
62
|
+
- lib/capricorn/system/shell.rb
|
63
|
+
- lib/capricorn/system.rb
|
64
|
+
- lib/capricorn.rb
|
65
|
+
- lib/rubygems_plugin.rb
|
66
|
+
- app_generators/engine/engine_generator.rb
|
67
|
+
- app_generators/engine/templates/config/routes.rb
|
68
|
+
- app_generators/engine/templates/init.rb
|
69
|
+
- app_generators/engine/templates/lib/engine.rb
|
70
|
+
- app_generators/engine/templates/rails/init.rb
|
71
|
+
has_rdoc: false
|
72
|
+
homepage: http://github.com/simonmenke/capricorn
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: "0"
|
83
|
+
version:
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: "0"
|
89
|
+
version:
|
90
|
+
requirements: []
|
91
|
+
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.2.0
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: Manage satellites
|
97
|
+
test_files:
|
98
|
+
- spec/actor/actions_spec.rb
|
99
|
+
- spec/spec_helper.rb
|