rails_pwnerer 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Manifest +11 -0
- data/bin/rpwn +1 -1
- data/bin/rpwndev +5 -0
- data/lib/pwnage/app/cluster_config.rb +6 -0
- data/lib/pwnage/app/config.rb +64 -0
- data/lib/pwnage/app/main.rb +1 -1
- data/lib/pwnage/app/nginx_config.rb +7 -6
- data/lib/pwnage/base/atomics.rb +57 -0
- data/lib/pwnage/base/hostname.rb +8 -0
- data/lib/pwnage/config/app.rb +13 -0
- data/lib/pwnage/config/paths.rb +37 -0
- data/lib/pwnage/config/ports.rb +45 -0
- data/lib/pwnage/config/repository.rb +119 -0
- data/lib/pwnage/dev_executor.rb +77 -0
- data/lib/pwnage/executor.rb +1 -7
- data/lib/pwnage/scaffolds/config.rb +39 -0
- data/lib/rails_pwnage.rb +3 -2
- data/rails_pwnerer.gemspec +24 -3
- metadata +23 -2
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
@@ -1,18 +1,28 @@
|
|
1
1
|
bin/rpwn
|
2
|
+
bin/rpwndev
|
2
3
|
CHANGELOG
|
3
4
|
lib/pwnage/app/cluster_config.rb
|
5
|
+
lib/pwnage/app/config.rb
|
4
6
|
lib/pwnage/app/database.rb
|
5
7
|
lib/pwnage/app/gems.rb
|
6
8
|
lib/pwnage/app/main.rb
|
7
9
|
lib/pwnage/app/nginx_config.rb
|
8
10
|
lib/pwnage/app/svn.rb
|
11
|
+
lib/pwnage/base/atomics.rb
|
9
12
|
lib/pwnage/base/dirs.rb
|
10
13
|
lib/pwnage/base/gems.rb
|
14
|
+
lib/pwnage/base/hostname.rb
|
11
15
|
lib/pwnage/base/packages.rb
|
12
16
|
lib/pwnage/base/startup.rb
|
13
17
|
lib/pwnage/base.rb
|
18
|
+
lib/pwnage/config/app.rb
|
14
19
|
lib/pwnage/config/main.rb
|
20
|
+
lib/pwnage/config/paths.rb
|
21
|
+
lib/pwnage/config/ports.rb
|
22
|
+
lib/pwnage/config/repository.rb
|
23
|
+
lib/pwnage/dev_executor.rb
|
15
24
|
lib/pwnage/executor.rb
|
25
|
+
lib/pwnage/scaffolds/config.rb
|
16
26
|
lib/pwnage/scaffolds/dirs.rb
|
17
27
|
lib/pwnage/scaffolds/gems.rb
|
18
28
|
lib/pwnage/scaffolds/hook_dyndns.rb
|
@@ -23,5 +33,6 @@ lib/pwnage/scaffolds/rubygems.rb
|
|
23
33
|
lib/rails_pwnage.rb
|
24
34
|
LICENSE
|
25
35
|
Manifest
|
36
|
+
Rakefile
|
26
37
|
README
|
27
38
|
RUBYFORGE
|
data/bin/rpwn
CHANGED
data/bin/rpwndev
ADDED
@@ -75,6 +75,12 @@ class RailsPwnage::App::ClusterConfig
|
|
75
75
|
# silently die if the app was completely busted
|
76
76
|
return unless app_config and File.exists? app_config[:app_path]
|
77
77
|
|
78
|
+
# alloc a port if somehow that slipped through the cracks
|
79
|
+
if app_config[:port0] == 0
|
80
|
+
manage_ports app_name, instance_name, :alloc
|
81
|
+
configure_mongrels app_name, instance_name
|
82
|
+
end
|
83
|
+
|
78
84
|
Dir.chdir app_config[:app_path] do
|
79
85
|
system 'mongrel_rails cluster::start'
|
80
86
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# syncs the app's internal configuration with the configuration database
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
class RailsPwnage::App::Config
|
5
|
+
include RailsPwnage::Base
|
6
|
+
|
7
|
+
# allocates room for the application and creates the application configuration database
|
8
|
+
def alloc(app_name, instance_name)
|
9
|
+
app_path = File.join(RailsPwnage::Config.path_to(:apps), app_name + '.' + instance_name)
|
10
|
+
FileUtils.mkpath app_path
|
11
|
+
|
12
|
+
app_db_name = RailsPwnage::Config.app_db_name(app_name, instance_name)
|
13
|
+
app_db = RailsPwnage::Config.create_db app_db_name
|
14
|
+
|
15
|
+
# default settings
|
16
|
+
|
17
|
+
app_db[:app_path] = app_path
|
18
|
+
app_db[:backup_path] = File.join(RailsPwnage::Config.path_to(:backups), app_name + '.' + instance_name)
|
19
|
+
|
20
|
+
# the user which will receive the "keys" to the production system
|
21
|
+
app_db[:pwnerer_user] = 'victor'
|
22
|
+
# the number of mongrel instances for the application instance
|
23
|
+
app_db[:mongrels] = 4
|
24
|
+
# the first internal port for the application instance
|
25
|
+
app_db[:port0] = 0 # will be overwritten during allocation
|
26
|
+
# the name of the database for the application instance
|
27
|
+
app_db[:db_name] = app_name + '_' + instance_name + '_prod'
|
28
|
+
# the datbase user for the given application
|
29
|
+
app_db[:db_user] = (app_name + '_' + instance_name)[0...16] # mySQL doesn't like long user names
|
30
|
+
# the password of the database user for the given application
|
31
|
+
app_db[:db_pass] = instance_name # TODO: use random number generator here instead
|
32
|
+
# a DNS name for server-based filtering (multiple apps on the same box)
|
33
|
+
app_db[:dns_name] = ''
|
34
|
+
# the maximum request size (megabytes) to be accepted by an application
|
35
|
+
app_db[:max_request_mb] = 48
|
36
|
+
|
37
|
+
RailsPwnage::Config.flush_db app_db
|
38
|
+
return app_path
|
39
|
+
end
|
40
|
+
|
41
|
+
# pushes config changes from the application file to the database
|
42
|
+
def update(app_name, instance_name)
|
43
|
+
app_config = RailsPwnage::Config[app_name, instance_name]
|
44
|
+
Dir.chdir app_config[:app_path] do
|
45
|
+
["config/rails_pwnerer/.yml", "config/rails_pwnerer/#{instance_name}.yml"].each do |fname|
|
46
|
+
next unless File.exists? fname
|
47
|
+
config_update = File.open(fname, 'r') { |f| YAML.load f }
|
48
|
+
config_update.each do |key, value|
|
49
|
+
app_config[key] = value
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
RailsPwnage::Config.flush_db RailsPwnage::Config.app_db_name(app_name, instance_name)
|
54
|
+
end
|
55
|
+
|
56
|
+
def setup(app_name, instance_name)
|
57
|
+
update app_name, instance_name
|
58
|
+
end
|
59
|
+
|
60
|
+
def remove(app_name, instance_name)
|
61
|
+
app_db_name = RailsPwnage::Config.app_db_name(app_name, instance_name)
|
62
|
+
RailsPwnage::Config.drop_db app_db_name
|
63
|
+
end
|
64
|
+
end
|
data/lib/pwnage/app/main.rb
CHANGED
@@ -38,7 +38,7 @@ module RailsPwnage::App
|
|
38
38
|
# removes an application (and stops its servers)
|
39
39
|
def self.remove(app_name, instance_name)
|
40
40
|
instance_magic(app_name, instance_name) do |app, instance|
|
41
|
-
[
|
41
|
+
[NginxConfig, ClusterConfig, Database, Svn, Config].each do |mod|
|
42
42
|
mod.new.remove app, instance
|
43
43
|
end
|
44
44
|
end
|
@@ -7,7 +7,7 @@ class RailsPwnage::App::NginxConfig
|
|
7
7
|
def config_nginx(app_name, instance_name)
|
8
8
|
app_config = RailsPwnage::Config[app_name, instance_name]
|
9
9
|
first_port = app_config[:port0]
|
10
|
-
|
10
|
+
dns_name = app_config[:dns_name]
|
11
11
|
|
12
12
|
nginx_config = File.join(RailsPwnage::Config.path_to(:nginx_configs), app_name + '.' + instance_name)
|
13
13
|
File.open(nginx_config, 'w') do |f|
|
@@ -22,7 +22,7 @@ class RailsPwnage::App::NginxConfig
|
|
22
22
|
f << <<NGINX_CONFIG
|
23
23
|
server {
|
24
24
|
listen 80;
|
25
|
-
#{(
|
25
|
+
#{(dns_name.empty? ? '' : "server_name " + dns_name + ";")}
|
26
26
|
root #{app_config[:app_path]};
|
27
27
|
client_max_body_size #{app_config[:max_request_mb]}M;
|
28
28
|
location / {
|
@@ -64,6 +64,11 @@ NGINX_CONFIG
|
|
64
64
|
remove_nginx_stub
|
65
65
|
end
|
66
66
|
|
67
|
+
def update(app_name, instance_name)
|
68
|
+
config_nginx app_name, instance_name
|
69
|
+
control_boot_script('nginx', :reload)
|
70
|
+
end
|
71
|
+
|
67
72
|
def remove(app_name, instance_name)
|
68
73
|
remove_nginx_config app_name, instance_name
|
69
74
|
end
|
@@ -77,9 +82,5 @@ NGINX_CONFIG
|
|
77
82
|
when :reload
|
78
83
|
control_boot_script('nginx', :reload)
|
79
84
|
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def update(app_name, instance_name)
|
83
|
-
# nothing to do here, unless we enable config rewriting
|
84
85
|
end
|
85
86
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# extends Base with atomic read/write functions
|
2
|
+
|
3
|
+
require 'digest/md5'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
module RailsPwnage::Base
|
8
|
+
# reads the content of one file
|
9
|
+
# returns nil if the file is corrupted, otherwise returns [file data, timestamp]
|
10
|
+
def atomic_read_internal(file_name)
|
11
|
+
begin
|
12
|
+
raw_data = File.open(file_name, 'r') { |f| YAML::load f }
|
13
|
+
ts_checksum = Digest::MD5.hexdigest("#{raw_data[1]}.#{raw_data[2]}")
|
14
|
+
return [nil, Time.at(0, 0)] unless ts_checksum == raw_data[3]
|
15
|
+
return [raw_data[0], Time.at(raw_data[1], raw_data[2])]
|
16
|
+
rescue
|
17
|
+
# fail if the YAML can't be processed or something else goes wrong
|
18
|
+
return [nil, Time.at(0, 0)]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
private :atomic_read_internal
|
22
|
+
|
23
|
+
# reads the data in a repository
|
24
|
+
def atomic_read(path, name)
|
25
|
+
main_file = File.join(path, name) + '.yml'
|
26
|
+
dup_file = File.join(path, name) + '.yml2'
|
27
|
+
|
28
|
+
# choose the single good file or, if both are good, use the latest timestamp
|
29
|
+
# this works as long as the time on a box doesn't go back (it's ok to have it skewed)
|
30
|
+
results = [main_file, dup_file].map { |file| atomic_read_internal file }
|
31
|
+
results.sort { |a, b| b[1] <=> a[1] }
|
32
|
+
return results.first[0]
|
33
|
+
end
|
34
|
+
|
35
|
+
# writes data to a repository
|
36
|
+
def atomic_write(data, path, name)
|
37
|
+
main_file = File.join(path, name) + '.yml'
|
38
|
+
dup_file = File.join(path, name) + '.yml2'
|
39
|
+
|
40
|
+
# append verification info at the end of the file to guard from incomplete writes
|
41
|
+
ts = Time.now
|
42
|
+
ts_checksum = Digest::MD5.hexdigest("#{ts.tv_sec}.#{ts.tv_usec}")
|
43
|
+
File.open(dup_file, 'w') { |f| YAML::dump [data, ts.tv_sec, ts.tv_usec, ts_checksum], f }
|
44
|
+
|
45
|
+
# move the file atomically to the main copy
|
46
|
+
FileUtils.mv(dup_file, main_file)
|
47
|
+
end
|
48
|
+
|
49
|
+
# erases a repository
|
50
|
+
def atomic_erase(path, name)
|
51
|
+
main_file = File.join(path, name) + '.yml'
|
52
|
+
dup_file = File.join(path, name) + '.yml2'
|
53
|
+
[main_file, dup_file].each do |file|
|
54
|
+
File.delete file if File.exists? file
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# application-specific configuration functions
|
2
|
+
|
3
|
+
module RailsPwnage::Config
|
4
|
+
# the name of the database storing an app's configuration
|
5
|
+
def self.app_db_name(app_name, instance_name)
|
6
|
+
return "#{app_name}.#{instance_name}"
|
7
|
+
end
|
8
|
+
|
9
|
+
# the instances of an application installed on this box
|
10
|
+
def self.app_instances(app_name)
|
11
|
+
self.databases().filter { |db| db.include? ?. }.map { |db| db[0..(db.rindex ?.)] }
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# important paths in the filesystem
|
2
|
+
|
3
|
+
module RailsPwnage::Config
|
4
|
+
# the path to something important (e.g. :apps --> path to all production applications)
|
5
|
+
def self.path_to(what = :prod, app_name = nil)
|
6
|
+
# need to hardcode path to config to avoid endless recursion
|
7
|
+
if what == :config
|
8
|
+
return '/prod/config/'
|
9
|
+
end
|
10
|
+
|
11
|
+
# first try the paths in the database
|
12
|
+
return self[:paths][what] if self[:paths] and self[:paths].has_key? what
|
13
|
+
|
14
|
+
# then try the global paths
|
15
|
+
static_path = static_path_to what
|
16
|
+
return static_path unless static_path.nil?
|
17
|
+
end
|
18
|
+
|
19
|
+
# hardcoded paths
|
20
|
+
def self.static_path_to(what)
|
21
|
+
case what
|
22
|
+
when :config
|
23
|
+
# the directory containing the config files
|
24
|
+
'/prod/config'
|
25
|
+
when :prod
|
26
|
+
# the directory containing all the production data
|
27
|
+
'/prod'
|
28
|
+
when :apps
|
29
|
+
# the directory containing the production apps
|
30
|
+
'/prod/apps'
|
31
|
+
when :backups
|
32
|
+
'/prod/backups'
|
33
|
+
else
|
34
|
+
return
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# keeps track of the available ports on the machine
|
2
|
+
|
3
|
+
module RailsPwnage::Config
|
4
|
+
def self.init_ports(free_ports = [[8000, 16000]])
|
5
|
+
self.create_db :free_ports
|
6
|
+
self[:free_ports][:list] = free_ports
|
7
|
+
self.flush_db :free_ports
|
8
|
+
end
|
9
|
+
|
10
|
+
# allocates a contiguous range of ports
|
11
|
+
# returns the starting port or nil
|
12
|
+
def self.alloc_ports(nports = 1)
|
13
|
+
free_ports = self[:free_ports][:list]
|
14
|
+
free_ports.each_index do |i|
|
15
|
+
next if free_ports[i][1] - free_ports[i][0] < nports
|
16
|
+
first_port = free_ports[i][0]
|
17
|
+
free_ports[i][0] += nports
|
18
|
+
free_ports.delete_at i if free_ports[i][0] == free_ports[i][1]
|
19
|
+
self[:free_ports][:list] = free_ports
|
20
|
+
self.flush_db :free_ports
|
21
|
+
return first_port
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# returns a continuous range of ports to the free list
|
26
|
+
def self.free_ports(start, count = 1)
|
27
|
+
free_ports = self[:free_ports][:list]
|
28
|
+
free_ports << [start, start + count]
|
29
|
+
|
30
|
+
# concatenate duplicates
|
31
|
+
free_ports.sort! { |a, b| a[0] <=> b[0]}
|
32
|
+
new_ports = [free_ports.first]
|
33
|
+
free_ports.each_index do |i|
|
34
|
+
if new_ports.last[1] >= free_ports[i][0]
|
35
|
+
new_ports.last[1] = [new_ports.last[1], free_ports[i][1]].max
|
36
|
+
else
|
37
|
+
new_ports << free_ports[i]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# write the new database
|
42
|
+
self[:free_ports][:list] = new_ports
|
43
|
+
self.flush_db :free_ports
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# implements the configuration repository
|
2
|
+
|
3
|
+
module RailsPwnage::Config
|
4
|
+
class << self
|
5
|
+
include RailsPwnage::Base
|
6
|
+
end
|
7
|
+
|
8
|
+
# maps each database name to its contents
|
9
|
+
@@db_cache = Hash.new
|
10
|
+
# maps each database name to its dirty flag
|
11
|
+
@@db_dirty = Hash.new
|
12
|
+
|
13
|
+
# called when a database is dirty
|
14
|
+
def self.mark_db_dirty(db_name)
|
15
|
+
@@db_dirty[db_name] = true
|
16
|
+
end
|
17
|
+
|
18
|
+
# installs the database hooks into a Hash
|
19
|
+
def self.install_db_hooks(db_contents, db_name)
|
20
|
+
# hooks:
|
21
|
+
# (1) automatically convert keys to strings
|
22
|
+
# (2) flip the dirty flag on writes
|
23
|
+
class << db_contents
|
24
|
+
def [](key)
|
25
|
+
super(key.to_s)
|
26
|
+
end
|
27
|
+
def []=(key, value)
|
28
|
+
super(key.to_s, value)
|
29
|
+
RailsPwnage::Config.mark_db_dirty @db_name
|
30
|
+
end
|
31
|
+
def has_key?(key)
|
32
|
+
super(key.to_s)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
db_contents.instance_variable_set :@db_name, db_name
|
36
|
+
return db_contents
|
37
|
+
end
|
38
|
+
|
39
|
+
# creates a new database
|
40
|
+
def self.create_db(db_name)
|
41
|
+
db_name = db_name.to_s
|
42
|
+
raise "Configuration database #{db_name} already exists" if get_db(db_name)
|
43
|
+
|
44
|
+
db_contents = install_db_hooks Hash.new, db_name
|
45
|
+
@@db_cache[db_name] = db_contents
|
46
|
+
@@db_dirty[db_name] = true
|
47
|
+
flush_db db_name
|
48
|
+
return db_contents
|
49
|
+
end
|
50
|
+
|
51
|
+
# drops a database
|
52
|
+
def self.drop_db(db_name)
|
53
|
+
@@db_cache[db_name] = nil
|
54
|
+
@@db_dirty[db_name] = true
|
55
|
+
flush_db db_name
|
56
|
+
end
|
57
|
+
|
58
|
+
# retrieves the contents of a db (from cache if necessary)
|
59
|
+
def self.get_db(db_name)
|
60
|
+
db_name = db_name.to_s
|
61
|
+
unless @@db_cache.has_key? db_name
|
62
|
+
db_path = RailsPwnage::Config.path_to :config
|
63
|
+
db_contents = atomic_read(db_path, db_name)
|
64
|
+
|
65
|
+
if db_contents.nil?
|
66
|
+
@@db_cache[db_name] = nil
|
67
|
+
else
|
68
|
+
@@db_cache[db_name] = install_db_hooks db_contents, db_name
|
69
|
+
end
|
70
|
+
@@db_dirty[db_name] = false
|
71
|
+
end
|
72
|
+
|
73
|
+
return @@db_cache[db_name]
|
74
|
+
end
|
75
|
+
|
76
|
+
# flushes the contents of the given db from cache
|
77
|
+
def self.flush_db(db_name)
|
78
|
+
db_name = db_name.to_s
|
79
|
+
return unless @@db_dirty[db_name]
|
80
|
+
db_path = RailsPwnage::Config.path_to :config
|
81
|
+
if @@db_cache[db_name].nil?
|
82
|
+
atomic_erase db_path, db_name
|
83
|
+
else
|
84
|
+
atomic_write @@db_cache[db_name], db_path, db_name
|
85
|
+
end
|
86
|
+
@@db_dirty[db_name] = false
|
87
|
+
end
|
88
|
+
|
89
|
+
# flushes the entire database cache (used when exiting)
|
90
|
+
def self.flush_db_cache
|
91
|
+
@@db_dirty.each do |db_name, is_dirty|
|
92
|
+
next unless is_dirty
|
93
|
+
flush_db db_name
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# override [] to make the global DB look like a Hash
|
98
|
+
def self.[](db_or_app_name, instance_name = nil)
|
99
|
+
if instance_name.nil?
|
100
|
+
db_name = db_or_app_name
|
101
|
+
else
|
102
|
+
db_name = app_db_name(db_or_app_name, instance_name)
|
103
|
+
end
|
104
|
+
get_db(db_name)
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.databases()
|
108
|
+
entries = Dir.entries RailsPwnage::Config.path_to(:config)
|
109
|
+
databases = []
|
110
|
+
entries.each do |entry|
|
111
|
+
next unless entry =~ /\.yml(2)?$/
|
112
|
+
databases << entry.gsub(/\.yml(2)?$/, '')
|
113
|
+
end
|
114
|
+
return databases
|
115
|
+
end
|
116
|
+
|
117
|
+
# ensures all databases are flushed when the script exits
|
118
|
+
Kernel.at_exit { RailsPwnage::Config.flush_db_cache }
|
119
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'pp'
|
2
|
+
|
3
|
+
class RailsPwnage::DevExecutor
|
4
|
+
# check if we're at the root of a Rails application
|
5
|
+
def at_app_root()
|
6
|
+
['app', 'config', 'db', 'lib', 'log', 'public',
|
7
|
+
'script', 'tmp', 'vendor', 'Rakefile'].all? { |dir| File.exists? dir }
|
8
|
+
end
|
9
|
+
|
10
|
+
def read_config(instance)
|
11
|
+
if instance == '*'
|
12
|
+
file = File.join(@config_root, '.yml')
|
13
|
+
else
|
14
|
+
file = File.join(@config_root, instance + '.yml')
|
15
|
+
end
|
16
|
+
|
17
|
+
begin
|
18
|
+
File.open(file, 'r' ) { |f| YAML.load f }
|
19
|
+
rescue
|
20
|
+
return Hash.new
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def write_config(config, instance)
|
25
|
+
if instance == '*'
|
26
|
+
file = File.join(@config_root, '.yml')
|
27
|
+
else
|
28
|
+
file = File.join(@config_root, instance + '.yml')
|
29
|
+
end
|
30
|
+
|
31
|
+
File.open(file, 'w') { |f| YAML.dump config, f }
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
# standalone runner
|
36
|
+
def run(args)
|
37
|
+
unless at_app_root
|
38
|
+
print "You need to run this at the root of your Rails application\n"
|
39
|
+
return
|
40
|
+
end
|
41
|
+
|
42
|
+
# create the config root unless it exists
|
43
|
+
@config_root = 'config/rails_pwnerer'
|
44
|
+
Dir.mkdir @config_root unless File.exists? @config_root
|
45
|
+
|
46
|
+
case args[0]
|
47
|
+
when 'get', 'getprop'
|
48
|
+
property = args[1]
|
49
|
+
instance = args[2] || '*'
|
50
|
+
config = read_config instance
|
51
|
+
pp config[property]
|
52
|
+
|
53
|
+
when 'set', 'setprop', 'setnum', 'setpropnum'
|
54
|
+
property = args[1]
|
55
|
+
if args[0].index 'num'
|
56
|
+
value = eval(args[2] || '1')
|
57
|
+
else
|
58
|
+
value = args[2] || 'true'
|
59
|
+
end
|
60
|
+
|
61
|
+
instance = args[3] || '*'
|
62
|
+
config = read_config instance
|
63
|
+
config[property] = value
|
64
|
+
write_config config, instance
|
65
|
+
|
66
|
+
when 'del', 'delprop', 'delete', 'rm', 'remove'
|
67
|
+
property = args[1]
|
68
|
+
instance = args[2] || '*'
|
69
|
+
config = read_config instance
|
70
|
+
config.delete property
|
71
|
+
write_config config, instance
|
72
|
+
|
73
|
+
else
|
74
|
+
print "Unrecognized command #{args[0]}\n"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/lib/pwnage/executor.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
# sets up the configuration repository
|
2
|
+
|
3
|
+
class RailsPwnage::Scaffolds::Config
|
4
|
+
include RailsPwnage::Base
|
5
|
+
|
6
|
+
# runner
|
7
|
+
def run
|
8
|
+
# paths
|
9
|
+
paths_db = RailsPwnage::Config.create_db :paths
|
10
|
+
# the directory containing the mongrel_cluster config files
|
11
|
+
paths_db[:mongrel_configs] = '/etc/mongrel_cluster'
|
12
|
+
# the directory containing the nginx config files
|
13
|
+
paths_db[:nginx_configs] = '/etc/nginx/sites-enabled'
|
14
|
+
# the directory containing the ddclient configuration
|
15
|
+
paths_db[:ddclient_config] = '/etc/ddclient.conf'
|
16
|
+
RailsPwnage::Config.flush_db :paths
|
17
|
+
|
18
|
+
# host info
|
19
|
+
host_info = RailsPwnage::Config.create_db :host
|
20
|
+
# the default instance name
|
21
|
+
host_info[:instance] = Socket.gethostname()
|
22
|
+
# the computer's name (if we ever do status reports)
|
23
|
+
host_info[:name] = Socket.gethostname()
|
24
|
+
# username for creating / dropping databases
|
25
|
+
host_info[:dbroot_name] = 'root'
|
26
|
+
# password for creating / dropping databases
|
27
|
+
host_info[:dbroot_pass] = ''
|
28
|
+
|
29
|
+
RailsPwnage::Config.flush_db :host
|
30
|
+
|
31
|
+
# the free port list
|
32
|
+
RailsPwnage::Config.init_ports
|
33
|
+
end
|
34
|
+
|
35
|
+
# standalone runner
|
36
|
+
def self.go
|
37
|
+
self.new.run
|
38
|
+
end
|
39
|
+
end
|
data/lib/rails_pwnage.rb
CHANGED
@@ -25,8 +25,6 @@ require 'pwnage/config/paths.rb'
|
|
25
25
|
require 'pwnage/config/ports.rb'
|
26
26
|
require 'pwnage/config/repository.rb'
|
27
27
|
|
28
|
-
require 'pwnage/executor.rb'
|
29
|
-
|
30
28
|
require 'pwnage/scaffolds/config.rb'
|
31
29
|
require 'pwnage/scaffolds/dirs.rb'
|
32
30
|
require 'pwnage/scaffolds/gems.rb'
|
@@ -43,3 +41,6 @@ require 'pwnage/app/database.rb'
|
|
43
41
|
require 'pwnage/app/gems.rb'
|
44
42
|
require 'pwnage/app/nginx_config.rb'
|
45
43
|
require 'pwnage/app/svn.rb'
|
44
|
+
|
45
|
+
require 'pwnage/dev_executor.rb'
|
46
|
+
require 'pwnage/executor.rb'
|
data/rails_pwnerer.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
|
2
|
-
# Gem::Specification for Rails_pwnerer-0.5.
|
2
|
+
# Gem::Specification for Rails_pwnerer-0.5.2
|
3
3
|
# Originally generated by Echoe
|
4
4
|
|
5
5
|
--- !ruby/object:Gem::Specification
|
6
6
|
name: rails_pwnerer
|
7
7
|
version: !ruby/object:Gem::Version
|
8
|
-
version: 0.5.
|
8
|
+
version: 0.5.2
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- Victor Costan
|
@@ -29,24 +29,35 @@ description: Rails deployment tool/hack.
|
|
29
29
|
email: victor@costan.us
|
30
30
|
executables:
|
31
31
|
- rpwn
|
32
|
+
- rpwndev
|
32
33
|
extensions: []
|
33
34
|
|
34
35
|
extra_rdoc_files:
|
35
36
|
- bin/rpwn
|
37
|
+
- bin/rpwndev
|
36
38
|
- CHANGELOG
|
37
39
|
- lib/pwnage/app/cluster_config.rb
|
40
|
+
- lib/pwnage/app/config.rb
|
38
41
|
- lib/pwnage/app/database.rb
|
39
42
|
- lib/pwnage/app/gems.rb
|
40
43
|
- lib/pwnage/app/main.rb
|
41
44
|
- lib/pwnage/app/nginx_config.rb
|
42
45
|
- lib/pwnage/app/svn.rb
|
46
|
+
- lib/pwnage/base/atomics.rb
|
43
47
|
- lib/pwnage/base/dirs.rb
|
44
48
|
- lib/pwnage/base/gems.rb
|
49
|
+
- lib/pwnage/base/hostname.rb
|
45
50
|
- lib/pwnage/base/packages.rb
|
46
51
|
- lib/pwnage/base/startup.rb
|
47
52
|
- lib/pwnage/base.rb
|
53
|
+
- lib/pwnage/config/app.rb
|
48
54
|
- lib/pwnage/config/main.rb
|
55
|
+
- lib/pwnage/config/paths.rb
|
56
|
+
- lib/pwnage/config/ports.rb
|
57
|
+
- lib/pwnage/config/repository.rb
|
58
|
+
- lib/pwnage/dev_executor.rb
|
49
59
|
- lib/pwnage/executor.rb
|
60
|
+
- lib/pwnage/scaffolds/config.rb
|
50
61
|
- lib/pwnage/scaffolds/dirs.rb
|
51
62
|
- lib/pwnage/scaffolds/gems.rb
|
52
63
|
- lib/pwnage/scaffolds/hook_dyndns.rb
|
@@ -59,20 +70,30 @@ extra_rdoc_files:
|
|
59
70
|
- README
|
60
71
|
files:
|
61
72
|
- bin/rpwn
|
73
|
+
- bin/rpwndev
|
62
74
|
- CHANGELOG
|
63
75
|
- lib/pwnage/app/cluster_config.rb
|
76
|
+
- lib/pwnage/app/config.rb
|
64
77
|
- lib/pwnage/app/database.rb
|
65
78
|
- lib/pwnage/app/gems.rb
|
66
79
|
- lib/pwnage/app/main.rb
|
67
80
|
- lib/pwnage/app/nginx_config.rb
|
68
81
|
- lib/pwnage/app/svn.rb
|
82
|
+
- lib/pwnage/base/atomics.rb
|
69
83
|
- lib/pwnage/base/dirs.rb
|
70
84
|
- lib/pwnage/base/gems.rb
|
85
|
+
- lib/pwnage/base/hostname.rb
|
71
86
|
- lib/pwnage/base/packages.rb
|
72
87
|
- lib/pwnage/base/startup.rb
|
73
88
|
- lib/pwnage/base.rb
|
89
|
+
- lib/pwnage/config/app.rb
|
74
90
|
- lib/pwnage/config/main.rb
|
91
|
+
- lib/pwnage/config/paths.rb
|
92
|
+
- lib/pwnage/config/ports.rb
|
93
|
+
- lib/pwnage/config/repository.rb
|
94
|
+
- lib/pwnage/dev_executor.rb
|
75
95
|
- lib/pwnage/executor.rb
|
96
|
+
- lib/pwnage/scaffolds/config.rb
|
76
97
|
- lib/pwnage/scaffolds/dirs.rb
|
77
98
|
- lib/pwnage/scaffolds/gems.rb
|
78
99
|
- lib/pwnage/scaffolds/hook_dyndns.rb
|
@@ -83,10 +104,10 @@ files:
|
|
83
104
|
- lib/rails_pwnage.rb
|
84
105
|
- LICENSE
|
85
106
|
- Manifest
|
107
|
+
- Rakefile
|
86
108
|
- README
|
87
109
|
- RUBYFORGE
|
88
110
|
- rails_pwnerer.gemspec
|
89
|
-
- Rakefile
|
90
111
|
has_rdoc: true
|
91
112
|
homepage: http://www.costan.us/rails_pwnage
|
92
113
|
post_install_message:
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_pwnerer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Costan
|
@@ -26,24 +26,35 @@ description: Rails deployment tool/hack.
|
|
26
26
|
email: victor@costan.us
|
27
27
|
executables:
|
28
28
|
- rpwn
|
29
|
+
- rpwndev
|
29
30
|
extensions: []
|
30
31
|
|
31
32
|
extra_rdoc_files:
|
32
33
|
- bin/rpwn
|
34
|
+
- bin/rpwndev
|
33
35
|
- CHANGELOG
|
34
36
|
- lib/pwnage/app/cluster_config.rb
|
37
|
+
- lib/pwnage/app/config.rb
|
35
38
|
- lib/pwnage/app/database.rb
|
36
39
|
- lib/pwnage/app/gems.rb
|
37
40
|
- lib/pwnage/app/main.rb
|
38
41
|
- lib/pwnage/app/nginx_config.rb
|
39
42
|
- lib/pwnage/app/svn.rb
|
43
|
+
- lib/pwnage/base/atomics.rb
|
40
44
|
- lib/pwnage/base/dirs.rb
|
41
45
|
- lib/pwnage/base/gems.rb
|
46
|
+
- lib/pwnage/base/hostname.rb
|
42
47
|
- lib/pwnage/base/packages.rb
|
43
48
|
- lib/pwnage/base/startup.rb
|
44
49
|
- lib/pwnage/base.rb
|
50
|
+
- lib/pwnage/config/app.rb
|
45
51
|
- lib/pwnage/config/main.rb
|
52
|
+
- lib/pwnage/config/paths.rb
|
53
|
+
- lib/pwnage/config/ports.rb
|
54
|
+
- lib/pwnage/config/repository.rb
|
55
|
+
- lib/pwnage/dev_executor.rb
|
46
56
|
- lib/pwnage/executor.rb
|
57
|
+
- lib/pwnage/scaffolds/config.rb
|
47
58
|
- lib/pwnage/scaffolds/dirs.rb
|
48
59
|
- lib/pwnage/scaffolds/gems.rb
|
49
60
|
- lib/pwnage/scaffolds/hook_dyndns.rb
|
@@ -56,20 +67,30 @@ extra_rdoc_files:
|
|
56
67
|
- README
|
57
68
|
files:
|
58
69
|
- bin/rpwn
|
70
|
+
- bin/rpwndev
|
59
71
|
- CHANGELOG
|
60
72
|
- lib/pwnage/app/cluster_config.rb
|
73
|
+
- lib/pwnage/app/config.rb
|
61
74
|
- lib/pwnage/app/database.rb
|
62
75
|
- lib/pwnage/app/gems.rb
|
63
76
|
- lib/pwnage/app/main.rb
|
64
77
|
- lib/pwnage/app/nginx_config.rb
|
65
78
|
- lib/pwnage/app/svn.rb
|
79
|
+
- lib/pwnage/base/atomics.rb
|
66
80
|
- lib/pwnage/base/dirs.rb
|
67
81
|
- lib/pwnage/base/gems.rb
|
82
|
+
- lib/pwnage/base/hostname.rb
|
68
83
|
- lib/pwnage/base/packages.rb
|
69
84
|
- lib/pwnage/base/startup.rb
|
70
85
|
- lib/pwnage/base.rb
|
86
|
+
- lib/pwnage/config/app.rb
|
71
87
|
- lib/pwnage/config/main.rb
|
88
|
+
- lib/pwnage/config/paths.rb
|
89
|
+
- lib/pwnage/config/ports.rb
|
90
|
+
- lib/pwnage/config/repository.rb
|
91
|
+
- lib/pwnage/dev_executor.rb
|
72
92
|
- lib/pwnage/executor.rb
|
93
|
+
- lib/pwnage/scaffolds/config.rb
|
73
94
|
- lib/pwnage/scaffolds/dirs.rb
|
74
95
|
- lib/pwnage/scaffolds/gems.rb
|
75
96
|
- lib/pwnage/scaffolds/hook_dyndns.rb
|
@@ -80,10 +101,10 @@ files:
|
|
80
101
|
- lib/rails_pwnage.rb
|
81
102
|
- LICENSE
|
82
103
|
- Manifest
|
104
|
+
- Rakefile
|
83
105
|
- README
|
84
106
|
- RUBYFORGE
|
85
107
|
- rails_pwnerer.gemspec
|
86
|
-
- Rakefile
|
87
108
|
has_rdoc: true
|
88
109
|
homepage: http://www.costan.us/rails_pwnage
|
89
110
|
post_install_message:
|