rails_pwnerer 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.3. Supports 'update' to update application from svn. Still no configuration outside of config/main.rb.
2
+
1
3
  v0.2. Supports 'install' to install application from svn. No configuration outside of config/main.rb.
2
4
 
3
5
  v0.1. Initial release. Supports 'den00b' to setup the environment.
@@ -31,6 +31,21 @@ class RailsPwnage::App::ClusterConfig
31
31
 
32
32
  # copy the configuration to the launch directory
33
33
  FileUtils.cp('config/mongrel_cluster.yml', "#{RailsPwnage::Config.path_to :mongrel_configs}#{File::SEPARATOR}#{app_name}.yml")
34
+ end
35
+ end
36
+
37
+ def stop_mongrels(app_name)
38
+ with_dir(RailsPwnage::Config.path_to(app_name)) do
39
+ system 'mongrel_rails cluster::stop'
40
+
41
+ # clean up PID files in case the mongrels died and left them behind
42
+ Dir.glob('tmp/pids/*.pid').each { |f| File.delete(f) }
43
+ end
44
+ end
45
+
46
+ def start_mongrels(app_name)
47
+ with_dir(RailsPwnage::Config.path_to(app_name)) do
48
+ system 'mongrel_rails cluster::start'
34
49
  end
35
50
  end
36
51
 
@@ -39,7 +54,19 @@ class RailsPwnage::App::ClusterConfig
39
54
  fix_permissions app_name
40
55
  end
41
56
 
57
+ def update(app_name, &update_proc)
58
+ stop_mongrels(app_name)
59
+ yield
60
+ ensure
61
+ # TODO: reconfigure the mongrels if the configuration database changed
62
+ start_mongrels(app_name)
63
+ end
64
+
42
65
  def self.setup(app_name)
43
66
  self.new.setup(app_name)
44
- end
67
+ end
68
+
69
+ def self.update(app_name, &update_proc)
70
+ self.new.update(app_name, &update_proc)
71
+ end
45
72
  end
@@ -1,5 +1,7 @@
1
1
  # sets up the application database
2
2
 
3
+ require 'yaml'
4
+
3
5
  class RailsPwnage::App::Database
4
6
  include RailsPwnage::Base
5
7
 
@@ -27,7 +29,19 @@ ENDSQL
27
29
 
28
30
  # configures rails to use the database in the production environment
29
31
  def configure_rails(app_name)
30
- # TODO: write rails configuration file
32
+ db_name = RailsPwnage::Config.app_dbname(app_name)
33
+ db_user = RailsPwnage::Config.app_db_user(app_name)
34
+ db_pass = RailsPwnage::Config.app_db_password(app_name)
35
+
36
+ config_file = RailsPwnage::Config.path_to(app_name) + File::SEPARATOR + 'config' + File::SEPARATOR + 'database.yml'
37
+ configuration = File.open(config_file, 'r') { |f| YAML.load f }
38
+ configuration['production'].merge! 'adapter' => 'mysql', 'database' => db_name, 'username' => db_user, 'password' => db_pass
39
+ File.open(config_file, 'w') { |f| YAML.dump(configuration, f) }
40
+
41
+ # bonus: lock down the database so only the right user can access it
42
+ pwnerer_user = RailsPwnage::Config.pwnerer_user
43
+ File.chmod(0600, config_file)
44
+ File.chown(uid_for_username(pwnerer_user), gid_for_username(pwnerer_user), config_file)
31
45
  end
32
46
 
33
47
  # migrates the database so it's ready
@@ -44,7 +58,16 @@ ENDSQL
44
58
  migrate_database app_name
45
59
  end
46
60
 
61
+ def update(app_name)
62
+ configure_rails app_name
63
+ migrate_database app_name
64
+ end
65
+
47
66
  def self.setup(app_name)
48
67
  self.new.setup(app_name)
49
68
  end
69
+
70
+ def self.update(app_name)
71
+ self.new.update(app_name)
72
+ end
50
73
  end
@@ -6,4 +6,12 @@ module RailsPwnage::App
6
6
  ClusterConfig.setup(app_name)
7
7
  NginxConfig.setup(app_name)
8
8
  end
9
+
10
+ def self.update(app_name)
11
+ ClusterConfig.update(app_name) do
12
+ Svn.update(app_name)
13
+ Database.update(app_name)
14
+ end
15
+ NginxConfig.update(app_name)
16
+ end
9
17
  end
@@ -60,4 +60,8 @@ NGINX_CONFIG
60
60
  def self.setup(app_name)
61
61
  self.new.setup(app_name)
62
62
  end
63
+
64
+ def self.update(app_name)
65
+ # nothing to do here, unless we enable config rewriting
66
+ end
63
67
  end
@@ -16,6 +16,12 @@ class RailsPwnage::App::Svn
16
16
 
17
17
  return app_name
18
18
  end
19
+
20
+ def update(app_name)
21
+ with_dir(RailsPwnage::Config.path_to(app_name)) do
22
+ system "svn update"
23
+ end
24
+ end
19
25
 
20
26
  def setup(svn_path)
21
27
  app_name = checkout(svn_path)
@@ -28,6 +34,10 @@ class RailsPwnage::App::Svn
28
34
  def self.setup(svn_path)
29
35
  self.new.setup(svn_path)
30
36
  end
37
+
38
+ def self.update(app_name)
39
+ self.new.update(app_name)
40
+ end
31
41
 
32
42
  # TODO: uninstallation
33
43
  end
@@ -22,6 +22,10 @@ class RailsPwnage::Executor
22
22
  when 'install'
23
23
  svn_path = args[1]
24
24
  RailsPwnage::App.install svn_path
25
+
26
+ when 'update'
27
+ app_name = args[1]
28
+ RailsPwnage::App.update app_name
25
29
  end
26
30
  end
27
31
 
@@ -14,7 +14,7 @@ class RailsPwnage::Scaffolds::Gems
14
14
 
15
15
  def install_tools
16
16
  # TODO: an application should have its own tools
17
- install_gems %w(rmagick mechanize sys-proctable)
17
+ install_gems %w(rmagick mechanize sys-proctable highline echoe)
18
18
  end
19
19
 
20
20
  # runner
@@ -1,16 +1,16 @@
1
1
 
2
- # Gem::Specification for Rails_pwnerer-0.2
2
+ # Gem::Specification for Rails_pwnerer-0.3
3
3
  # Originally generated by Echoe
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = %q{rails_pwnerer}
7
- s.version = "0.2"
7
+ s.version = "0.3"
8
8
 
9
9
  s.specification_version = 2 if s.respond_to? :specification_version=
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Victor Costan"]
13
- s.date = %q{2008-04-13}
13
+ s.date = %q{2008-04-14}
14
14
  s.default_executable = %q{rpwn}
15
15
  s.description = %q{Rails deployment tool/hack.}
16
16
  s.email = %q{victor@costan.us}
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.2"
4
+ version: "0.3"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Costan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-04-13 00:00:00 -04:00
12
+ date: 2008-04-14 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15