zena 1.0.0.beta2 → 1.0.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. data/.gitignore +2 -0
  2. data/History.txt +12 -0
  3. data/app/controllers/application_controller.rb +0 -1
  4. data/app/controllers/columns_controller.rb +11 -1
  5. data/app/controllers/nodes_controller.rb +79 -19
  6. data/app/controllers/versions_controller.rb +0 -2
  7. data/app/controllers/virtual_classes_controller.rb +19 -6
  8. data/app/models/column.rb +5 -1
  9. data/app/models/comment.rb +1 -6
  10. data/app/models/node.rb +21 -3
  11. data/app/models/role.rb +21 -0
  12. data/app/models/site.rb +7 -2
  13. data/app/models/template.rb +3 -3
  14. data/app/models/text_document.rb +4 -4
  15. data/app/models/user.rb +21 -8
  16. data/app/views/columns/_li.html.erb +1 -0
  17. data/app/views/nodes/_groups.rhtml +1 -1
  18. data/app/views/sites/_form.erb +3 -1
  19. data/app/views/sites/_li.erb +1 -0
  20. data/app/views/sites/index.erb +1 -1
  21. data/app/views/virtual_classes/_form.erb +11 -2
  22. data/app/views/virtual_classes/_li.erb +5 -2
  23. data/bin/zena +1 -1
  24. data/bricks/math/lib/bricks/math.rb +1 -1
  25. data/bricks/mongrel/README +3 -0
  26. data/bricks/mongrel/zena/deploy.rb +56 -0
  27. data/bricks/passenger/README +3 -0
  28. data/bricks/passenger/zena/deploy.rb +49 -0
  29. data/config/bricks.yml +6 -0
  30. data/config/deploy.rb +24 -18
  31. data/config/gems.yml +3 -3
  32. data/db/migrate/20100915062903_add_api_group_id_to_site.rb +9 -0
  33. data/lib/tasks/zena.rake +39 -35
  34. data/lib/zena.rb +5 -6
  35. data/lib/zena/acts/enrollable.rb +37 -6
  36. data/lib/zena/app.rb +4 -2
  37. data/lib/zena/deploy.rb +110 -150
  38. data/lib/zena/deploy/awstats.conf.rhtml +4 -4
  39. data/lib/zena/deploy/httpd.rhtml +2 -1
  40. data/lib/zena/deploy/stats.vhost.rhtml +7 -7
  41. data/lib/zena/deploy/vhost.rhtml +1 -1
  42. data/lib/zena/deploy/vhost_www.rhtml +4 -4
  43. data/lib/zena/foxy_parser.rb +6 -5
  44. data/lib/zena/info.rb +1 -1
  45. data/lib/zena/integration/test_case.rb +8 -3
  46. data/lib/zena/parser.rb +11 -11
  47. data/lib/zena/parser/zafu_tags.rb +2 -2
  48. data/lib/zena/remote.rb +16 -0
  49. data/lib/zena/remote/connection.rb +67 -0
  50. data/lib/zena/remote/interface.rb +405 -0
  51. data/lib/zena/remote/klass.rb +14 -0
  52. data/lib/zena/remote/mock.rb +58 -0
  53. data/lib/zena/remote/node.rb +76 -0
  54. data/lib/zena/routes.rb +2 -1
  55. data/lib/zena/use.rb +9 -4
  56. data/lib/zena/use/ajax.rb +3 -3
  57. data/lib/zena/use/authlogic.rb +8 -1
  58. data/lib/zena/use/context.rb +22 -21
  59. data/lib/zena/use/dates.rb +26 -3
  60. data/lib/zena/use/display.rb +33 -5
  61. data/lib/zena/use/forms.rb +90 -12
  62. data/lib/zena/use/fulltext.rb +1 -1
  63. data/lib/zena/use/i18n.rb +118 -31
  64. data/lib/zena/use/query_builder.rb +7 -5
  65. data/lib/zena/use/query_node.rb +30 -4
  66. data/lib/zena/use/rendering.rb +1 -1
  67. data/lib/zena/use/search.rb +10 -7
  68. data/lib/zena/use/urls.rb +3 -3
  69. data/lib/zena/use/zafu_attributes.rb +2 -2
  70. data/lib/zena/use/zafu_eval.rb +1 -1
  71. data/lib/zena/use/zafu_safe_definitions.rb +1 -0
  72. data/lib/zena/use/zafu_templates.rb +1 -1
  73. data/lib/zena/zafu_compiler.rb +5 -1
  74. data/public/javascripts/zena.js +4 -4
  75. data/public/stylesheets/admin.css +1 -0
  76. data/test/custom_queries/complex.host.yml +3 -3
  77. data/test/fixtures/files/translations_fr.yml +4 -1
  78. data/test/functional/application_controller_test.rb +2 -2
  79. data/test/functional/nodes_controller_test.rb +57 -5
  80. data/test/functional/users_controller_test.rb +10 -9
  81. data/test/functional/virtual_classes_controller_test.rb +48 -0
  82. data/test/integration/navigation_test.rb +13 -1
  83. data/test/integration/query_node/filters.yml +5 -0
  84. data/test/integration/query_node_test.rb +1 -1
  85. data/test/integration/zafu_compiler/ajax.yml +13 -19
  86. data/test/integration/zafu_compiler/basic.yml +0 -72
  87. data/test/integration/zafu_compiler/complex.yml +1 -1
  88. data/test/integration/zafu_compiler/complex_ok.yml +19 -0
  89. data/test/integration/zafu_compiler/dates.yml +62 -1
  90. data/test/integration/zafu_compiler/display.yml +4 -4
  91. data/test/integration/zafu_compiler/forms.yml +19 -7
  92. data/test/integration/zafu_compiler/i18n.yml +56 -1
  93. data/test/integration/zafu_compiler/later.yml +23 -1
  94. data/test/integration/zafu_compiler/relations.yml +1 -1
  95. data/test/integration/zafu_compiler/roles.yml +29 -1
  96. data/test/integration/zafu_compiler/safe_definitions.yml +1 -1
  97. data/test/integration/zafu_compiler/zafu_attributes.yml +2 -1
  98. data/test/integration/zafu_compiler_test.rb +5 -3
  99. data/test/sites/zena/columns.yml +3 -0
  100. data/test/sites/zena/roles.yml +0 -1
  101. data/test/sites/zena/sites.yml +1 -0
  102. data/test/sites/zena/versions.yml +2 -0
  103. data/test/unit/node_test.rb +27 -9
  104. data/test/unit/relation_proxy_test.rb +7 -4
  105. data/test/unit/remote_test.rb +379 -0
  106. data/test/unit/user_test.rb +47 -0
  107. data/test/unit/zena/acts/enrollable_test.rb +36 -7
  108. data/test/unit/zena/acts/serializable_test.rb +14 -2
  109. data/test/unit/zena/use/i18n_test.rb +32 -5
  110. data/test/unit/zena/use/query_node_test.rb +13 -1
  111. data/zena.gemspec +25 -11
  112. metadata +24 -10
data/lib/tasks/zena.rake CHANGED
@@ -295,45 +295,49 @@ namespace :zena do
295
295
 
296
296
  desc 'Rebuild foxy fixtures for all sites'
297
297
  task :build_fixtures => :environment do
298
- Dir["#{RAILS_ROOT}/test/fixtures/*.yml"].each do |f|
299
- FileUtils.rm f
300
- end
298
+ if RAILS_ENV != 'test'
299
+ puts "## You can only build fixtures by using the test environment to avoid loosing data (used = #{RAILS_ENV})"
300
+ else
301
+ Dir["#{RAILS_ROOT}/test/fixtures/*.yml"].each do |f|
302
+ FileUtils.rm f
303
+ end
301
304
 
302
- tables = Node.connection.tables
303
- ordered_tables = %w{roles versions nodes attachments zips relations links}
304
-
305
- tables -= ordered_tables
306
- tables += ordered_tables
307
- roles, versions, nodes = nil, nil, nil
308
- tables.each do |table|
309
- case table
310
- when 'roles'
311
- roles = Zena::FoxyParser.new(table)
312
- roles.run
313
- when 'versions'
314
- versions = Zena::FoxyParser.new(table)
315
- versions.run
316
- when 'nodes'
317
- nodes = Zena::FoxyParser.new(table, :versions => versions, :roles => roles)
318
- nodes.run
319
- when 'zips'
320
- Zena::FoxyParser.new(table, :nodes => nodes).run
321
- when 'relations'
322
- Zena::FoxyParser.new(table, :roles => roles).run
323
- when 'links'
324
- Zena::FoxyParser.new(table, :nodes => nodes).run
325
- else
326
- Zena::FoxyParser.new(table).run
305
+ tables = Node.connection.tables
306
+ ordered_tables = %w{roles versions nodes attachments zips relations links}
307
+
308
+ tables -= ordered_tables
309
+ tables += ordered_tables
310
+ roles, versions, nodes = nil, nil, nil
311
+ tables.each do |table|
312
+ case table
313
+ when 'roles'
314
+ roles = Zena::FoxyParser.new(table)
315
+ roles.run
316
+ when 'versions'
317
+ versions = Zena::FoxyParser.new(table)
318
+ versions.run
319
+ when 'nodes'
320
+ nodes = Zena::FoxyParser.new(table, :versions => versions, :roles => roles)
321
+ nodes.run
322
+ when 'zips'
323
+ Zena::FoxyParser.new(table, :nodes => nodes).run
324
+ when 'relations'
325
+ Zena::FoxyParser.new(table, :roles => roles).run
326
+ when 'links'
327
+ Zena::FoxyParser.new(table, :nodes => nodes).run
328
+ else
329
+ Zena::FoxyParser.new(table).run
330
+ end
327
331
  end
328
- end
329
332
 
330
- %w{db:fixtures:load zena:rebuild_index}.each do |task|
331
- puts "******************************* #{task}"
332
- Rake::Task[task].invoke
333
- end
333
+ %w{db:fixtures:load zena:rebuild_index}.each do |task|
334
+ puts "******************************* #{task}"
335
+ Rake::Task[task].invoke
336
+ end
334
337
 
335
- index_tables = Node.connection.tables.select {|t| t =~ /^idx_/ }
336
- Zena::FoxyParser.dump_fixtures(index_tables)
338
+ index_tables = Node.connection.tables.select {|t| t =~ /^idx_/ }
339
+ Zena::FoxyParser.dump_fixtures(index_tables)
340
+ end
337
341
  end
338
342
 
339
343
  desc 'Rebuild index for all sites (without SiteWorker)'
data/lib/zena.rb CHANGED
@@ -212,12 +212,11 @@ unless File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml'))
212
212
  FileUtils.cp(File.join(Zena::ROOT, 'config', 'database_example.yml'), File.join(RAILS_ROOT, 'config', 'database.yml'))
213
213
  end
214
214
 
215
- unless File.exist?(File.join(RAILS_ROOT, 'log'))
216
- FileUtils.mkpath(File.join(RAILS_ROOT, 'log'))
217
- end
218
-
219
- unless File.exist?(File.join(RAILS_ROOT, 'sites'))
220
- FileUtils.mkpath(File.join(RAILS_ROOT, 'sites'))
215
+ %w{log sites}.each do |dir|
216
+ path = File.join(RAILS_ROOT, dir)
217
+ if !File.exist?(path) && !File.symlink?(path)
218
+ FileUtils.mkpath(path)
219
+ end
221
220
  end
222
221
 
223
222
  # this list is taken from http://www.duke.edu/websrv/file-extensions.html
@@ -35,7 +35,7 @@ module Zena
35
35
 
36
36
  # We overwrite safe_method_type from RubyLess to include the properties loaded
37
37
  # with load_roles!.
38
- def safe_method_type(signature)
38
+ def safe_method_type(signature, receiver = nil)
39
39
  if signature.size == 1 && (column = loaded_role_properties[signature.first])
40
40
  RubyLess::SafeClass.safe_method_type_for_column(column, true)
41
41
  else
@@ -59,12 +59,14 @@ module Zena
59
59
  end
60
60
 
61
61
  def all_possible_roles
62
- kpaths = []
62
+ @all_possible_roles ||= begin
63
+ kpaths = []
63
64
 
64
- kpath = self.kpath || vclass.kpath
65
- kpath.split(//).each_index { |i| kpaths << kpath[0..i] }
66
- # FIXME: !! manage a memory cache for Roles
67
- Role.all(:conditions => ['kpath IN (?)', kpaths])
65
+ kpath = self.kpath || vclass.kpath
66
+ kpath.split(//).each_index { |i| kpaths << kpath[0..i] }
67
+ # FIXME: !! manage a memory cache for Roles
68
+ Role.all(:conditions => ['kpath IN (?) AND site_id = ?', kpaths, current_site.id], :order => 'kpath ASC')
69
+ end
68
70
  end
69
71
  end # LoadRoles
70
72
 
@@ -92,10 +94,13 @@ module Zena
92
94
  alias_method_chain :properties=, :enrollable
93
95
  alias_method_chain :rebuild_index!, :enrollable
94
96
 
97
+ before_validation :check_unknown_attributes
95
98
  before_validation :prepare_roles
96
99
  after_save :update_roles
97
100
  after_destroy :destroy_nodes_roles
98
101
  has_and_belongs_to_many :roles, :class_name => '::Role'
102
+ safe_context :possible_roles => {:class => [Role], :method => 'zafu_possible_roles'}
103
+ safe_context :roles => {:class => [Role], :method => 'zafu_roles'}
99
104
 
100
105
  property do |p|
101
106
  p.serialize :cached_role_ids, Array
@@ -106,6 +111,8 @@ module Zena
106
111
  def attributes_with_enrollable=(attrs)
107
112
  load_roles!
108
113
  self.attributes_without_enrollable = attrs
114
+ rescue ActiveRecord::UnknownAttributeError => err
115
+ @unknown_attribute_error = err
109
116
  end
110
117
 
111
118
  def properties_with_enrollable=(attrs)
@@ -126,7 +133,31 @@ module Zena
126
133
  rebuild_index_without_enrollable!
127
134
  end
128
135
 
136
+ def zafu_possible_roles
137
+ roles = all_possible_roles
138
+ roles.empty? ? nil : roles
139
+ end
140
+
141
+ def zafu_roles
142
+ return nil unless role_ids = self.prop['cached_role_ids']
143
+ # FIXME: memory cache for roles
144
+ roles = Role.all(:conditions => ['id IN (?) AND site_id = ?', role_ids, current_site.id], :order => 'kpath ASC')
145
+ roles.empty? ? nil : roles
146
+ end
147
+
129
148
  private
149
+ # Do not go any further if the object contains errors
150
+ def check_unknown_attributes
151
+ if @unknown_attribute_error
152
+ name = @unknown_attribute_error.message[%r{unknown attribute: (.+)}, 1]
153
+ errors.add(name, "unknown attribute")
154
+ @unknown_attribute_error = nil
155
+ false
156
+ else
157
+ true
158
+ end
159
+ end
160
+
130
161
  # Prepare roles to add/remove to object.
131
162
  def prepare_roles
132
163
  return unless prop.changed?
data/lib/zena/app.rb CHANGED
@@ -2,21 +2,23 @@ require File.join(File.dirname(__FILE__), 'info')
2
2
 
3
3
  Zena::Use.module [
4
4
  Zena::Use::Action,
5
- Zena::Use::Ajax,
6
5
  Zena::Use::Authlogic,
7
6
  Zena::Use::Calendar,
8
7
  Zena::Use::Context,
9
8
  Zena::Use::Dates,
10
- Zena::Use::Display,
11
9
  Zena::Acts::Enrollable,
12
10
  Zena::Use::ErrorRendering,
13
11
  Zena::Use::Forms,
14
12
  Zena::Use::HtmlTags,
15
13
  Zena::Use::I18n,
16
14
  Zena::Use::NestedAttributesAlias,
15
+ # Must appear before Display so that we first try to resolve as QB before r_show fallback.
17
16
  Zena::Use::QueryBuilder,
17
+ Zena::Use::Display,
18
18
  Zena::Use::Refactor,
19
19
  Zena::Use::Rendering,
20
+ # Ajax must appear after rendering because it uses 'super' in js_render
21
+ Zena::Use::Ajax,
20
22
  Zena::Use::Upload,
21
23
  Zena::Use::Urls,
22
24
  Zena::Use::ZafuAttributes,
data/lib/zena/deploy.rb CHANGED
@@ -30,14 +30,20 @@ Capistrano::Configuration.instance(:must_exist).load do
30
30
 
31
31
  set :templates, File.join(File.dirname(__FILE__), 'deploy')
32
32
  self[:app_type] ||= :mongrel
33
- self[:app_root] ||= '/var/zena/current'
34
- self[:sites_root] ||= '/var/www/zena'
33
+
34
+ self[:deploy_to] ||= "/home/#{db_name}/app"
35
+ self[:sites_root] ||= "/home/#{db_name}/sites"
36
+ self[:dump_root] ||= "/home/#{db_name}/dump"
37
+
38
+ self[:app_root] ||= "#{deploy_to}/current"
39
+
35
40
  self[:balancer] ||= db_name
41
+ self[:db_user] ||= db_name
36
42
  self[:runner] ||= 'root'
37
43
  self[:on_stop] = []
38
44
  self[:on_start] = []
39
45
 
40
- set :in_current, "cd #{deploy_to}/current &&"
46
+ set :in_current, "cd #{app_root} &&"
41
47
 
42
48
  class RenderClass
43
49
  def initialize(path)
@@ -67,12 +73,29 @@ Capistrano::Configuration.instance(:must_exist).load do
67
73
  self[:on_start] << block
68
74
  end
69
75
 
76
+ def ancestry(path)
77
+ # Build directory ancestry ['/a', '/a/b', '/a/b/c']
78
+ paths = path.split('/')[1..-1].inject(['']) do |res, cur|
79
+ res << (res.last + "/#{cur}")
80
+ res
81
+ end[1..-1]
82
+ end
83
+
70
84
  #========================== SOURCE CODE =========================#
71
85
 
72
86
 
73
87
  desc "set permissions to www-data"
74
88
  task :set_permissions, :roles => :app do
75
- run "chown -R www-data:www-data #{deploy_to}/current/public #{deploy_to}/current/log #{deploy_to}/current/tmp"
89
+ directories = [
90
+ 'current/public',
91
+ 'current/tmp',
92
+ 'current/log',
93
+ 'shared/log',
94
+ ].map {|dir| "#{deploy_to}/#{dir}"}
95
+
96
+ # make sure production.log is created before so that it gets the correct permissionsong
97
+ run "touch #{deploy_to}/shared/log/production.log"
98
+ run "chown -R www-data:www-data #{directories.join(' ')}"
76
99
  end
77
100
 
78
101
  "Update the currently released version of the software directly via an SCM update operation"
@@ -93,7 +116,7 @@ Capistrano::Configuration.instance(:must_exist).load do
93
116
  desc "after code update"
94
117
  task :after_update, :roles => :app do
95
118
  app_update_symlinks
96
- db_update_config
119
+ db::update_config
97
120
  apache2_setup
98
121
  migrate
99
122
  clear_zafu
@@ -102,7 +125,7 @@ Capistrano::Configuration.instance(:must_exist).load do
102
125
 
103
126
  desc "update symlink to 'sites' directory"
104
127
  task :app_update_symlinks, :roles => :app do
105
- run "test ! -e #{deploy_to}/current/sites || rm #{deploy_to}/current/sites"
128
+ run "test ! -e #{deploy_to}/current/sites || rm -rf #{deploy_to}/current/sites || true"
106
129
  run "ln -sf #{sites_root} #{deploy_to}/current/sites"
107
130
  set_permissions
108
131
  end
@@ -114,10 +137,11 @@ Capistrano::Configuration.instance(:must_exist).load do
114
137
 
115
138
  desc "initial app setup"
116
139
  task :app_setup, :roles => :app do
117
- gem_update
118
- run "test -e #{deploy_to} || mkdir #{deploy_to}"
119
- run "test -e #{sites_root} || mkdir #{sites_root}"
120
- deploy::setup
140
+ paths = ancestry(deploy_to) + ancestry(sites_root) + ancestry("#{deploy_to}/shared/log") + ancestry(dump_root)
141
+
142
+ paths.uniq.sort.each do |dir|
143
+ run "test -e #{dir} || mkdir #{dir}"
144
+ end
121
145
  end
122
146
 
123
147
  #========================== MANAGE HOST =========================#
@@ -133,7 +157,7 @@ Capistrano::Configuration.instance(:must_exist).load do
133
157
  desc "update code in the current version"
134
158
  task :up, :roles => :app do
135
159
  run "cd #{deploy_to}/current && #{self[:scm] == 'git' ? "git pull origin #{self[:branch] || 'master'}" : 'svn up'} && (echo #{strategy.configuration[:real_revision]} > #{deploy_to}/current/REVISION)"
136
- db_update_config
160
+ db::update_config
137
161
  clear_zafu
138
162
  clear_cache
139
163
  migrate
@@ -173,9 +197,7 @@ Capistrano::Configuration.instance(:must_exist).load do
173
197
  run "test -e /etc/apache2/sites-enabled/#{self[:host]} || a2ensite #{self[:host]}" if debian_host
174
198
 
175
199
  unless self[:host] =~ /^www/
176
- vhost_www = render("#{templates}/vhost_www.rhtml",
177
- :host => self[:host]
178
- )
200
+ vhost_www = render("#{templates}/vhost_www.rhtml", :config => self)
179
201
  put(vhost_www, "#{vhost_root}/www.#{self[:host]}")
180
202
  run "test -e /etc/apache2/sites-enabled/www.#{self[:host]} || a2ensite www.#{self[:host]}" if debian_host
181
203
  end
@@ -193,13 +215,13 @@ Capistrano::Configuration.instance(:must_exist).load do
193
215
  puts "host or password not set (use -s host=... -s pass=...)"
194
216
  else
195
217
  # create awstats config file
196
- awstats_conf = render("#{templates}/awstats.conf.rhtml", :host => self[:host] )
218
+ awstats_conf = render("#{templates}/awstats.conf.rhtml", :config => self)
197
219
  put(awstats_conf, "/etc/awstats/awstats.#{self[:host]}.conf")
198
220
  run "chown www-data:www-data /etc/awstats/awstats.#{self[:host]}.conf"
199
221
  run "chmod 640 /etc/awstats/awstats.#{self[:host]}.conf"
200
222
 
201
223
  # create stats vhost
202
- stats_vhost = render("#{templates}/stats.vhost.rhtml", :host => self[:host] )
224
+ stats_vhost = render("#{templates}/stats.vhost.rhtml", :config => self)
203
225
  put(stats_vhost, "#{vhost_root}/stats.#{self[:host]}")
204
226
  run "test -e /etc/apache2/sites-enabled/stats.#{self[:host]} || a2ensite stats.#{self[:host]}"
205
227
 
@@ -211,7 +233,7 @@ Capistrano::Configuration.instance(:must_exist).load do
211
233
  run "cat /etc/cron.d/awstats | grep \"#{self[:host]}\" || echo \"0,10,20,30,40,50 * * * * www-data [ -x /usr/lib/cgi-bin/awstats.pl -a -f /etc/awstats/awstats.#{self[:host]}.conf -a -r #{sites_root}/#{self[:host]}/log/apache2.access.log ] && /usr/lib/cgi-bin/awstats.pl -config=#{self[:host]} -update >/dev/null\n\" >> /etc/cron.d/awstats"
212
234
 
213
235
  # create .htpasswd file
214
- run "test ! -e #{sites_root}/#{self[:host]}/log/.awstatspw || rm #{sites_root}/#{self[:host]}/log/.awstatspw"
236
+ run "test ! -e #{sites_root}/#{self[:host]}/log/.awstatspw || rm #{sites_root}/#{self[:host]}/log/.awstatspw || true"
215
237
  run "htpasswd -c -b #{sites_root}/#{self[:host]}/log/.awstatspw 'admin' '#{self[:pass]}'"
216
238
  run "chmod 600 #{sites_root}/#{self[:host]}/log/.awstatspw"
217
239
  run "chown www-data:www-data #{sites_root}/#{self[:host]}/log/.awstatspw"
@@ -269,7 +291,9 @@ Capistrano::Configuration.instance(:must_exist).load do
269
291
 
270
292
  desc "Apache2 initial setup"
271
293
  task :apache2_setup, :roles => :web do
272
- self[:ports] = (mongrel_port.to_i...(mongrel_port.to_i + mongrel_count.to_i)).to_a
294
+ if self[:mongrel_port]
295
+ self[:ports] = (mongrel_port.to_i...(mongrel_port.to_i + mongrel_count.to_i)).to_a
296
+ end
273
297
  httpd_conf = render("#{templates}/httpd.rhtml", :config => self)
274
298
  log_rotate = render("#{templates}/logrotate_app.rhtml", :config => self)
275
299
  if debian_host
@@ -293,26 +317,25 @@ Capistrano::Configuration.instance(:must_exist).load do
293
317
 
294
318
  desc "install zena gem on remote server"
295
319
  task :gem_update, :roles => :app do
296
- run "gem sources -a http://gems.github.com"
297
320
  run "gem install zena"
298
321
  end
299
322
 
300
323
  #========================== MYSQL ===============================#
301
324
 
302
- desc "set database.yml file according to settings"
303
- task :db_update_config, :roles => :app do
304
- db_app_config = render("#{templates}/database.rhtml",
305
- :db_name => db_name,
306
- :db_user => db_user,
307
- :db_password => db_password
308
- )
309
- put(db_app_config, "#{deploy_to}/current/config/database.yml")
310
- end
325
+ namespace :db do
326
+ desc "set database.yml file according to settings"
327
+ task :update_config, :roles => :app do
328
+ db_app_config = render("#{templates}/database.rhtml",
329
+ :db_name => db_name,
330
+ :db_user => db_user,
331
+ :db_password => db_password
332
+ )
333
+ put(db_app_config, "#{deploy_to}/current/config/database.yml")
334
+ end
311
335
 
312
- desc "create database"
313
- task :db_create, :roles => :db do
314
- on_rollback do
315
- run "mysql -u root -p -e \"DROP DATABASE #{db_name};\"" do |channel, stream, data|
336
+ desc "create database"
337
+ task :create, :roles => :db do
338
+ run "mysql -u root -p -e \"CREATE DATABASE #{db_name} DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; GRANT ALL ON #{db_name}.* TO '#{db_user}'@'localhost' IDENTIFIED BY '#{db_password}';\"" do |channel, stream, data|
316
339
  if data =~ /^Enter password:\s*/m
317
340
  logger.info "#{channel[:host]} asked for password"
318
341
  channel.send_data "#{password}\n"
@@ -321,121 +344,73 @@ Capistrano::Configuration.instance(:must_exist).load do
321
344
  end
322
345
  end
323
346
 
324
- run "mysql -u root -p -e \"CREATE DATABASE #{db_name} DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; GRANT ALL ON #{db_name}.* TO '#{db_user}'@'localhost' IDENTIFIED BY '#{db_password}';\"" do |channel, stream, data|
325
- if data =~ /^Enter password:\s*/m
326
- logger.info "#{channel[:host]} asked for password"
327
- channel.send_data "#{password}\n"
347
+ desc "drop database"
348
+ task :drop, :roles => :db do
349
+ run "mysql -u root -p -e \"DROP DATABASE #{db_name};\"" do |channel, stream, data|
350
+ if data =~ /^Enter password:\s*/m
351
+ logger.info "#{channel[:host]} asked for password"
352
+ channel.send_data "#{password}\n"
353
+ end
354
+ puts data
328
355
  end
329
- puts data
330
356
  end
331
- end
332
357
 
333
- desc "initial database setup"
334
- task :db_setup, :roles => :db do
335
- transaction do
336
- db_create
358
+ desc "initial database setup"
359
+ task :setup, :roles => :db do
360
+ create
337
361
  end
338
- end
339
-
340
-
341
- desc "Full initial setup"
342
- task :initial_setup do
343
- transaction do
344
- app_setup
345
362
 
346
- db_setup
347
-
348
- deploy::update
349
-
350
- apache2_setup
351
-
352
- set_permissions
353
-
354
- start
355
- end
356
- end
357
-
358
- desc "Database dump"
359
- task :db_dump, :roles => :db do
360
- run "mysqldump #{db_name} -u root -p > #{deploy_to}/current/#{db_name}.sql" do |channel, stream, data|
361
- if data =~ /^Enter password:\s*/m
362
- logger.info "#{channel[:host]} asked for password"
363
- channel.send_data "#{password}\n"
363
+ desc "Database dump"
364
+ task :dump, :roles => :db do
365
+ run "mysqldump #{db_name} -u root -p | /bin/gzip > #{dump_root}/`date +%Y-%m-%d_%H:%M`.sql.gz" do |channel, stream, data|
366
+ if data =~ /^Enter password:\s*/m
367
+ logger.info "#{channel[:host]} asked for password"
368
+ channel.send_data "#{password}\n"
369
+ end
370
+ puts data
364
371
  end
365
- puts data
366
372
  end
367
- run "#{in_current} tar czf #{db_name}.sql.tgz #{db_name}.sql"
368
- run "#{in_current} rm #{db_name}.sql"
369
- end
370
-
371
- desc "Get backup file back"
372
- task :get_backup, :roles => :app do
373
- get "#{deploy_to}/current/#{db_name}_data.tgz", "./#{db_name}_#{Time.now.strftime '%Y-%m-%d-%H'}.tgz"
374
- end
375
-
376
- # FIXME: backup not loading data for every site...
377
- desc "Backup all data and bring it backup here"
378
- task :backup, :roles => :app do
379
- db_dump
380
- # key track of the current svn revision for app
381
-
382
- run "#{in_current} svn info > #{deploy_to}/current/zena_version.txt"
383
- run "#{in_current} rake zena:full_backup RAILS_ENV='production'"
384
- run "#{in_current} tar czf #{db_name}_data.tgz #{db_name}.sql.tgz sites_data.tgz zena_version.txt"
385
- get_backup
386
- end
373
+ end # db
374
+
375
+ # Would need to be fixed before being used
376
+ #
377
+ # desc "Get backup file back"
378
+ # task :get_backup, :roles => :app do
379
+ # get "#{deploy_to}/current/#{db_name}_data.tgz", "./#{db_name}_#{Time.now.strftime '%Y-%m-%d-%H'}.tgz"
380
+ # end
381
+ #
382
+ # # FIXME: backup not loading data for every site...
383
+ # desc "Backup all data and bring it backup here"
384
+ # task :backup, :roles => :app do
385
+ # db_dump
386
+ # # key track of the current svn revision for app
387
+ #
388
+ # run "#{in_current} svn info > #{deploy_to}/current/zena_version.txt"
389
+ # run "#{in_current} rake zena:full_backup RAILS_ENV='production'"
390
+ # run "#{in_current} tar czf #{db_name}_data.tgz #{db_name}.sql.tgz sites_data.tgz zena_version.txt"
391
+ # get_backup
392
+ # end
387
393
 
388
394
  Bricks.load_filename('deploy')
389
395
 
396
+ #========================== DEPLOY ===============================#
390
397
 
391
- #========================== MONGREL ===============================#
392
- namespace :mongrel do
393
-
394
- desc "configure mongrel"
395
- task :configure, :roles => :app do
396
- run "#{in_current} mongrel_rails cluster::configure -e production -p #{mongrel_port} -N #{mongrel_count} -c #{deploy_to}/current -P log/mongrel.pid -l log/mongrel.log -a 127.0.0.1 --user www-data --group www-data"
397
- run "#{in_current} echo 'config_script: config/mongrel_upload_progress.conf' >> config/mongrel_cluster.yml"
398
- end
398
+ namespace :zena do
399
+ desc "Prepare server for deployment"
400
+ task :setup, :roles => :app do
401
+ transaction do
402
+ app_setup
399
403
 
400
- desc "Stop the drb upload_progress server"
401
- task :upload_progress_stop , :roles => :app do
402
- run "#{in_current} ruby lib/upload_progress_server.rb stop"
403
- end
404
-
405
- desc "Start the drb upload_progress server"
406
- task :upload_progress_start , :roles => :app do
407
- run "#{in_current} lib/upload_progress_server.rb start"
408
- end
409
-
410
- desc "Restart the upload_progress server"
411
- task :upload_progress_restart, :roles => :app do
412
- upload_progress_stop
413
- upload_progress_start
414
- end
415
-
416
- desc "Restart mongrels"
417
- task :restart, :roles => :app do
418
- stop
419
- start
420
- end
404
+ db::setup
421
405
 
422
- desc "Start mongrels"
423
- task :start, :roles => :app do
424
- configure
425
- upload_progress_start
426
- run "#{in_current} mongrel_rails cluster::start"
427
- end
428
-
429
- desc "Stop mongrels"
430
- task :stop, :roles => :app do
431
- configure
432
- upload_progress_stop
433
- run "#{in_current} mongrel_rails cluster::stop"
406
+ apache2_setup
407
+ end
434
408
  end
435
409
  end
436
410
 
437
- namespace :deploy do
411
+ before 'deploy:setup', 'zena:setup'
438
412
 
413
+ namespace :deploy do
439
414
  desc "Restart application"
440
415
  task :restart, :roles => :app do
441
416
 
@@ -446,12 +421,8 @@ Capistrano::Configuration.instance(:must_exist).load do
446
421
  self[:on_start].each do |block|
447
422
  block.call
448
423
  end
449
- case self[:app_type]
450
- when :mongrel
451
- mongrel.restart
452
- else
453
- puts "'#{self[:app_type]}' not supported."
454
- end
424
+
425
+ app.restart
455
426
  end
456
427
 
457
428
  desc "Start application"
@@ -461,12 +432,7 @@ Capistrano::Configuration.instance(:must_exist).load do
461
432
  block.call
462
433
  end
463
434
 
464
- case self[:app_type]
465
- when :mongrel
466
- mongrel.start
467
- else
468
- puts "'#{self[:app_type]}' not supported."
469
- end
435
+ app.start
470
436
  end
471
437
 
472
438
  desc "Stop application"
@@ -476,14 +442,8 @@ Capistrano::Configuration.instance(:must_exist).load do
476
442
  block.call
477
443
  end
478
444
 
479
- case self[:app_type]
480
- when :mongrel
481
- mongrel.stop
482
- else
483
- puts "'#{self[:app_type]}' not supported."
484
- end
445
+ app.stop
485
446
  end
486
447
 
487
- end
488
-
448
+ end # mongrel/deploy
489
449
  end