capricorn 0.2.25 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +19 -0
- data/README.md +1 -0
- data/bin/capricorn-app-scaffolder +27 -0
- data/bin/capricorn-gem-spec +33 -0
- data/bin/capricornctl +12 -0
- data/bin/capricornd +31 -0
- data/erlang/lib/bert/doc/overview.edoc +4 -0
- data/erlang/lib/bert/ebin/bert.app +9 -0
- data/erlang/lib/bert/rebar.config +3 -0
- data/erlang/lib/bert/src/bert.erl +69 -0
- data/erlang/lib/bertio/doc/overview.edoc +4 -0
- data/erlang/lib/bertio/ebin/bertio.app +9 -0
- data/erlang/lib/bertio/rebar.config +3 -0
- data/erlang/lib/bertio/src/bertio.erl +28 -0
- data/erlang/lib/bertrpc/doc/overview.edoc +4 -0
- data/erlang/lib/bertrpc/ebin/bertrpc.app +12 -0
- data/erlang/lib/bertrpc/include/bertrpc.hrl +1 -0
- data/erlang/lib/bertrpc/rebar.config +5 -0
- data/erlang/lib/bertrpc/src/bertrpc.erl +471 -0
- data/erlang/lib/bertrpc/src/bertrpc_hello_world.erl +148 -0
- data/erlang/lib/bertrpc/src/fd_tcp.erl +376 -0
- data/erlang/lib/capricorn/doc/overview.edoc +4 -0
- data/erlang/lib/capricorn/ebin/capricorn.app +56 -0
- data/erlang/lib/capricorn/include/capricorn.hrl +76 -0
- data/erlang/lib/capricorn/rebar.config +3 -0
- data/erlang/lib/capricorn/src/cap_application.erl +170 -0
- data/erlang/lib/capricorn/src/cap_cluster.erl +121 -0
- data/erlang/lib/capricorn/src/cap_cluster_gems.erl +422 -0
- data/erlang/lib/capricorn/src/cap_config.erl +25 -0
- data/erlang/lib/capricorn/src/cap_dets_updater.erl +26 -0
- data/erlang/lib/capricorn/src/cap_event_sup.erl +35 -0
- data/erlang/lib/capricorn/src/cap_events.erl +24 -0
- data/erlang/lib/capricorn/src/cap_external_api.erl +87 -0
- data/erlang/lib/capricorn/src/cap_external_apps_api.erl +125 -0
- data/erlang/lib/capricorn/src/cap_external_gems_api.erl +85 -0
- data/erlang/lib/capricorn/src/cap_external_machines_api.erl +18 -0
- data/erlang/lib/capricorn/src/cap_gem_utils.erl +111 -0
- data/erlang/lib/capricorn/src/cap_internal_api.erl +69 -0
- data/erlang/lib/capricorn/src/cap_internal_apps_api.erl +38 -0
- data/erlang/lib/capricorn/src/cap_log.erl +113 -0
- data/erlang/lib/capricorn/src/cap_machine.erl +338 -0
- data/erlang/lib/capricorn/src/cap_machine_apps.erl +410 -0
- data/erlang/lib/capricorn/src/cap_machine_apps_sup.erl +57 -0
- data/erlang/lib/capricorn/src/cap_sup.erl +200 -0
- data/erlang/lib/capricorn/src/cap_util.erl +278 -0
- data/erlang/lib/capricorn/src/capricorn.erl +45 -0
- data/erlang/lib/capricorn/src/capricorn_app.erl +36 -0
- data/erlang/lib/emq/ebin/emq.app +17 -0
- data/erlang/lib/emq/src/emq.erl +261 -0
- data/erlang/lib/emq/src/emq_app.erl +11 -0
- data/erlang/lib/emq/src/emq_pool.erl +178 -0
- data/erlang/lib/emq/src/emq_queue.erl +332 -0
- data/erlang/lib/emq/src/emq_status.erl +148 -0
- data/erlang/lib/emq/src/emq_sup.erl +132 -0
- data/erlang/lib/gcd/ebin/gcd.app +18 -0
- data/erlang/lib/gcd/include/gcd.hrl +5 -0
- data/erlang/lib/gcd/rebar.config +3 -0
- data/erlang/lib/gcd/src/gcd.erl +51 -0
- data/erlang/lib/gcd/src/gcd_app.erl +13 -0
- data/erlang/lib/gcd/src/gcd_event.erl +39 -0
- data/erlang/lib/gcd/src/gcd_server.erl +30 -0
- data/erlang/lib/gcd/src/gcd_srv.erl +186 -0
- data/erlang/lib/gcd/src/gcd_sup.erl +18 -0
- data/erlang/rebar +0 -0
- data/erlang/rebar.config +9 -0
- data/erlang/rel/overlay/bin/capricornd +146 -0
- data/erlang/rel/overlay/erts-vsn/bin/erl +34 -0
- data/erlang/rel/overlay/erts-vsn/bin/nodetool +80 -0
- data/erlang/rel/overlay/etc/capricorn/app.config +59 -0
- data/erlang/rel/overlay/etc/capricorn/cluster-vm.args +21 -0
- data/erlang/rel/overlay/etc/capricorn/machine-vm.args +21 -0
- data/erlang/rel/reltool.config +43 -0
- data/ext/Makefile +2 -0
- data/ext/extconf.rb +1 -0
- data/lib/capricorn-client.rb +86 -0
- data/lib/capricorn-client/cli/applications.rb +256 -0
- data/lib/capricorn-client/cli/gems.rb +57 -0
- data/lib/capricorn-client/cli/machines.rb +9 -0
- data/lib/capricorn-client/helpers.rb +62 -0
- data/lib/capricorn.rb +5 -99
- data/lib/capricorn/driver.rb +86 -0
- data/lib/capricorn/recipes/apache-debian.rb +112 -0
- data/lib/capricorn/recipes/centos-plesk.rb +162 -0
- data/lib/capricorn/recipes/macports.rb +54 -0
- data/lib/capricorn/system_context.rb +49 -0
- data/lib/capricorn/version.rb +5 -0
- metadata +233 -74
- data/app_generators/engine/engine_generator.rb +0 -40
- data/app_generators/engine/templates/Gmfile +0 -20
- data/app_generators/engine/templates/MIT-LICENSE.txt +0 -20
- data/app_generators/engine/templates/README.rdoc +0 -7
- data/app_generators/engine/templates/config/initializers/rails_init.rb +0 -1
- data/app_generators/engine/templates/config/routes.rb +0 -2
- data/app_generators/engine/templates/gitignore +0 -9
- data/app_generators/engine/templates/init.rb +0 -1
- data/app_generators/engine/templates/lib/engine.rb +0 -4
- data/app_generators/engine/templates/rails/init.rb +0 -1
- data/app_generators/engine/templates/tasks/engine_tasks.rake +0 -4
- data/bin/capricorn +0 -20
- data/lib/capricorn/actor.rb +0 -23
- data/lib/capricorn/actor/actions.rb +0 -76
- data/lib/capricorn/actors/apache_actor.rb +0 -56
- data/lib/capricorn/actors/base_actor.rb +0 -335
- data/lib/capricorn/actors/host_file_actor.rb +0 -77
- data/lib/capricorn/actors/mysql_actor.rb +0 -20
- data/lib/capricorn/actors/passenger_actor.rb +0 -28
- data/lib/capricorn/actors/plesk_actor.rb +0 -228
- data/lib/capricorn/actors/sqlite3_actor.rb +0 -44
- data/lib/capricorn/app_runner.rb +0 -108
- data/lib/capricorn/apps/dev.rb +0 -15
- data/lib/capricorn/apps/engines.rb +0 -33
- data/lib/capricorn/apps/jobs.rb +0 -35
- data/lib/capricorn/apps/satellite.rb +0 -68
- data/lib/capricorn/apps/server.rb +0 -73
- data/lib/capricorn/client.rb +0 -48
- data/lib/capricorn/client/auth_token.rb +0 -98
- data/lib/capricorn/daemon.rb +0 -81
- data/lib/capricorn/exception_handler.rb +0 -79
- data/lib/capricorn/extentions/rubygems_plugin.rb +0 -27
- data/lib/capricorn/extentions/thor_extentions.rb +0 -32
- data/lib/capricorn/job_queue.rb +0 -203
- data/lib/capricorn/satellite.rb +0 -52
- data/lib/capricorn/satellite/actions.rb +0 -55
- data/lib/capricorn/satellite/dependency_loader.rb +0 -82
- data/lib/capricorn/satellite/persistence.rb +0 -50
- data/lib/capricorn/server.rb +0 -144
- data/lib/capricorn/server/daemon.rb +0 -83
- data/lib/capricorn/server/proxy.rb +0 -25
- data/lib/capricorn/server/security.rb +0 -120
- data/lib/capricorn/system.rb +0 -218
- data/lib/capricorn/system/config.rb +0 -49
- data/lib/capricorn/system/helper.rb +0 -21
- data/lib/capricorn/system/options.rb +0 -79
- data/lib/capricorn/system/process_user.rb +0 -73
- data/lib/capricorn/system/satellites.rb +0 -44
- data/lib/capricorn/system/shell.rb +0 -80
- data/lib/rubygems_plugin.rb +0 -1
- data/spec/actor/actions_spec.rb +0 -13
- data/spec/spec_helper.rb +0 -1
data/lib/capricorn/system.rb
DELETED
@@ -1,218 +0,0 @@
|
|
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, immediate)
|
71
|
-
self.queue.enqueue("install new satellite #{domain}", :domain => domain, :immediate => immediate) 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 relink_satellite(satellite, immediate)
|
81
|
-
self.queue.enqueue("relink #{satellite.domain}", :satellite => satellite, :immediate => immediate) do |options|
|
82
|
-
satellite = options[:satellite]
|
83
|
-
|
84
|
-
if satellite
|
85
|
-
run_action_on :link_satellite, satellite
|
86
|
-
save_satellite! satellite
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def update_satellite(satellite, immediate)
|
92
|
-
if satellite
|
93
|
-
self.queue.enqueue("update #{satellite.domain}", :satellite => satellite, :immediate => immediate) do |options|
|
94
|
-
|
95
|
-
satellite = options[:satellite]
|
96
|
-
if satellite.update_all_engines
|
97
|
-
run_action_on :update_engine, satellite
|
98
|
-
run_action_on :link_satellite, satellite
|
99
|
-
save_satellite! satellite
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
103
|
-
else
|
104
|
-
false
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def uninstall_satellite(satellite, immediate)
|
109
|
-
if satellite
|
110
|
-
self.queue.enqueue("uninstall #{satellite.domain}", :satellite => satellite, :immediate => immediate) do |options|
|
111
|
-
run_action_on :uninstall_satellite, options[:satellite]
|
112
|
-
destroy_satellite! options[:satellite]
|
113
|
-
end
|
114
|
-
else
|
115
|
-
false
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
def make_development_satellite(satellite, name)
|
120
|
-
if satellite
|
121
|
-
satellite.module_name = name.to_s
|
122
|
-
satellite.development = true
|
123
|
-
Capricorn.runtime_gem('rubigen', Capricorn::RUBIGEN_VERSION)
|
124
|
-
resolve_options_with satellite do
|
125
|
-
as_user(web_user, web_group) do
|
126
|
-
Dir.chdir(satellite_root) do
|
127
|
-
|
128
|
-
FileUtils.rm_r("doc", :verbose => true) rescue nil
|
129
|
-
FileUtils.rm_r("README", :verbose => true) rescue nil
|
130
|
-
FileUtils.rm_r("public/javascripts", :verbose => true) rescue nil
|
131
|
-
FileUtils.mkdir_p("public/vendor", :verbose => true) rescue nil
|
132
|
-
FileUtils.ln_s(
|
133
|
-
File.join(satellite_root, "public"),
|
134
|
-
File.join(satellite_root, "public/vendor", satellite.module_name),
|
135
|
-
:verbose => true) rescue nil
|
136
|
-
|
137
|
-
require 'rubigen/scripts/generate'
|
138
|
-
RubiGen::Base.use_application_sources!
|
139
|
-
RubiGen::Scripts::Generate.new.run(["-f", name], :generator => 'engine')
|
140
|
-
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
save_satellite! satellite
|
145
|
-
else
|
146
|
-
false
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
def install_engine(satellite, name, options, immediate)
|
151
|
-
if satellite
|
152
|
-
self.queue.enqueue("install #{satellite.domain}: #{name} #{options.inspect}",
|
153
|
-
:satellite => satellite, :name => name, :options => options, :immediate => immediate) do |options|
|
154
|
-
|
155
|
-
satellite, name, options = options[:satellite], options[:name], options[:options]
|
156
|
-
resolve_options_with(satellite) { ensure_presence_of_gem(name, options) }
|
157
|
-
if satellite.add_engine(name, options)
|
158
|
-
run_action_on :install_engine, satellite
|
159
|
-
run_action_on :link_satellite, satellite
|
160
|
-
save_satellite! satellite
|
161
|
-
end
|
162
|
-
|
163
|
-
end
|
164
|
-
else
|
165
|
-
false
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def update_engine(satellite, name, options, immediate)
|
170
|
-
if satellite
|
171
|
-
self.queue.enqueue("update #{satellite.domain}: #{name} #{options.inspect}",
|
172
|
-
:satellite => satellite, :name => name, :options => options, :immediate => immediate) do |options|
|
173
|
-
|
174
|
-
satellite, name, options = options[:satellite], options[:name], options[:options]
|
175
|
-
resolve_options_with(satellite) { ensure_presence_of_gem(name, options) }
|
176
|
-
if satellite.update_engine(name, options)
|
177
|
-
run_action_on :update_engine, satellite
|
178
|
-
run_action_on :link_satellite, satellite
|
179
|
-
save_satellite! satellite
|
180
|
-
end
|
181
|
-
|
182
|
-
end
|
183
|
-
else
|
184
|
-
false
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
def uninstall_engine(satellite, name, immediate)
|
189
|
-
if satellite
|
190
|
-
self.queue.enqueue("uninstall #{satellite.domain}: #{name}",
|
191
|
-
:satellite => satellite, :name => name, :immediate => immediate) do |options|
|
192
|
-
|
193
|
-
satellite, name = options[:satellite], options[:name]
|
194
|
-
if satellite.remove_engine(name)
|
195
|
-
run_action_on :uninstall_engine, satellite
|
196
|
-
run_action_on :link_satellite, satellite
|
197
|
-
save_satellite! satellite
|
198
|
-
end
|
199
|
-
|
200
|
-
end
|
201
|
-
else
|
202
|
-
false
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
private
|
207
|
-
|
208
|
-
def run_action_on(action, satellite)
|
209
|
-
resolve_options_with satellite do
|
210
|
-
actors = @actors.collect { |actor_klass| actor_klass.new(self, satellite) }
|
211
|
-
actors.each { |actor| actor.run_callbacks_in_fase! action, :before }
|
212
|
-
actors.each { |actor| actor.run_callbacks_in_fase! action, :on }
|
213
|
-
actors.each { |actor| actor.run_callbacks_in_fase! action, :after }
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
end
|
218
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
|
2
|
-
module Capricorn
|
3
|
-
class System
|
4
|
-
module Config
|
5
|
-
|
6
|
-
def use_development!
|
7
|
-
environment { 'development' }
|
8
|
-
end
|
9
|
-
|
10
|
-
def development?
|
11
|
-
environment == 'development'
|
12
|
-
end
|
13
|
-
|
14
|
-
def use_production!
|
15
|
-
environment { 'production' }
|
16
|
-
end
|
17
|
-
|
18
|
-
def production?
|
19
|
-
environment == 'production'
|
20
|
-
end
|
21
|
-
|
22
|
-
def environment(&block)
|
23
|
-
option(:environment, block) { |s,v| v or 'production' }
|
24
|
-
end
|
25
|
-
|
26
|
-
def use_ssl!
|
27
|
-
option(:use_ssl, lambda { true })
|
28
|
-
end
|
29
|
-
|
30
|
-
def use_ssl?
|
31
|
-
option(:use_ssl, nil)
|
32
|
-
end
|
33
|
-
|
34
|
-
def bind(hostname=nil, port=nil)
|
35
|
-
server_hostname { hostname }
|
36
|
-
server_port { port }
|
37
|
-
end
|
38
|
-
|
39
|
-
def server_hostname(&block)
|
40
|
-
option(:server_hostname, block) { |v| v or 'localhost' }
|
41
|
-
end
|
42
|
-
|
43
|
-
def server_port(&block)
|
44
|
-
option(:server_port, block) { |v| v or 5000 }
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
|
2
|
-
module Capricorn
|
3
|
-
class System
|
4
|
-
module Helper
|
5
|
-
|
6
|
-
def use(actor)
|
7
|
-
actor_klass = (Capricorn::Actors.const_get(actor) rescue nil)
|
8
|
-
raise "Actor not found! (#{actor})" unless actor_klass
|
9
|
-
|
10
|
-
actor_helper = (actor_klass.const_get('Helper') rescue nil)
|
11
|
-
extend actor_helper if actor_helper
|
12
|
-
|
13
|
-
actor_config = (actor_klass.const_get('Config') rescue nil)
|
14
|
-
extend actor_config if actor_config
|
15
|
-
|
16
|
-
@actors.push(actor_klass)
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
|
2
|
-
module Capricorn
|
3
|
-
class System
|
4
|
-
module Options
|
5
|
-
|
6
|
-
def option(name, proc, &handler)
|
7
|
-
if proc
|
8
|
-
@option_descriptors.push({
|
9
|
-
:name => name.to_sym,
|
10
|
-
:proc => proc,
|
11
|
-
:handler => handler
|
12
|
-
})
|
13
|
-
else
|
14
|
-
if handler && !@options.key?(name.to_sym)
|
15
|
-
@options[name.to_sym] = handler.call(nil)
|
16
|
-
end
|
17
|
-
@options[name.to_sym]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def satellite_option(name, proc, &handler)
|
22
|
-
if proc
|
23
|
-
@satellite_option_descriptors.push({
|
24
|
-
:name => name.to_sym,
|
25
|
-
:proc => proc,
|
26
|
-
:handler => handler
|
27
|
-
})
|
28
|
-
else
|
29
|
-
if handler && !@satellite_options.key?(name.to_sym)
|
30
|
-
@satellite_options[name.to_sym] = handler.call(@current_satellite, nil)
|
31
|
-
end
|
32
|
-
@satellite_options[name.to_sym]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def set_satellite_option(name, value)
|
37
|
-
@satellite_options[name.to_sym] = value
|
38
|
-
end
|
39
|
-
|
40
|
-
def resolve_options_with(satellite)
|
41
|
-
@current_satellite = satellite
|
42
|
-
resolve_options!
|
43
|
-
|
44
|
-
result = yield
|
45
|
-
|
46
|
-
@current_satellite = nil
|
47
|
-
resolve_options!
|
48
|
-
|
49
|
-
result
|
50
|
-
end
|
51
|
-
|
52
|
-
def resolve_options!
|
53
|
-
resolve_options_for_system!
|
54
|
-
resolve_options_for_satellite!
|
55
|
-
end
|
56
|
-
|
57
|
-
def resolve_options_for_system!
|
58
|
-
@options = {}
|
59
|
-
@option_descriptors.each do |option|
|
60
|
-
value = option[:proc].call if option[:proc]
|
61
|
-
value = option[:handler].call(value) if option[:handler]
|
62
|
-
@options[option[:name]] = value
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def resolve_options_for_satellite!
|
67
|
-
@satellite_options = {}
|
68
|
-
if @current_satellite
|
69
|
-
@satellite_option_descriptors.each do |option|
|
70
|
-
value = option[:proc].call(@current_satellite) if option[:proc]
|
71
|
-
value = option[:handler].call(@current_satellite, value) if option[:handler]
|
72
|
-
@satellite_options[option[:name]] = value
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
|
2
|
-
module Capricorn
|
3
|
-
class System
|
4
|
-
module ProcessUser
|
5
|
-
|
6
|
-
# get the uid for a user name
|
7
|
-
def get_uid(username)
|
8
|
-
return username if Numeric === username
|
9
|
-
Etc.getpwnam(username).uid
|
10
|
-
end
|
11
|
-
|
12
|
-
# get the gid for a group name
|
13
|
-
def get_gid(groupname)
|
14
|
-
return groupname if Numeric === groupname
|
15
|
-
Etc.getgrnam(groupname).gid
|
16
|
-
end
|
17
|
-
|
18
|
-
# get the user name for a uid (or the current process user)
|
19
|
-
def get_user_name(uid=Process.uid)
|
20
|
-
return uid if String === uid
|
21
|
-
Etc.getpwuid(uid).name
|
22
|
-
end
|
23
|
-
|
24
|
-
# get the group name for a gid (or the current process group)
|
25
|
-
def get_group_name(gid=Process.gid)
|
26
|
-
return gid if String === gid
|
27
|
-
Etc.getgrgid(gid).name
|
28
|
-
end
|
29
|
-
|
30
|
-
# is this process running as this user?
|
31
|
-
def is_user(username)
|
32
|
-
uid = get_uid(username)
|
33
|
-
Process.euid == uid and Process.uid == uid
|
34
|
-
end
|
35
|
-
|
36
|
-
# is this process running as this group?
|
37
|
-
def is_group(groupname)
|
38
|
-
gid = get_gid(groupname)
|
39
|
-
Process.egid == gid and Process.gid == gid
|
40
|
-
end
|
41
|
-
|
42
|
-
# switch this user to the specified user and group
|
43
|
-
def switch_to_user(username, groupname=nil)
|
44
|
-
different_uid = (Process.euid != get_uid(username))
|
45
|
-
different_gid = (Process.egid != get_gid(groupname)) if groupname
|
46
|
-
|
47
|
-
if groupname and different_gid
|
48
|
-
Process.gid = Process.egid = get_gid(groupname)
|
49
|
-
end
|
50
|
-
|
51
|
-
if different_uid
|
52
|
-
Process.uid = Process.euid = get_uid(username)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
# run the passed block as the specified user and group
|
57
|
-
def as_user(username, groupname=nil, &block)
|
58
|
-
euid = Process.euid
|
59
|
-
egid = Process.egid
|
60
|
-
|
61
|
-
value = nil
|
62
|
-
begin
|
63
|
-
switch_to_user(username, groupname)
|
64
|
-
value = block.call
|
65
|
-
ensure
|
66
|
-
switch_to_user(euid, egid)
|
67
|
-
end
|
68
|
-
value
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
|
2
|
-
module Capricorn
|
3
|
-
class System
|
4
|
-
module Satellites
|
5
|
-
|
6
|
-
def satellites_hash
|
7
|
-
@satellites || load_satellites
|
8
|
-
end
|
9
|
-
|
10
|
-
def satellites
|
11
|
-
satellites_hash.values
|
12
|
-
end
|
13
|
-
|
14
|
-
def find_satellite(domain)
|
15
|
-
satellites_hash[domain]
|
16
|
-
end
|
17
|
-
|
18
|
-
def save_satellite!(satellite)
|
19
|
-
satellites_hash[satellite.domain] = satellite
|
20
|
-
satellite.dump_file(self.path('satellites', "#{satellite.domain}.yml"))
|
21
|
-
end
|
22
|
-
|
23
|
-
def destroy_satellite!(satellite)
|
24
|
-
satellites_hash.delete(satellite.domain)
|
25
|
-
FileUtils.rm_f(self.path('satellites', "#{satellite.domain}.yml"))
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def load_satellites
|
31
|
-
@satellites = {}
|
32
|
-
|
33
|
-
FileUtils.mkdir_p(self.path('satellites'))
|
34
|
-
Dir.glob(self.path('satellites', '*.yml')).each do |yml|
|
35
|
-
satellite = Capricorn::Satellite.load_file(yml)
|
36
|
-
@satellites[satellite.domain] = satellite
|
37
|
-
end
|
38
|
-
|
39
|
-
@satellites
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|