rails_pwnerer 0.6.64 → 0.6.65
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/LICENSE +0 -0
- data/Manifest +51 -49
- data/README +0 -0
- data/RUBYFORGE +0 -0
- data/Rakefile +7 -11
- data/ext/rpwn_setup_notice/extconf.rb +24 -16
- data/lib/{pwnage → rails_pwnerer}/app/cluster_config.rb +17 -17
- data/lib/{pwnage → rails_pwnerer}/app/config.rb +14 -14
- data/lib/{pwnage → rails_pwnerer}/app/db/mysql.rb +9 -9
- data/lib/{pwnage → rails_pwnerer}/app/files.rb +13 -13
- data/lib/{pwnage → rails_pwnerer}/app/gems.rb +3 -3
- data/lib/{pwnage → rails_pwnerer}/app/main.rb +4 -4
- data/lib/{pwnage → rails_pwnerer}/app/nginx_config.rb +7 -7
- data/lib/{pwnage → rails_pwnerer}/app/scripts.rb +4 -4
- data/lib/{pwnage → rails_pwnerer}/app/vcs/git.rb +9 -9
- data/lib/{pwnage → rails_pwnerer}/app/vcs/perforce.rb +11 -11
- data/lib/{pwnage → rails_pwnerer}/app/vcs/svn.rb +9 -9
- data/lib/{pwnage → rails_pwnerer}/base/atomics.rb +1 -1
- data/lib/{pwnage → rails_pwnerer}/base/cpus.rb +1 -1
- data/lib/{pwnage → rails_pwnerer}/base/dirs.rb +1 -1
- data/lib/{pwnage → rails_pwnerer}/base/gems.rb +2 -2
- data/lib/{pwnage → rails_pwnerer}/base/hostname.rb +1 -1
- data/lib/{pwnage → rails_pwnerer}/base/input.rb +1 -1
- data/lib/rails_pwnerer/base/packages.rb +272 -0
- data/lib/{pwnage → rails_pwnerer}/base/process.rb +1 -1
- data/lib/{pwnage → rails_pwnerer}/base/rails.rb +1 -1
- data/lib/{pwnage → rails_pwnerer}/base/startup.rb +1 -1
- data/lib/{pwnage → rails_pwnerer}/base.rb +1 -1
- data/lib/{pwnage → rails_pwnerer}/config/app.rb +1 -1
- data/lib/{pwnage → rails_pwnerer}/config/frontends.rb +1 -1
- data/lib/rails_pwnerer/config/main.rb +3 -0
- data/lib/{pwnage → rails_pwnerer}/config/paths.rb +1 -1
- data/lib/{pwnage → rails_pwnerer}/config/ports.rb +1 -1
- data/lib/{pwnage → rails_pwnerer}/config/repository.rb +7 -7
- data/lib/rails_pwnerer/ctl_executor.rb +19 -0
- data/lib/{pwnage → rails_pwnerer}/dev_executor.rb +2 -2
- data/lib/{pwnage → rails_pwnerer}/executor.rb +17 -17
- data/lib/{pwnage → rails_pwnerer}/scaffolds/config.rb +7 -7
- data/lib/{pwnage → rails_pwnerer}/scaffolds/dir_permissions.rb +4 -4
- data/lib/{pwnage → rails_pwnerer}/scaffolds/dirs.rb +3 -3
- data/lib/{pwnage → rails_pwnerer}/scaffolds/gems.rb +2 -2
- data/lib/{pwnage → rails_pwnerer}/scaffolds/hook_daemon.rb +2 -2
- data/lib/{pwnage → rails_pwnerer}/scaffolds/hook_dyndns.rb +3 -3
- data/lib/{pwnage → rails_pwnerer}/scaffolds/mysql_config.rb +2 -2
- data/lib/rails_pwnerer/scaffolds/packages.rb +118 -0
- data/lib/{pwnage → rails_pwnerer}/scaffolds/rubygems.rb +2 -2
- data/lib/{pwnage → rails_pwnerer}/scaffolds/sshd.rb +2 -2
- data/lib/{pwnage → rails_pwnerer}/util/kill_process_set.rb +1 -1
- data/lib/rails_pwnerer/util/main.rb +5 -0
- data/lib/rails_pwnerer.rb +52 -52
- data/rails_pwnerer.gemspec +17 -7
- data/test/base_package_test.rb +126 -0
- data/test/helper.rb +25 -0
- metadata +151 -107
- data/lib/pwnage/base/packages.rb +0 -159
- data/lib/pwnage/config/main.rb +0 -3
- data/lib/pwnage/ctl_executor.rb +0 -19
- data/lib/pwnage/scaffolds/packages.rb +0 -110
- data/lib/pwnage/util/main.rb +0 -5
data/CHANGELOG
CHANGED
data/LICENSE
CHANGED
File without changes
|
data/Manifest
CHANGED
@@ -1,54 +1,56 @@
|
|
1
|
-
bin/rpwn
|
2
|
-
bin/rpwnctl
|
3
|
-
bin/rpwndev
|
4
1
|
CHANGELOG
|
5
|
-
ext/rpwn_setup_notice/extconf.rb
|
6
|
-
lib/pwnage/app/cluster_config.rb
|
7
|
-
lib/pwnage/app/config.rb
|
8
|
-
lib/pwnage/app/db/mysql.rb
|
9
|
-
lib/pwnage/app/files.rb
|
10
|
-
lib/pwnage/app/gems.rb
|
11
|
-
lib/pwnage/app/main.rb
|
12
|
-
lib/pwnage/app/nginx_config.rb
|
13
|
-
lib/pwnage/app/scripts.rb
|
14
|
-
lib/pwnage/app/vcs/git.rb
|
15
|
-
lib/pwnage/app/vcs/perforce.rb
|
16
|
-
lib/pwnage/app/vcs/svn.rb
|
17
|
-
lib/pwnage/base/atomics.rb
|
18
|
-
lib/pwnage/base/cpus.rb
|
19
|
-
lib/pwnage/base/dirs.rb
|
20
|
-
lib/pwnage/base/gems.rb
|
21
|
-
lib/pwnage/base/hostname.rb
|
22
|
-
lib/pwnage/base/input.rb
|
23
|
-
lib/pwnage/base/packages.rb
|
24
|
-
lib/pwnage/base/process.rb
|
25
|
-
lib/pwnage/base/rails.rb
|
26
|
-
lib/pwnage/base/startup.rb
|
27
|
-
lib/pwnage/base.rb
|
28
|
-
lib/pwnage/config/app.rb
|
29
|
-
lib/pwnage/config/frontends.rb
|
30
|
-
lib/pwnage/config/main.rb
|
31
|
-
lib/pwnage/config/paths.rb
|
32
|
-
lib/pwnage/config/ports.rb
|
33
|
-
lib/pwnage/config/repository.rb
|
34
|
-
lib/pwnage/ctl_executor.rb
|
35
|
-
lib/pwnage/dev_executor.rb
|
36
|
-
lib/pwnage/executor.rb
|
37
|
-
lib/pwnage/scaffolds/config.rb
|
38
|
-
lib/pwnage/scaffolds/dir_permissions.rb
|
39
|
-
lib/pwnage/scaffolds/dirs.rb
|
40
|
-
lib/pwnage/scaffolds/gems.rb
|
41
|
-
lib/pwnage/scaffolds/hook_daemon.rb
|
42
|
-
lib/pwnage/scaffolds/hook_dyndns.rb
|
43
|
-
lib/pwnage/scaffolds/mysql_config.rb
|
44
|
-
lib/pwnage/scaffolds/packages.rb
|
45
|
-
lib/pwnage/scaffolds/rubygems.rb
|
46
|
-
lib/pwnage/scaffolds/sshd.rb
|
47
|
-
lib/pwnage/util/kill_process_set.rb
|
48
|
-
lib/pwnage/util/main.rb
|
49
|
-
lib/rails_pwnerer.rb
|
50
2
|
LICENSE
|
51
3
|
Manifest
|
52
|
-
Rakefile
|
53
4
|
README
|
54
5
|
RUBYFORGE
|
6
|
+
Rakefile
|
7
|
+
bin/rpwn
|
8
|
+
bin/rpwnctl
|
9
|
+
bin/rpwndev
|
10
|
+
ext/rpwn_setup_notice/extconf.rb
|
11
|
+
lib/rails_pwnerer.rb
|
12
|
+
lib/rails_pwnerer/app/cluster_config.rb
|
13
|
+
lib/rails_pwnerer/app/config.rb
|
14
|
+
lib/rails_pwnerer/app/db/mysql.rb
|
15
|
+
lib/rails_pwnerer/app/files.rb
|
16
|
+
lib/rails_pwnerer/app/gems.rb
|
17
|
+
lib/rails_pwnerer/app/main.rb
|
18
|
+
lib/rails_pwnerer/app/nginx_config.rb
|
19
|
+
lib/rails_pwnerer/app/scripts.rb
|
20
|
+
lib/rails_pwnerer/app/vcs/git.rb
|
21
|
+
lib/rails_pwnerer/app/vcs/perforce.rb
|
22
|
+
lib/rails_pwnerer/app/vcs/svn.rb
|
23
|
+
lib/rails_pwnerer/base.rb
|
24
|
+
lib/rails_pwnerer/base/atomics.rb
|
25
|
+
lib/rails_pwnerer/base/cpus.rb
|
26
|
+
lib/rails_pwnerer/base/dirs.rb
|
27
|
+
lib/rails_pwnerer/base/gems.rb
|
28
|
+
lib/rails_pwnerer/base/hostname.rb
|
29
|
+
lib/rails_pwnerer/base/input.rb
|
30
|
+
lib/rails_pwnerer/base/packages.rb
|
31
|
+
lib/rails_pwnerer/base/process.rb
|
32
|
+
lib/rails_pwnerer/base/rails.rb
|
33
|
+
lib/rails_pwnerer/base/startup.rb
|
34
|
+
lib/rails_pwnerer/config/app.rb
|
35
|
+
lib/rails_pwnerer/config/frontends.rb
|
36
|
+
lib/rails_pwnerer/config/main.rb
|
37
|
+
lib/rails_pwnerer/config/paths.rb
|
38
|
+
lib/rails_pwnerer/config/ports.rb
|
39
|
+
lib/rails_pwnerer/config/repository.rb
|
40
|
+
lib/rails_pwnerer/ctl_executor.rb
|
41
|
+
lib/rails_pwnerer/dev_executor.rb
|
42
|
+
lib/rails_pwnerer/executor.rb
|
43
|
+
lib/rails_pwnerer/scaffolds/config.rb
|
44
|
+
lib/rails_pwnerer/scaffolds/dir_permissions.rb
|
45
|
+
lib/rails_pwnerer/scaffolds/dirs.rb
|
46
|
+
lib/rails_pwnerer/scaffolds/gems.rb
|
47
|
+
lib/rails_pwnerer/scaffolds/hook_daemon.rb
|
48
|
+
lib/rails_pwnerer/scaffolds/hook_dyndns.rb
|
49
|
+
lib/rails_pwnerer/scaffolds/mysql_config.rb
|
50
|
+
lib/rails_pwnerer/scaffolds/packages.rb
|
51
|
+
lib/rails_pwnerer/scaffolds/rubygems.rb
|
52
|
+
lib/rails_pwnerer/scaffolds/sshd.rb
|
53
|
+
lib/rails_pwnerer/util/kill_process_set.rb
|
54
|
+
lib/rails_pwnerer/util/main.rb
|
55
|
+
test/base_package_test.rb
|
56
|
+
test/helper.rb
|
data/README
CHANGED
File without changes
|
data/RUBYFORGE
CHANGED
File without changes
|
data/Rakefile
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
gem 'echoe'
|
3
2
|
require 'echoe'
|
4
3
|
|
5
4
|
Echoe.new('rails_pwnerer') do |p|
|
@@ -7,22 +6,19 @@ Echoe.new('rails_pwnerer') do |p|
|
|
7
6
|
|
8
7
|
p.author = 'Victor Costan'
|
9
8
|
p.email = 'victor@costan.us'
|
10
|
-
p.summary = 'Rails deployment
|
9
|
+
p.summary = 'Rails deployment hack.'
|
11
10
|
p.url = 'http://www.costan.us/rails_pwnage'
|
12
|
-
p.runtime_dependencies = []
|
13
11
|
p.dependencies = []
|
14
|
-
|
15
|
-
p.
|
16
|
-
# override echoe's default of 1.2
|
17
|
-
p.rubygems_version = '>= 0'
|
18
|
-
p.extensions = ['ext/rpwn_setup_notice/extconf.rb']
|
12
|
+
p.development_dependencies = ['echoe', 'fakefs', 'flexmock']
|
13
|
+
p.extension_pattern = ['ext/**/extconf.rb']
|
19
14
|
p.eval = proc do |p|
|
20
15
|
p.default_executable = 'bin/rpwn'
|
21
16
|
end
|
22
17
|
|
23
|
-
p.need_tar_gz =
|
24
|
-
p.need_zip =
|
25
|
-
p.rdoc_pattern =
|
18
|
+
p.need_tar_gz = !Gem.win_platform?
|
19
|
+
p.need_zip = !Gem.win_platform?
|
20
|
+
p.rdoc_pattern =
|
21
|
+
/^(lib|bin|tasks|ext)|^BUILD|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
|
26
22
|
end
|
27
23
|
|
28
24
|
if $0 == __FILE__
|
@@ -1,19 +1,25 @@
|
|
1
|
-
#
|
1
|
+
# Invoked when the gem is installed. Hack to get a post-install hook.
|
2
2
|
|
3
|
-
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
|
6
|
+
# Cheat to get the gem binaries installed in the user's path even on Debians.
|
4
7
|
['rpwn', 'rpwnctl', 'rpwndev'].each do |file|
|
5
|
-
|
6
|
-
unless File.exists?
|
7
|
-
|
8
|
+
bin_path = "/usr/bin/#{file}"
|
9
|
+
unless File.exists? bin_path
|
10
|
+
source_path = File.expand_path "../../../bin/#{file}", __FILE__
|
11
|
+
Kernel.system "ln -s #{source_path} #{bin_path}"
|
8
12
|
end
|
9
13
|
|
10
|
-
File.chmod((File.stat(binpath).mode | 0755), binpath)
|
14
|
+
File.chmod((File.stat(binpath).mode | 0755), binpath) rescue nil
|
11
15
|
end
|
12
16
|
|
13
|
-
#
|
17
|
+
# Make the gem readable and runnable by anyone.
|
18
|
+
#
|
19
|
+
# This is a work-around for systems with messed up permission masks.
|
14
20
|
def openup(path)
|
15
21
|
if File.file?(path)
|
16
|
-
File.chmod((File.stat(path).mode | 0755), path)
|
22
|
+
File.chmod((File.stat(path).mode | 0755), path) rescue nil
|
17
23
|
return
|
18
24
|
end
|
19
25
|
|
@@ -22,13 +28,15 @@ def openup(path)
|
|
22
28
|
openup File.join(path, entry)
|
23
29
|
end
|
24
30
|
end
|
25
|
-
base_path = File.expand_path
|
26
|
-
openup
|
31
|
+
base_path = File.expand_path "../../..", __FILE__
|
32
|
+
openup base_path
|
27
33
|
|
28
|
-
#
|
29
|
-
# abusing the patience of Ruby developers
|
34
|
+
# We really shouldn't be abusing rubygems' root. Then again, the Debian
|
35
|
+
# maintaines shouldn't be abusing the patience of Ruby developers.
|
30
36
|
|
31
|
-
#
|
32
|
-
|
33
|
-
File.open(
|
34
|
-
File.open('
|
37
|
+
# Now trick rubygems and echoe into believeing that a gem got installed is good.
|
38
|
+
ext_binary = 'rpwn_setup_notice' + (Gem.win_platform? ? '.dll' : '.so')
|
39
|
+
File.open(ext_binary, 'w') { |f| }
|
40
|
+
File.open('Makefile', 'w') do |f|
|
41
|
+
f.write "# target_prefix = #{ext_binary}\nall:\n\ninstall:\n\n"
|
42
|
+
end
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
require 'fileutils'
|
4
4
|
|
5
|
-
class
|
6
|
-
include
|
5
|
+
class RailsPwnerer::App::ClusterConfig
|
6
|
+
include RailsPwnerer::Base
|
7
7
|
|
8
8
|
def fix_permissions(app_name, instance_name)
|
9
|
-
app_config =
|
9
|
+
app_config = RailsPwnerer::Config[app_name, instance_name]
|
10
10
|
pwnerer_user = app_config[:pwnerer_user]
|
11
11
|
pwnerer_uid = uid_for_username(pwnerer_user)
|
12
12
|
pwnerer_group = group_for_username(pwnerer_user)
|
@@ -25,27 +25,27 @@ class RailsPwnage::App::ClusterConfig
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def manage_ports(app_name, instance_name, action)
|
28
|
-
app_config =
|
29
|
-
return unless frontends =
|
28
|
+
app_config = RailsPwnerer::Config[app_name, instance_name]
|
29
|
+
return unless frontends = RailsPwnerer::Config.app_frontends(app_name, instance_name)
|
30
30
|
|
31
31
|
case action
|
32
32
|
when :alloc
|
33
|
-
app_config[:port0] =
|
33
|
+
app_config[:port0] = RailsPwnerer::Config.alloc_ports frontends
|
34
34
|
when :free
|
35
|
-
|
35
|
+
RailsPwnerer::Config.free_ports app_config[:port0], frontends
|
36
36
|
return if app_config[:port0] == 0 # do not release if ports have already been released
|
37
37
|
app_config[:port0] = 0
|
38
38
|
end
|
39
|
-
|
39
|
+
RailsPwnerer::Config.flush_db RailsPwnerer::Config.app_db_name(app_name, instance_name)
|
40
40
|
end
|
41
41
|
|
42
42
|
def stop(app_name, instance_name)
|
43
|
-
app_config =
|
43
|
+
app_config = RailsPwnerer::Config[app_name, instance_name]
|
44
44
|
# silently die if the app was completely busted
|
45
45
|
return unless app_config and File.exists? app_config[:app_path]
|
46
46
|
|
47
47
|
app_path, first_port = app_config[:app_path], app_config[:port0]
|
48
|
-
frontends =
|
48
|
+
frontends = RailsPwnerer::Config.app_frontends(app_name, instance_name)
|
49
49
|
|
50
50
|
cmdline_patterns = ['thin', nil]
|
51
51
|
|
@@ -55,7 +55,7 @@ class RailsPwnage::App::ClusterConfig
|
|
55
55
|
fe_port = first_port + f
|
56
56
|
cmdline = "thin stop -a 127.0.0.1 -p #{fe_port} -d -P tmp/pids/fe.#{fe_port}.pid"
|
57
57
|
cmdline_patterns[1] = "(127.0.0.1:#{fe_port})"
|
58
|
-
|
58
|
+
RailsPwnerer::Util.kill_process_set(cmdline, "tmp/pids/fe.#{fe_port}.pid",
|
59
59
|
cmdline_patterns, :verbose => false, :sleep_delay => 0.2)
|
60
60
|
end
|
61
61
|
|
@@ -63,13 +63,13 @@ class RailsPwnage::App::ClusterConfig
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def start(app_name, instance_name)
|
66
|
-
app_config =
|
66
|
+
app_config = RailsPwnerer::Config[app_name, instance_name]
|
67
67
|
# silently die if the app was completely busted
|
68
68
|
return unless app_config and File.exists? app_config[:app_path]
|
69
69
|
|
70
70
|
app_path, pwnerer_user = app_config[:app_path], app_config[:pwnerer_user]
|
71
71
|
pwnerer_group = group_for_username(pwnerer_user)
|
72
|
-
frontends =
|
72
|
+
frontends = RailsPwnerer::Config.app_frontends(app_name, instance_name)
|
73
73
|
first_port, environment = app_config[:port0], app_config[:environment]
|
74
74
|
|
75
75
|
stop app_name, instance_name
|
@@ -78,7 +78,7 @@ class RailsPwnage::App::ClusterConfig
|
|
78
78
|
if first_port == 0
|
79
79
|
manage_ports app_name, instance_name, :alloc
|
80
80
|
first_port = app_config[:port0]
|
81
|
-
|
81
|
+
RailsPwnerer::App::NginxConfig.new.update app_name, instance_name
|
82
82
|
end
|
83
83
|
|
84
84
|
static_cmd = "thin start -a 127.0.0.1 -c #{app_path} -d -u #{pwnerer_user}" +
|
@@ -128,12 +128,12 @@ class RailsPwnage::App::ClusterConfig
|
|
128
128
|
end
|
129
129
|
|
130
130
|
def control_all(action)
|
131
|
-
|
131
|
+
RailsPwnerer::Config.all_applications.each do |ai|
|
132
132
|
case action
|
133
133
|
when :start
|
134
|
-
|
134
|
+
RailsPwnerer::App::ClusterConfig.new.start ai[0], ai[1]
|
135
135
|
when :stop
|
136
|
-
|
136
|
+
RailsPwnerer::App::ClusterConfig.new.stop ai[0], ai[1]
|
137
137
|
end
|
138
138
|
end
|
139
139
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# syncs the app's internal configuration with the configuration database
|
2
2
|
require 'yaml'
|
3
3
|
|
4
|
-
class
|
5
|
-
include
|
4
|
+
class RailsPwnerer::App::Config
|
5
|
+
include RailsPwnerer::Base
|
6
6
|
|
7
7
|
def random_db_password
|
8
8
|
(0...16).map { |i| "abcdefghijklmnopqrstuvwxyz"[rand(26),1]}.join
|
@@ -13,12 +13,12 @@ class RailsPwnage::App::Config
|
|
13
13
|
# update: this adds keys that might have been added in new versions of rpwn
|
14
14
|
def populate_defaults(app_name, instance_name, app_db)
|
15
15
|
# the path to application main files
|
16
|
-
app_db[:app_path] = File.join(
|
16
|
+
app_db[:app_path] = File.join(RailsPwnerer::Config.path_to(:apps), app_name + '.' + instance_name)
|
17
17
|
# the path to application backups
|
18
|
-
app_db[:backup_path] ||= File.join(
|
18
|
+
app_db[:backup_path] ||= File.join(RailsPwnerer::Config.path_to(:backups), app_name + '.' + instance_name)
|
19
19
|
|
20
20
|
# the user which will receive the "keys" to the production system
|
21
|
-
app_db[:pwnerer_user] ||=
|
21
|
+
app_db[:pwnerer_user] ||= RailsPwnerer::Config[:host][:pwnerer_user]
|
22
22
|
# the number of frontends for the application instance
|
23
23
|
app_db[:frontends] ||= 4 # most computers have 2 cores nowadays
|
24
24
|
# the number of frontends per core for the application instance
|
@@ -52,19 +52,19 @@ class RailsPwnage::App::Config
|
|
52
52
|
|
53
53
|
# allocates room for the application and creates the application configuration database
|
54
54
|
def alloc(app_name, instance_name)
|
55
|
-
app_db_name =
|
56
|
-
app_db =
|
55
|
+
app_db_name = RailsPwnerer::Config.app_db_name(app_name, instance_name)
|
56
|
+
app_db = RailsPwnerer::Config.create_db app_db_name
|
57
57
|
populate_defaults app_name, instance_name, app_db
|
58
58
|
|
59
59
|
FileUtils.mkpath app_db[:app_path]
|
60
60
|
|
61
|
-
|
61
|
+
RailsPwnerer::Config.flush_db app_db
|
62
62
|
return app_db[:app_path]
|
63
63
|
end
|
64
64
|
|
65
65
|
# pushes config changes from the application file to the database
|
66
66
|
def update(app_name, instance_name)
|
67
|
-
app_config =
|
67
|
+
app_config = RailsPwnerer::Config[app_name, instance_name]
|
68
68
|
|
69
69
|
db_name, db_user, db_pass = app_config[:db_name], app_config[:db_user], app_config[:db_pass]
|
70
70
|
app_config.clear
|
@@ -95,16 +95,16 @@ class RailsPwnage::App::Config
|
|
95
95
|
# TODO: if database settings changed, the database should be moved (re-created or re-keyed)
|
96
96
|
if db_pass != app_config[:db_pass]
|
97
97
|
db_pass = random_db_password if !db_pass || db_pass.empty?
|
98
|
-
|
98
|
+
RailsPwnerer::App::Database.new.manage app_name, instance_name, :rekey
|
99
99
|
end
|
100
100
|
|
101
|
-
|
101
|
+
RailsPwnerer::Config.flush_db RailsPwnerer::Config.app_db_name(app_name, instance_name)
|
102
102
|
end
|
103
103
|
|
104
104
|
def manage(app_name, instance_name, action)
|
105
105
|
case action
|
106
106
|
when :rekey
|
107
|
-
app_config =
|
107
|
+
app_config = RailsPwnerer::Config[app_name, instance_name]
|
108
108
|
app_config[:db_pass] = random_db_password
|
109
109
|
end
|
110
110
|
end
|
@@ -114,7 +114,7 @@ class RailsPwnage::App::Config
|
|
114
114
|
end
|
115
115
|
|
116
116
|
def remove(app_name, instance_name)
|
117
|
-
app_db_name =
|
118
|
-
|
117
|
+
app_db_name = RailsPwnerer::Config.app_db_name(app_name, instance_name)
|
118
|
+
RailsPwnerer::Config.drop_db app_db_name
|
119
119
|
end
|
120
120
|
end
|
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
require 'yaml'
|
4
4
|
|
5
|
-
class
|
6
|
-
include
|
5
|
+
class RailsPwnerer::App::Database
|
6
|
+
include RailsPwnerer::Base
|
7
7
|
|
8
8
|
# creates/drops the mysql database for the application
|
9
9
|
def admin_database(app_name, instance_name, action = :create)
|
10
|
-
app_config =
|
10
|
+
app_config = RailsPwnerer::Config[app_name, instance_name]
|
11
11
|
# exit and don't complain if the app is busted
|
12
12
|
return unless app_config and File.exists? app_config[:app_path]
|
13
13
|
|
@@ -34,8 +34,8 @@ ENDSQL
|
|
34
34
|
|
35
35
|
# run it
|
36
36
|
File.open('admin_db.sql', 'w') { |f| f.write sql_commands }
|
37
|
-
dbroot_name =
|
38
|
-
dbroot_pass =
|
37
|
+
dbroot_name = RailsPwnerer::Config[:host][:dbroot_name]
|
38
|
+
dbroot_pass = RailsPwnerer::Config[:host][:dbroot_pass]
|
39
39
|
dbpass_arg = dbroot_pass.empty? ? '' : "-p#{dbroot_pass}"
|
40
40
|
system "mysql -u#{dbroot_name} #{dbpass_arg} < admin_db.sql"
|
41
41
|
|
@@ -67,7 +67,7 @@ ENDSQL
|
|
67
67
|
|
68
68
|
# configures rails to use the database in the production environment
|
69
69
|
def configure_rails(app_name, instance_name)
|
70
|
-
app_config =
|
70
|
+
app_config = RailsPwnerer::Config[app_name, instance_name]
|
71
71
|
db_name, db_user, db_pass = app_config[:db_name], app_config[:db_user], app_config[:db_pass]
|
72
72
|
|
73
73
|
config_file = File.join app_config[:app_path], 'config', 'database.yml'
|
@@ -89,7 +89,7 @@ ENDSQL
|
|
89
89
|
|
90
90
|
# migrates the database to the latest schema version
|
91
91
|
def migrate_database(app_name, instance_name)
|
92
|
-
Dir.chdir
|
92
|
+
Dir.chdir RailsPwnerer::Config[app_name, instance_name][:app_path] do
|
93
93
|
# now migrate the database
|
94
94
|
system "rake db:migrate RAILS_ENV=production"
|
95
95
|
end
|
@@ -97,7 +97,7 @@ ENDSQL
|
|
97
97
|
|
98
98
|
# creates a database dump in the backup area
|
99
99
|
def dump_database(app_name, instance_name)
|
100
|
-
app_config =
|
100
|
+
app_config = RailsPwnerer::Config[app_name, instance_name]
|
101
101
|
db_name, db_user, db_pass = app_config[:db_name], app_config[:db_user], app_config[:db_pass]
|
102
102
|
|
103
103
|
pwnerer_user = app_config[:pwnerer_user]
|
@@ -118,7 +118,7 @@ ENDSQL
|
|
118
118
|
|
119
119
|
# loads the latest database dump from the backup area
|
120
120
|
def load_database(app_name, instance_name)
|
121
|
-
app_config =
|
121
|
+
app_config = RailsPwnerer::Config[app_name, instance_name]
|
122
122
|
db_name, db_user, db_pass = app_config[:db_name], app_config[:db_user], app_config[:db_pass]
|
123
123
|
|
124
124
|
Dir.chdir app_config[:backup_path] do
|
@@ -1,19 +1,19 @@
|
|
1
1
|
# manages an application's file system
|
2
2
|
|
3
|
-
class
|
4
|
-
include
|
3
|
+
class RailsPwnerer::App::Files
|
4
|
+
include RailsPwnerer::Base
|
5
5
|
|
6
6
|
# dump the application files to the backup area
|
7
7
|
def dump_files(app_name, instance_name)
|
8
|
-
pwnerer_user =
|
8
|
+
pwnerer_user = RailsPwnerer::Config[app_name, instance_name][:pwnerer_user]
|
9
9
|
pwnerer_uid = uid_for_username(pwnerer_user)
|
10
10
|
pwnerer_gid = gid_for_username(pwnerer_user)
|
11
11
|
|
12
12
|
timestamp = Time.now.strftime '%Y%m%d%H%M%S'
|
13
13
|
dump_file = "files/#{app_name}.#{instance_name}_#{timestamp}.tar.gz"
|
14
14
|
|
15
|
-
backup_path =
|
16
|
-
app_path =
|
15
|
+
backup_path = RailsPwnerer::Config[app_name, instance_name][:backup_path]
|
16
|
+
app_path = RailsPwnerer::Config[app_name, instance_name][:app_path]
|
17
17
|
Dir.chdir backup_path do
|
18
18
|
# create a cold copy of the application files
|
19
19
|
cold_copy = File.join('tmp', File.basename(app_path))
|
@@ -21,7 +21,7 @@ class RailsPwnage::App::Files
|
|
21
21
|
FileUtils.cp_r app_path, 'tmp'
|
22
22
|
|
23
23
|
# remove the garbage in the cold copy
|
24
|
-
[
|
24
|
+
[RailsPwnerer::App::Git, RailsPwnerer::App::Svn].each do |mod|
|
25
25
|
mod.new.cleanup_app_caches cold_copy, instance_name, true
|
26
26
|
end
|
27
27
|
|
@@ -39,11 +39,11 @@ class RailsPwnage::App::Files
|
|
39
39
|
|
40
40
|
# creates the directory scaffold in the application's backup dir
|
41
41
|
def scaffold_backup(app_name, instance_name)
|
42
|
-
pwnerer_user =
|
42
|
+
pwnerer_user = RailsPwnerer::Config[app_name, instance_name][:pwnerer_user]
|
43
43
|
pwnerer_uid = uid_for_username(pwnerer_user)
|
44
44
|
pwnerer_gid = gid_for_username(pwnerer_user)
|
45
45
|
|
46
|
-
backup_path =
|
46
|
+
backup_path = RailsPwnerer::Config[app_name, instance_name][:backup_path]
|
47
47
|
FileUtils.mkpath backup_path unless File.exists? backup_path
|
48
48
|
File.chown(pwnerer_uid, pwnerer_gid, backup_path)
|
49
49
|
|
@@ -57,8 +57,8 @@ class RailsPwnage::App::Files
|
|
57
57
|
|
58
58
|
# loads the latest file dump from the backup area
|
59
59
|
def load_files(app_name, instance_name)
|
60
|
-
backup_path =
|
61
|
-
app_path =
|
60
|
+
backup_path = RailsPwnerer::Config[app_name, instance_name][:backup_path]
|
61
|
+
app_path = RailsPwnerer::Config[app_name, instance_name][:app_path]
|
62
62
|
|
63
63
|
dump_file = Dir.glob(File.join(backup_path, "files/#{app_name}.#{instance_name}_*")).max
|
64
64
|
unless dump_file
|
@@ -73,7 +73,7 @@ class RailsPwnage::App::Files
|
|
73
73
|
|
74
74
|
# remove the application files
|
75
75
|
def drop_files(app_name, instance_name)
|
76
|
-
app_config =
|
76
|
+
app_config = RailsPwnerer::Config[app_name, instance_name]
|
77
77
|
# exit and don't complain if the app is busted
|
78
78
|
return unless app_config and File.exists? app_config[:app_path]
|
79
79
|
|
@@ -89,7 +89,7 @@ class RailsPwnage::App::Files
|
|
89
89
|
drop_files app_name, instance_name
|
90
90
|
load_files app_name, instance_name
|
91
91
|
when :console
|
92
|
-
Dir.chdir(
|
92
|
+
Dir.chdir(RailsPwnerer::Config[app_name, instance_name][:app_path]) do
|
93
93
|
if File.exist? 'script/rails'
|
94
94
|
Kernel.system 'rails console production'
|
95
95
|
else
|
@@ -97,7 +97,7 @@ class RailsPwnage::App::Files
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
when :db_console
|
100
|
-
Dir.chdir(
|
100
|
+
Dir.chdir(RailsPwnerer::Config[app_name, instance_name][:app_path]) do
|
101
101
|
if File.exist? 'script/rails'
|
102
102
|
Kernel.system 'rails dbconsole production --include-password'
|
103
103
|
else
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# sets up the application gems
|
2
2
|
|
3
|
-
class
|
4
|
-
include
|
3
|
+
class RailsPwnerer::App::Gems
|
4
|
+
include RailsPwnerer::Base
|
5
5
|
|
6
6
|
def update(app_name, instance_name)
|
7
|
-
app_config =
|
7
|
+
app_config = RailsPwnerer::Config[app_name, instance_name]
|
8
8
|
|
9
9
|
Dir.chdir app_config[:app_path] do
|
10
10
|
# Phase 1: app-directed install
|
@@ -1,11 +1,11 @@
|
|
1
|
-
module
|
1
|
+
module RailsPwnerer::App
|
2
2
|
# internal method implementing magic instance names
|
3
3
|
def self.instance_magic(app_name, instance_name)
|
4
4
|
case instance_name
|
5
5
|
when '*'
|
6
|
-
|
6
|
+
RailsPwnerer::Config.all_instances app_name { |i| yield app_name, i }
|
7
7
|
when '.'
|
8
|
-
yield app_name,
|
8
|
+
yield app_name, RailsPwnerer::Config[:host][:instance]
|
9
9
|
else
|
10
10
|
yield app_name, instance_name
|
11
11
|
end
|
@@ -119,7 +119,7 @@ module RailsPwnage::App
|
|
119
119
|
when :db_console
|
120
120
|
Files.new.manage app, instance, action
|
121
121
|
when :db_reset
|
122
|
-
app_config =
|
122
|
+
app_config = RailsPwnerer::Config[app, instance]
|
123
123
|
unless app_config[:enable_db_reset]
|
124
124
|
print "Database resets are disabled for this instance.\n"
|
125
125
|
print "If you truly want to reset, add the :enable_db_reset configuration key.\n"
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# builds the nginx configuration
|
2
2
|
|
3
|
-
class
|
4
|
-
include
|
3
|
+
class RailsPwnerer::App::NginxConfig
|
4
|
+
include RailsPwnerer::Base
|
5
5
|
|
6
6
|
# writes the nginx configuration for this server
|
7
7
|
def config_nginx(app_name, instance_name)
|
8
|
-
app_config =
|
8
|
+
app_config = RailsPwnerer::Config[app_name, instance_name]
|
9
9
|
first_port = app_config[:port0]
|
10
10
|
|
11
11
|
# Can be specified as comma-separated string or array.
|
@@ -18,12 +18,12 @@ class RailsPwnage::App::NginxConfig
|
|
18
18
|
default_app_port = app_config[:ssl_key] ? 443 : 80
|
19
19
|
app_port = app_config[:port] || default_app_port
|
20
20
|
|
21
|
-
nginx_config = File.join(
|
21
|
+
nginx_config = File.join(RailsPwnerer::Config.path_to(:nginx_configs),
|
22
22
|
app_name + '.' + instance_name)
|
23
23
|
File.open(nginx_config, 'w') do |f|
|
24
24
|
# link to the frontends
|
25
25
|
f << " upstream #{app_name}_#{instance_name} {\n"
|
26
|
-
|
26
|
+
RailsPwnerer::Config.app_frontends(app_name, instance_name).times do |instance|
|
27
27
|
f << " server 127.0.0.1:#{first_port + instance};\n"
|
28
28
|
end
|
29
29
|
f << " }\n\n"
|
@@ -68,13 +68,13 @@ NGINX_CONFIG
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def remove_nginx_config(app_name, instance_name)
|
71
|
-
nginx_config = File.join(
|
71
|
+
nginx_config = File.join(RailsPwnerer::Config.path_to(:nginx_configs), app_name + '.' + instance_name)
|
72
72
|
File.delete nginx_config if File.exists? nginx_config
|
73
73
|
end
|
74
74
|
|
75
75
|
# removes the default configuration stub (so nginx doesn't stumble upon it)
|
76
76
|
def remove_nginx_stub
|
77
|
-
stub_file = File.join(
|
77
|
+
stub_file = File.join(RailsPwnerer::Config.path_to(:nginx_configs), 'default')
|
78
78
|
File.delete stub_file if File.exists?(stub_file)
|
79
79
|
end
|
80
80
|
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# runs custom scripts on app events
|
2
2
|
|
3
|
-
class
|
4
|
-
include
|
3
|
+
class RailsPwnerer::App::Scripts
|
4
|
+
include RailsPwnerer::Base
|
5
5
|
|
6
6
|
def run_script(app_name, instance_name, script_name)
|
7
|
-
app_config =
|
7
|
+
app_config = RailsPwnerer::Config[app_name, instance_name]
|
8
8
|
pwnerer_user = app_config[:pwnerer_user]
|
9
9
|
pwnerer_uid = uid_for_username(pwnerer_user)
|
10
10
|
pwnerer_gid = gid_for_username(pwnerer_user)
|
@@ -70,7 +70,7 @@ class RailsPwnage::App::Scripts
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def control_all(action)
|
73
|
-
|
73
|
+
RailsPwnerer::Config.all_applications.each do |ai|
|
74
74
|
run_script ai[0], ai[1], (case action
|
75
75
|
when :pre_start then 'pre_start'
|
76
76
|
when :post_start then 'post_start'
|