zena 0.16.0 → 0.16.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.16.1 2010-01-16
2
+
3
+ * 3 minor enhancements
4
+ * rewrite of rake and capistrano tasks for sphinx brick
5
+ * rewrite of rake and capistrano tasks for worker brick
6
+ * fixed asset copying (should not overwrite without asking)
7
+
1
8
  == 0.16.0 2010-01-15
2
9
 
3
10
  * 3 major enhancements:
data/app/models/site.rb CHANGED
@@ -315,7 +315,6 @@ class Site < ActiveRecord::Base
315
315
  Site.connection.execute "DELETE FROM caches WHERE site_id = #{self[:id]}"
316
316
  Site.connection.execute "DELETE FROM cached_pages_nodes WHERE cached_pages_nodes.node_id IN (SELECT nodes.id FROM nodes WHERE nodes.site_id = #{self[:id]})"
317
317
  Site.connection.execute "DELETE FROM cached_pages WHERE site_id = #{self[:id]}"
318
- Node.connection.execute "UPDATE nodes SET fullpath = NULL, basepath = NULL WHERE site_id = #{self[:id]}"
319
318
  end
320
319
 
321
320
  if clear_zafu
@@ -42,7 +42,7 @@ module Bricks
42
42
  begin
43
43
  require 'thinking_sphinx/deltas/delayed_delta'
44
44
  ThinkingSphinx::Deltas::DelayedDelta
45
- has_dd = Bricks::CONFIG['delayed_job']
45
+ has_dd = Bricks::CONFIG['worker']
46
46
  rescue LoadError
47
47
  has_dd = false
48
48
  end
@@ -1,20 +1,48 @@
1
1
  require 'thinking_sphinx/deploy/capistrano'
2
2
 
3
3
  Capistrano::Configuration.instance(:must_exist).load do
4
-
5
- # FIXME: we should find a way to write a clean 'before' hook
6
- # so that this is simply appeded to existing rules !!
7
- task :before_update_code, :roles => [:app] do
8
- thinking_sphinx.stop
4
+ task :sphinx_stop, :roles => [:app] do
5
+ # stop sphinx search daemon
6
+ run "#{in_current} rake RAILS_ENV=production sphinx:stop"
9
7
  end
10
8
 
11
- task :after_update_code, :roles => [:app] do
12
- symlink_sphinx_indexes
13
- thinking_sphinx.configure
14
- thinking_sphinx.start
9
+ task :sphinx_start, :roles => [:app] do
10
+ # make sure sphinx can access the indexes
11
+ sphinx_symlink_indexes
12
+ # make sure a cron indexer is in place
13
+ sphinx_setup_indexer
14
+ # start search daemon
15
+ run "#{in_current} rake RAILS_ENV=production sphinx:start"
15
16
  end
16
17
 
17
- task :symlink_sphinx_indexes, :roles => [:app] do
18
+ task :sphinx_symlink_indexes, :roles => [:app] do
19
+ run "test -e #{shared_path}/db || mkdir #{shared_path}/db"
20
+ run "test -e #{shared_path}/db/sphinx || mkdir #{shared_path}/db/sphinx"
18
21
  run "ln -nfs #{shared_path}/db/sphinx #{current_path}/db/sphinx"
19
22
  end
20
- end
23
+
24
+ task :sphinx_setup, :roles => [:app] do
25
+ # setup sphinx
26
+ run "#{in_current} rake RAILS_ENV=production sphinx:setup"
27
+ end
28
+
29
+ task :sphinx_index, :roles => [:app] do
30
+ # rebuild sphinx index now
31
+ run "#{in_current} rake RAILS_ENV=production sphinx:index"
32
+ end
33
+
34
+ task :sphinx_setup_indexer, :roles => [:app] do
35
+ # install cron job to rebuild indexes
36
+ run "#{in_current} rake RAILS_ENV=production sphinx:setup_indexer"
37
+ end
38
+
39
+ # Hook start/stop methods into app start/stop/restart
40
+
41
+ on_stop do
42
+ sphinx_stop
43
+ end
44
+
45
+ on_start do
46
+ sphinx_start
47
+ end
48
+ end
@@ -4,8 +4,9 @@ test:
4
4
  production:
5
5
  enable_star: 1
6
6
  min_infix_len: 2
7
- pid_file: /var/zena/shared/tmp/searchd.pid
7
+ pid_file: /var/zena/shared/log/searchd.pid
8
8
  searchd_files: /var/zena/shared/db/sphinx
9
+ run_indexer_at: "10,40"
9
10
 
10
11
  development:
11
12
  enable_star: 1
@@ -1,21 +1,138 @@
1
- require 'thinking_sphinx'
2
- require 'thinking_sphinx/tasks'
3
-
4
- begin
5
- require 'thinking_sphinx/deltas/delayed_delta/tasks'
6
- require 'thinking_sphinx/deltas/delayed_delta' # we need this line for the ts:dd job runner
7
- rescue LoadError
8
- # no delayed_delta
9
- end
1
+ # The ThinkingSphinx::Configuration needs RAILS_ROOT and RAILS_ENV in order to function. Only 'setup' needs the
2
+ # environment since it needs to get configuration settings from the classes in zena.
3
+ require 'tempfile'
4
+ require 'yaml'
10
5
 
11
6
  namespace :sphinx do
7
+ setup_done = File.exist?("#{RAILS_ROOT}/config/#{RAILS_ENV}.sphinx.conf")
8
+
9
+ desc "Create a default configuration file and generate sphinx query"
10
+ task :setup => :environment do
11
+ # TODO: find another way to make sure the models are loaded:
12
+ [Node, Version]
12
13
 
13
- desc "Create a default configuration file"
14
- task :config do
15
14
  if File.exist?("#{RAILS_ROOT}/config/sphinx.yml")
16
- puts "#{RAILS_ROOT}/config/sphinx.yml exists, not copying"
15
+ puts "Sphinx searchd: config/sphinx.yml exists, not copying"
17
16
  else
18
17
  FileUtils.cp(File.join(File.dirname(__FILE__), 'sphinx.yml'), "#{RAILS_ROOT}/config/sphinx.yml")
18
+ puts "Sphinx searchd: created initial config/sphinx.yml"
19
+ end
20
+
21
+ sphinx_conf = ThinkingSphinx::Configuration.instance
22
+
23
+ # We need this mess because mkdir_p does not properly resolve symlinks
24
+ db_path = sphinx_conf.searchd_file_path
25
+ base = File.dirname(db_path)
26
+ sym_base = `readlink #{base.inspect}`
27
+ if sym_base != '' && $? == 0
28
+ base = sym_base.chomp
29
+ end
30
+
31
+ db_path = File.join(base, File.basename(db_path))
32
+
33
+ FileUtils.mkdir_p db_path
34
+
35
+ sphinx_conf.build
36
+ puts "Sphinx searchd: created Sphinx configuration (#{sphinx_conf.config_file})"
37
+ end
38
+
39
+ desc "Create a crontab entry to run the indexer every 30 minutes"
40
+ task :setup_indexer do
41
+ Rake::Task['sphinx:setup'].invoke if !setup_done
42
+
43
+ config = YAML.load_file(File.join(RAILS_ROOT, 'config', 'sphinx.yml'))[RAILS_ENV]
44
+ every = config['run_indexer_at'] || '10,40'
45
+ res = `crontab -l 2>&1`
46
+ if $? != 0 || res =~ /crontab/
47
+ puts "Sphinx indexer: could not access crontab (#{res.chomp})"
48
+ else
49
+ crontab = res.chomp.split("\n")
50
+ res = []
51
+ job = "#{every} * * * * /usr/bin/rake RAILS_ENV=production sphinx:index >> /root/cron.log 2>&1"
52
+ job_inserted = false
53
+ job_action = 'install'
54
+ crontab.each do |line|
55
+ if line =~ /sphinx:index/
56
+ if !job_inserted
57
+ # update
58
+ res << job
59
+ job_inserted = true
60
+ job_action = 'update'
61
+ end
62
+ else
63
+ res << line
64
+ end
65
+ end
66
+
67
+ if !job_inserted
68
+ # new entry in crontab
69
+ res << job
70
+ end
71
+
72
+ tmpf = Tempfile.new('crontab')
73
+ File.open(tmpf.path, 'wb') do |file|
74
+ file.puts res.join("\n")
75
+ end
76
+ user = `whoami`
77
+ res = `crontab -u #{user.chomp} #{tmpf.path}`
78
+ if $? == 0
79
+ puts "Sphinx indexer: cron job #{job_action} ok"
80
+ else
81
+ puts "Sphinx indexer: could not #{job_action} cron job\n#{res}"
82
+ end
83
+ end
84
+ end
85
+
86
+ desc "Start a Sphinx searchd daemon using Thinking Sphinx's settings"
87
+ task :start do
88
+ sphinx_conf = ThinkingSphinx::Configuration.instance
89
+
90
+ Rake::Task['sphinx:setup'].invoke if !setup_done
91
+
92
+ if ThinkingSphinx.sphinx_running?
93
+ puts "Sphinx searchd: already started (pid #{ThinkingSphinx.sphinx_pid})"
94
+ else
95
+ Dir["#{sphinx_conf.searchd_file_path}/*.spl"].each { |file| File.delete(file) }
96
+
97
+ sphinx_conf.controller.start
98
+
99
+ if ThinkingSphinx.sphinx_running?
100
+ puts "Sphinx searchd: started successfully (pid #{ThinkingSphinx.sphinx_pid})."
101
+ else
102
+ tail = `tail -n 10 #{sphinx_conf.searchd_log_file.inspect}`
103
+ puts "Sphinx searchd: failed to start.\n#{tail}"
104
+ end
105
+ end
106
+ end
107
+
108
+ desc "Stop Sphinx searchd"
109
+ task :stop do
110
+ unless ThinkingSphinx.sphinx_running?
111
+ puts "Sphinx searchd: already stopped."
112
+ else
113
+ ThinkingSphinx::Configuration.instance.controller.stop
114
+ puts "Sphinx searchd: stopped (pid #{ThinkingSphinx.sphinx_pid})."
19
115
  end
20
116
  end
117
+
118
+ desc "Restart Sphinx searchd"
119
+ task :restart do
120
+ Rake::Task['sphinx:stop'].invoke
121
+ sleep(1)
122
+ Rake::Task['sphinx:start'].invoke
123
+ end
124
+
125
+ desc "Index data for Sphinx using Thinking Sphinx's settings"
126
+ task :index do
127
+
128
+ Rake::Task['sphinx:setup'].invoke if !setup_done
129
+
130
+ res = ThinkingSphinx::Configuration.instance.controller.index
131
+ if $? == 0
132
+ puts "Sphinx searchd: successfully indexed data"
133
+ else
134
+ puts "Sphinx searchd: indexing failed\n#{res}"
135
+ end
136
+ end
137
+
21
138
  end
File without changes
@@ -0,0 +1,22 @@
1
+ require 'thinking_sphinx/deploy/capistrano'
2
+
3
+ Capistrano::Configuration.instance(:must_exist).load do
4
+
5
+ task :worker_stop, :roles => [:app] do
6
+ # stop delayed job worker
7
+ run "#{in_current} rake RAILS_ENV=production worker:stop"
8
+ end
9
+
10
+ on_stop do
11
+ worker_stop
12
+ end
13
+
14
+ task :worker_start, :roles => [:app] do
15
+ # start delayed job worker
16
+ run "#{in_current} rake RAILS_ENV=production worker:start"
17
+ end
18
+
19
+ on_start do
20
+ worker_start
21
+ end
22
+ end
File without changes
@@ -0,0 +1,68 @@
1
+
2
+ class WorkerCmd
3
+ OK_MESSAGE = {'start' => 'started', 'stop' => 'stopped'}
4
+ def initialize(name, script)
5
+ @name = name
6
+ @script = script
7
+ end
8
+
9
+ def execute(cmd)
10
+ res = `cd #{RAILS_ROOT} && #{@script} RAILS_ENV=#{RAILS_ENV} #{cmd}`
11
+ if $? == 0
12
+ puts "#{@name}: #{OK_MESSAGE[cmd]} (pid #{pid})"
13
+ else
14
+ puts "#{@name}: failed to #{cmd}\n#{res}"
15
+ end
16
+ @pid = nil
17
+ end
18
+
19
+ def start
20
+ if running?
21
+ puts "#{@name}: already started (pid #{pid})"
22
+ else
23
+ execute('start')
24
+ end
25
+ end
26
+
27
+ def stop
28
+ if !running?
29
+ puts "#{@name}: already stopped"
30
+ else
31
+ execute('stop')
32
+ end
33
+ end
34
+
35
+ def pid_file
36
+ @pid_file ||= File.expand_path(File.join(RAILS_ROOT, 'log', "#{@name}.pid"))
37
+ end
38
+
39
+ def pid
40
+ @pid ||= File.exists?(pid_file) ? File.read(pid_file)[/\d+/] : nil
41
+ end
42
+
43
+ def running?
44
+ pid && Process.kill(0, pid.to_i) rescue false
45
+ end
46
+ end
47
+
48
+
49
+ namespace :worker do
50
+ worker = WorkerCmd.new('worker', File.expand_path(File.join(File.dirname(__FILE__), 'worker')))
51
+
52
+ desc "Start the delayed jobs worker"
53
+ task :start do
54
+ worker.start
55
+ end
56
+
57
+ desc "Stop the delayed jobs worker"
58
+ task :stop do
59
+ worker.stop
60
+ end
61
+
62
+ desc "Restart the delayed jobs worker"
63
+ task :restart do
64
+ worker.stop
65
+ sleep(1)
66
+ worker.start
67
+ end
68
+ end
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'daemons'
4
+
5
+ env, cmd = 'development', nil
6
+ ARGV.each do |arg|
7
+ if arg =~ /RAILS_ENV\s*=\s*(\w+)/
8
+ env = $1
9
+ else
10
+ cmd = arg
11
+ end
12
+ end
13
+
14
+ unless %w{index start stop restart}.include?(cmd)
15
+ puts "Usage: script/sphinx RAILS_ENV=production [index|start|stop|restart]"
16
+ exit -1
17
+ end
18
+
19
+ dir = File.expand_path('.')
20
+
21
+ daemon_options = {
22
+ :multiple => false,
23
+ :dir_mode => :normal,
24
+ :dir => File.join(dir, 'log'),
25
+ :backtrace => true
26
+ }
27
+
28
+ ARGV.clear
29
+ ARGV << cmd
30
+
31
+ Daemons.run_proc('worker', daemon_options) do
32
+ ARGV.clear
33
+
34
+ Dir.chdir dir
35
+ ENV['RAILS_ENV'] = RAILS_ENV = env
36
+ require File.join('config', 'environment')
37
+ require 'delayed_job'
38
+
39
+ Delayed::Worker.new.start
40
+ end
data/config/bricks.yml CHANGED
@@ -2,7 +2,7 @@ test:
2
2
  tags: ON
3
3
  captcha: ON
4
4
  sphinx: OFF
5
- delayed_job: OFF
5
+ worker: OFF
6
6
 
7
7
  development:
8
8
  tags: ON
@@ -14,7 +14,7 @@ development:
14
14
  adapter: 'mysql,postgresql'
15
15
  run_if:
16
16
  file: 'log/searchd.development.pid'
17
- delayed_job:
17
+ worker:
18
18
  switch: OFF
19
19
  activate_if:
20
20
  gem: 'delayed_job'
@@ -29,7 +29,7 @@ production:
29
29
  adapter: 'mysql,postgresql'
30
30
  run_if:
31
31
  file: 'log/searchd.production.pid'
32
- delayed_job:
32
+ worker:
33
33
  switch: ON
34
34
  activate_if:
35
35
  gem: 'delayed_job'
data/config/deploy.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  set :db_name, "zena" # If you change this: no dots in this name !
2
- set :server_ip, 3333 # FIXME: set this to your remote server IP in the form: "215.0.0.1"
2
+ set :server_ip, nil # FIXME: set this to your remote server IP in the form: "215.0.0.1"
3
3
  set :mongrel_port, "8000"
4
4
  set :mongrel_count, "3"
5
5
  set :db_password, nil # FIXME: set password (can be anything).
@@ -32,7 +32,16 @@ if self[:server_ip]
32
32
  if !defined?(::RAILS_ENV)
33
33
  ::RAILS_ENV = 'production'
34
34
  end
35
- require 'zena/deploy'
35
+
36
+ # This file is copied into zena applications.
37
+ deploy_path = "#{RAILS_ROOT}/lib/zena/deploy"
38
+ if File.exist?("#{deploy_path}.rb")
39
+ # We are running directly inside zena
40
+ require deploy_path
41
+ else
42
+ # Zena app, using zena as gem
43
+ require 'zena/deploy'
44
+ end
36
45
 
37
46
  else
38
47
  puts <<-TXT
data/config/gems.yml CHANGED
@@ -23,13 +23,13 @@ thinking-sphinx:
23
23
  optional: yes
24
24
  source: 'http://gemcutter.org'
25
25
  lib: 'thinking_sphinx'
26
- version: '>= 1.3.1'
26
+ version: '>= 1.3.14'
27
27
 
28
28
  ts-delayed-delta:
29
29
  optional: yes
30
30
  source: 'http://gemcutter.org'
31
31
  lib: 'thinking_sphinx/deltas/delayed_delta'
32
- version: '>= 1.0.0'
32
+ version: '>= 1.0.2'
33
33
 
34
34
  delayed_job:
35
35
  optional: yes
@@ -61,4 +61,3 @@ thoughtbot-shoulda:
61
61
 
62
62
  jeweler:
63
63
  version: '>= 1.4.0'
64
- development_only: true
data/config/sphinx.yml CHANGED
@@ -5,6 +5,7 @@ production:
5
5
  enable_star: 1
6
6
  min_infix_len: 2
7
7
  sql_range_step: 10000000
8
+ run_indexer_at: "10,40"
8
9
 
9
10
  development:
10
11
  enable_star: 1
@@ -1,7 +1,11 @@
1
1
  class AddPersistenceToken < ActiveRecord::Migration
2
+ User.reset_column_information
2
3
  def self.up
3
4
  add_column :users, :persistence_token, :string
4
- add_column :users, :password_salt, :string
5
+ unless User.column_names.include?('password_salt')
6
+ # Strangely some legacy apps already have the password_salt. Better be safe.
7
+ add_column :users, :password_salt, :string
8
+ end
5
9
  rename_column :users, :password, :crypted_password
6
10
  end
7
11
 
@@ -1,5 +1,11 @@
1
1
  class RebuildFullpath < ActiveRecord::Migration
2
2
  def self.up
3
+
4
+ # Reset column information (used when running all migrations at once)
5
+ [User, Node, Version, Site, Group].each do |klass|
6
+ klass.reset_column_information
7
+ end
8
+
3
9
  Site.all.each do |site|
4
10
  puts "===== rebuilding fullpath for #{site.host} (#{Node.count(:conditions => "site_id = #{site.id}")} nodes)"
5
11
  site.rebuild_fullpath
@@ -0,0 +1,11 @@
1
+ class RebuildFullpathAfterFix < ActiveRecord::Migration
2
+ def self.up
3
+ Site.all.each do |site|
4
+ puts "===== rebuilding fullpath for #{site.host} (#{Node.count(:conditions => "site_id = #{site.id}")} nodes)"
5
+ site.rebuild_fullpath
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ end
11
+ end
data/db/schema.rb CHANGED
@@ -9,7 +9,7 @@
9
9
  #
10
10
  # It's strongly recommended to check this file into your version control system.
11
11
 
12
- ActiveRecord::Schema.define(:version => 20091124161608) do
12
+ ActiveRecord::Schema.define(:version => 20100115134729) do
13
13
 
14
14
  create_table "cached_pages", :force => true do |t|
15
15
  t.text "path"
data/lib/tasks/zena.rake CHANGED
@@ -59,6 +59,8 @@ def copy_assets(from, to)
59
59
  end
60
60
  end
61
61
 
62
+ COPY_FILE_OVERWRITE_ALL = {}
63
+
62
64
  def copy_files(from, to)
63
65
  base = File.dirname(to)
64
66
  unless File.exist?(base)
@@ -69,6 +71,32 @@ def copy_files(from, to)
69
71
  next if f =~ /\A./
70
72
  copy_files("#{from}/#{f}", "#{to}/#{f}")
71
73
  end
74
+ elsif File.exist?(to)
75
+ if COPY_FILE_OVERWRITE_ALL.has_key?(base)
76
+ if COPY_FILE_OVERWRITE_ALL[base]
77
+ FileUtils.cp(from, base)
78
+ else
79
+ # skip
80
+ end
81
+ elsif File.read(from) != File.read(to)
82
+ # ask
83
+ puts "\n## exists: #{to}\n (a= overwrite all in same destination, s= overwrite none in same destination)"
84
+ print " overwrite (ayNs) ? "
85
+ answer = STDIN.gets.chomp.downcase
86
+ case answer
87
+ when 'y'
88
+ FileUtils.cp(from, base)
89
+ when 'a'
90
+ COPY_FILE_OVERWRITE_ALL[base] = true
91
+ puts "overwrite all in #{base}"
92
+ FileUtils.cp(from, base)
93
+ when 's'
94
+ COPY_FILE_OVERWRITE_ALL[base] = false
95
+ puts "overwrite none in #{base}"
96
+ else
97
+ puts "skip #{to}"
98
+ end
99
+ end
72
100
  else
73
101
  FileUtils.cp(from, base)
74
102
  end
@@ -395,20 +423,28 @@ namespace :zena do
395
423
  end
396
424
  end
397
425
 
398
- desc "Create the database, migrate, create 'localhost' site and start application"
426
+ desc "Create the database, migrate, create 'localhost' site and start application (in production environment by default)"
399
427
  task :init do
400
428
  # FIXME: how to run sub-task
401
- [
402
- "rake zena:migrate RAILS_ENV=production",
403
- "rake zena:mksite HOST='localhost' PASSWORD='admin' LANG='en' RAILS_ENV=production",
404
- "#{Gem.win_platform? ? 'start' : 'open'} #{File.join(Zena::ROOT, 'lib/zena/deploy/start.html')}"
405
- ].each do |cmd|
406
- puts cmd
407
- system(cmd)
408
- end
409
- cmd = "script/server -e production -p 3211"
429
+ ENV['RAILS_ENV'] = RAILS_ENV || 'production'
430
+ ENV['HOST'] ||= 'localhost'
431
+ ENV['LANG'] ||= 'en'
432
+ ENV['PASSWORD'] ||= 'admin'
433
+
434
+ Rake::Task["db:create"].invoke
435
+ Rake::Task["zena:migrate"].invoke
436
+
437
+ # We cannot use 'invoke' here because the User class needs to be reloaded
438
+ env = %w{RAILS_ENV HOST LANG PASSWORD}.map{|e| "#{e}=#{ENV[e]}"}.join(' ')
439
+ cmd = "rake zena:mksite #{env}"
440
+ puts cmd
441
+ system(cmd)
442
+
443
+ system("#{Gem.win_platform? ? 'start' : 'open'} #{File.join(Zena::ROOT, 'lib/zena/deploy/start.html')}")
444
+
445
+ cmd = "script/server -e #{ENV['RAILS_ENV']} -p 3211"
410
446
  puts cmd
411
447
  exec cmd
412
448
  end
413
449
 
414
- end
450
+ end
data/lib/zena/deploy.rb CHANGED
@@ -27,13 +27,18 @@ require File.join(File.dirname(__FILE__), 'info')
27
27
  require File.join(File.dirname(__FILE__), '..', 'bricks')
28
28
 
29
29
  Capistrano::Configuration.instance(:must_exist).load do
30
+
30
31
  set :templates, File.join(File.dirname(__FILE__), 'deploy')
31
32
  self[:app_type] ||= :mongrel
32
33
  self[:app_root] ||= '/var/zena/current'
33
34
  self[:sites_root] ||= '/var/www/zena'
34
35
  self[:balancer] ||= db_name
36
+ self[:runner] ||= 'root'
37
+ self[:on_stop] = []
38
+ self[:on_start] = []
35
39
 
36
40
  set :in_current, "cd #{deploy_to}/current &&"
41
+
37
42
  class RenderClass
38
43
  def initialize(path)
39
44
  @text = File.read(path)
@@ -54,6 +59,14 @@ Capistrano::Configuration.instance(:must_exist).load do
54
59
  RenderClass.new(file).render(hash)
55
60
  end
56
61
 
62
+ def on_stop(&block)
63
+ self[:on_stop] << block
64
+ end
65
+
66
+ def on_start(&block)
67
+ self[:on_start] << block
68
+ end
69
+
57
70
  #========================== SOURCE CODE =========================#
58
71
 
59
72
 
@@ -69,12 +82,12 @@ Capistrano::Configuration.instance(:must_exist).load do
69
82
 
70
83
  desc "clear all zafu compiled templates"
71
84
  task :clear_zafu, :roles => :app do
72
- run "#{in_current} rake zena:clear_zafu RAILS_ENV=production"
85
+ run "#{in_current} rake RAILS_ENV=production zena:clear_zafu"
73
86
  end
74
87
 
75
88
  desc "clear all cache compiled templates"
76
89
  task :clear_cache, :roles => :app do
77
- run "#{in_current} rake zena:clear_cache RAILS_ENV=production"
90
+ run "#{in_current} rake RAILS_ENV=production zena:clear_cache"
78
91
  end
79
92
 
80
93
  desc "after code update"
@@ -96,7 +109,7 @@ Capistrano::Configuration.instance(:must_exist).load do
96
109
 
97
110
  desc "migrate database (zena version)"
98
111
  task :migrate, :roles => :db do
99
- run "#{in_current} rake zena:migrate RAILS_ENV=production"
112
+ run "#{in_current} rake RAILS_ENV=production zena:migrate"
100
113
  end
101
114
 
102
115
  desc "initial app setup"
@@ -133,46 +146,19 @@ Capistrano::Configuration.instance(:must_exist).load do
133
146
  restart
134
147
  end
135
148
 
136
- #========================== MONGREL ===============================#
137
- desc "configure mongrel"
138
- task :mongrel_setup, :roles => :app do
139
- 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"
140
- run "#{in_current} echo 'config_script: config/mongrel_upload_progress.conf' >> config/mongrel_cluster.yml"
141
- end
142
-
143
- desc "Stop the drb upload_progress server"
144
- task :stop_upload_progress , :roles => :app do
145
- run "#{in_current} ruby lib/upload_progress_server.rb stop"
146
- end
147
-
148
- desc "Start the drb upload_progress server"
149
- task :start_upload_progress , :roles => :app do
150
- run "#{in_current} lib/upload_progress_server.rb start"
151
- end
152
-
153
- desc "Restart the upload_progress server"
154
- task :restart_upload_progress, :roles => :app do
155
- stop_upload_progress
156
- start_upload_progress
149
+ desc "Restart application"
150
+ task :restart, :roles => :app do
151
+ deploy.restart
157
152
  end
158
153
 
159
- desc "Start mongrel"
154
+ desc "Start application"
160
155
  task :start, :roles => :app do
161
- restart_upload_progress
162
- run "#{in_current} mongrel_rails cluster::start"
156
+ deploy.start
163
157
  end
164
158
 
165
- desc "Stop mongrel"
159
+ desc "Stop application"
166
160
  task :stop, :roles => :app do
167
- stop_upload_progress
168
- run "#{in_current} mongrel_rails cluster::stop"
169
- end
170
-
171
- desc "Restart mongrel"
172
- task :restart, :roles => :app do
173
- stop
174
- restart_upload_progress
175
- start
161
+ deploy.stop
176
162
  end
177
163
 
178
164
  #========================== APACHE2 ===============================#
@@ -361,8 +347,6 @@ Capistrano::Configuration.instance(:must_exist).load do
361
347
 
362
348
  deploy::update
363
349
 
364
- mongrel_setup
365
-
366
350
  apache2_setup
367
351
 
368
352
  set_permissions
@@ -402,4 +386,104 @@ Capistrano::Configuration.instance(:must_exist).load do
402
386
  end
403
387
 
404
388
  Bricks.load_misc('deploy')
389
+
390
+
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
399
+
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
421
+
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"
434
+ end
435
+ end
436
+
437
+ namespace :deploy do
438
+
439
+ desc "Restart application"
440
+ task :restart, :roles => :app do
441
+
442
+ self[:on_stop].each do |block|
443
+ block.call
444
+ end
445
+
446
+ self[:on_start].each do |block|
447
+ block.call
448
+ end
449
+ case self[:app_type]
450
+ when :mongrel
451
+ mongrel.restart
452
+ else
453
+ puts "'#{self[:app_type]}' not supported."
454
+ end
455
+ end
456
+
457
+ desc "Start application"
458
+ task :start, :roles => :app do
459
+
460
+ self[:on_start].each do |block|
461
+ block.call
462
+ end
463
+
464
+ case self[:app_type]
465
+ when :mongrel
466
+ mongrel.start
467
+ else
468
+ puts "'#{self[:app_type]}' not supported."
469
+ end
470
+ end
471
+
472
+ desc "Stop application"
473
+ task :stop, :roles => :app do
474
+
475
+ self[:on_stop].each do |block|
476
+ block.call
477
+ end
478
+
479
+ case self[:app_type]
480
+ when :mongrel
481
+ mongrel.stop
482
+ else
483
+ puts "'#{self[:app_type]}' not supported."
484
+ end
485
+ end
486
+
487
+ end
488
+
405
489
  end
data/lib/zena/info.rb CHANGED
@@ -9,7 +9,7 @@ ZENA_CALENDAR_LANGS = ["en", "fr"] # FIXME: build this dynamically from existing
9
9
  ENABLE_XSENDFILE = false
10
10
 
11
11
  module Zena
12
- VERSION = '0.16.0'
12
+ VERSION = '0.16.1'
13
13
  REVISION = 1336
14
14
  ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
15
15
  end
@@ -227,7 +227,7 @@ class SiteTest < Zena::Unit::TestCase
227
227
  assert_equal Hash['w'=>{'fr' => versions_id(:opening_red_fr), 'en' => versions_id(:opening_en)},
228
228
  'r'=>{'fr' => versions_id(:opening_fr), 'en' => versions_id(:opening_en)}], opening.vhash
229
229
  end
230
-
230
+
231
231
  def test_rebuild_fullpath
232
232
  login(:tiger)
233
233
  Node.connection.execute "UPDATE nodes SET fullpath = NULL"
@@ -239,17 +239,32 @@ class SiteTest < Zena::Unit::TestCase
239
239
  assert_equal 'projects/cleanWater/status', status.fullpath
240
240
  assert_equal 'projects/cleanWater', status.basepath
241
241
  assert_equal false, status.custom_base
242
-
242
+
243
243
  assert_equal 'projects/cleanWater/opening', opening.fullpath
244
244
  assert_equal 'projects/cleanWater', opening.basepath
245
245
  assert_equal false, opening.custom_base
246
-
246
+
247
247
  assert_equal 'projects/cleanWater', cleanWater.fullpath
248
248
  assert_equal 'projects/cleanWater', cleanWater.basepath
249
249
  assert_equal true, cleanWater.custom_base
250
-
250
+
251
251
  assert_equal 'collections/art', art.fullpath
252
252
  assert_equal '', art.basepath
253
253
  assert_equal false, art.custom_base
254
254
  end
255
+
256
+ context 'Clearing a site cache' do
257
+ setup do
258
+ login(:tiger)
259
+ @site = visitor.site
260
+ end
261
+
262
+ should 'not alter fullpath' do
263
+ node = secure!(Node) { nodes(:status) }
264
+ assert_equal 'projects/cleanWater/status', node.fullpath
265
+ @site.clear_cache
266
+ node = secure!(Node) { nodes(:status) }
267
+ assert_equal 'projects/cleanWater/status', node.fullpath
268
+ end
269
+ end
255
270
  end
@@ -272,4 +272,26 @@ class UserTest < Zena::Unit::TestCase
272
272
  login(:lion)
273
273
  assert_equal ['hello'], visitor.to_publish.map {|r| r.node.name}
274
274
  end
275
+
276
+ context 'Creating a new user' do
277
+ setup do
278
+ login(:lion)
279
+ end
280
+
281
+ context 'with new' do
282
+ should 'accept a password attribute' do
283
+ user = nil
284
+ assert_nothing_raised { user = User.new('name' => 'R2D2', 'password' => 'Artoo') }
285
+ assert_equal Zena::CryptoProvider::Initial.encrypt('Artoo'), user.crypted_password
286
+ end
287
+ end
288
+
289
+ context 'with new_no_defaults' do
290
+ should 'accept a password attribute' do
291
+ user = nil
292
+ assert_nothing_raised { user = User.new_no_defaults('name' => 'R2D2', 'password' => 'Artoo') }
293
+ assert_equal Zena::CryptoProvider::Initial.encrypt('Artoo'), user.crypted_password
294
+ end
295
+ end
296
+ end
275
297
  end
data/zena.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{zena}
8
- s.version = "0.16.0"
8
+ s.version = "0.16.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Gaspard Bucher"]
12
- s.date = %q{2010-01-15}
12
+ s.date = %q{2010-01-16}
13
13
  s.default_executable = %q{zena}
14
14
  s.description = %q{zena is a Ruby on Rails CMS (content managment system) with a focus on usability, ease of customization and web 2.0 goodness (application like behaviour).}
15
15
  s.email = %q{gaspard@teti.ch}
@@ -250,10 +250,6 @@ Gem::Specification.new do |s|
250
250
  "bricks/captcha/patch/application_helper.rb",
251
251
  "bricks/captcha/patch/site.rb",
252
252
  "bricks/captcha/zafu/captcha.rb",
253
- "bricks/delayed_job/README",
254
- "bricks/delayed_job/migrate/20091104191643_create_delayed_jobs_table.rb",
255
- "bricks/delayed_job/misc/init.rb",
256
- "bricks/delayed_job/misc/tasks.rb",
257
253
  "bricks/math/patch/application_helper.rb",
258
254
  "bricks/sphinx/MIT-LICENSE",
259
255
  "bricks/sphinx/README",
@@ -270,6 +266,12 @@ Gem::Specification.new do |s|
270
266
  "bricks/tags/test/unit/tags_test.rb",
271
267
  "bricks/tags/test/zafu/tags.yml",
272
268
  "bricks/toto.zip",
269
+ "bricks/worker/README",
270
+ "bricks/worker/migrate/20091104191643_create_delayed_jobs_table.rb",
271
+ "bricks/worker/misc/deploy.rb",
272
+ "bricks/worker/misc/init.rb",
273
+ "bricks/worker/misc/tasks.rb",
274
+ "bricks/worker/misc/worker",
273
275
  "config/boot.rb",
274
276
  "config/bricks.yml",
275
277
  "config/database_example.yml",
@@ -367,6 +369,7 @@ Gem::Specification.new do |s|
367
369
  "db/migrate/20091101184952_add_session_table.rb",
368
370
  "db/migrate/20091123175137_add_single_access_token.rb",
369
371
  "db/migrate/20091124161608_rebuild_fullpath.rb",
372
+ "db/migrate/20100115134729_rebuild_fullpath_after_fix.rb",
370
373
  "db/schema.rb",
371
374
  "doc/README_FOR_APP",
372
375
  "doc/fixtures.graffle",
@@ -1605,9 +1608,6 @@ Gem::Specification.new do |s|
1605
1608
  "script/performance/benchmarker",
1606
1609
  "script/performance/profiler",
1607
1610
  "script/plugin",
1608
- "script/process/inspector",
1609
- "script/process/reaper",
1610
- "script/process/spawner",
1611
1611
  "script/runner",
1612
1612
  "script/server",
1613
1613
  "script/set_revision",
@@ -2017,17 +2017,17 @@ Gem::Specification.new do |s|
2017
2017
  s.add_runtime_dependency(%q<rails>, ["= 2.3.4"])
2018
2018
  s.add_runtime_dependency(%q<uuidtools>, ["= 2.0.0"])
2019
2019
  s.add_runtime_dependency(%q<authlogic>, [">= 0"])
2020
- s.add_runtime_dependency(%q<ts-delayed-delta>, [">= 1.0.0"])
2020
+ s.add_runtime_dependency(%q<ts-delayed-delta>, [">= 1.0.2"])
2021
2021
  s.add_runtime_dependency(%q<pvande-differ>, ["= 0.1.1"])
2022
2022
  s.add_runtime_dependency(%q<mislav-will_paginate>, ["~> 2.2.3"])
2023
2023
  s.add_runtime_dependency(%q<delayed_job>, [">= 1.8.4"])
2024
2024
  s.add_runtime_dependency(%q<syntax>, ["= 1.0.0"])
2025
- s.add_runtime_dependency(%q<thinking-sphinx>, [">= 1.3.1"])
2025
+ s.add_runtime_dependency(%q<thinking-sphinx>, [">= 1.3.14"])
2026
2026
  s.add_runtime_dependency(%q<yamltest>, ["= 0.5.3"])
2027
2027
  s.add_runtime_dependency(%q<json>, [">= 1.1.9"])
2028
2028
  s.add_runtime_dependency(%q<gettext>, ["= 1.93.0"])
2029
2029
  s.add_runtime_dependency(%q<rmagick>, [">= 2.11.1"])
2030
- s.add_development_dependency(%q<jeweler>, [">= 1.4.0"])
2030
+ s.add_runtime_dependency(%q<jeweler>, [">= 1.4.0"])
2031
2031
  s.add_runtime_dependency(%q<grosser-fast_gettext>, ["~> 0.4.16"])
2032
2032
  s.add_runtime_dependency(%q<thoughtbot-shoulda>, ["= 2.10.2"])
2033
2033
  s.add_runtime_dependency(%q<hpricot>, [">= 0"])
@@ -2040,12 +2040,12 @@ Gem::Specification.new do |s|
2040
2040
  s.add_dependency(%q<rails>, ["= 2.3.4"])
2041
2041
  s.add_dependency(%q<uuidtools>, ["= 2.0.0"])
2042
2042
  s.add_dependency(%q<authlogic>, [">= 0"])
2043
- s.add_dependency(%q<ts-delayed-delta>, [">= 1.0.0"])
2043
+ s.add_dependency(%q<ts-delayed-delta>, [">= 1.0.2"])
2044
2044
  s.add_dependency(%q<pvande-differ>, ["= 0.1.1"])
2045
2045
  s.add_dependency(%q<mislav-will_paginate>, ["~> 2.2.3"])
2046
2046
  s.add_dependency(%q<delayed_job>, [">= 1.8.4"])
2047
2047
  s.add_dependency(%q<syntax>, ["= 1.0.0"])
2048
- s.add_dependency(%q<thinking-sphinx>, [">= 1.3.1"])
2048
+ s.add_dependency(%q<thinking-sphinx>, [">= 1.3.14"])
2049
2049
  s.add_dependency(%q<yamltest>, ["= 0.5.3"])
2050
2050
  s.add_dependency(%q<json>, [">= 1.1.9"])
2051
2051
  s.add_dependency(%q<gettext>, ["= 1.93.0"])
@@ -2064,12 +2064,12 @@ Gem::Specification.new do |s|
2064
2064
  s.add_dependency(%q<rails>, ["= 2.3.4"])
2065
2065
  s.add_dependency(%q<uuidtools>, ["= 2.0.0"])
2066
2066
  s.add_dependency(%q<authlogic>, [">= 0"])
2067
- s.add_dependency(%q<ts-delayed-delta>, [">= 1.0.0"])
2067
+ s.add_dependency(%q<ts-delayed-delta>, [">= 1.0.2"])
2068
2068
  s.add_dependency(%q<pvande-differ>, ["= 0.1.1"])
2069
2069
  s.add_dependency(%q<mislav-will_paginate>, ["~> 2.2.3"])
2070
2070
  s.add_dependency(%q<delayed_job>, [">= 1.8.4"])
2071
2071
  s.add_dependency(%q<syntax>, ["= 1.0.0"])
2072
- s.add_dependency(%q<thinking-sphinx>, [">= 1.3.1"])
2072
+ s.add_dependency(%q<thinking-sphinx>, [">= 1.3.14"])
2073
2073
  s.add_dependency(%q<yamltest>, ["= 0.5.3"])
2074
2074
  s.add_dependency(%q<json>, [">= 1.1.9"])
2075
2075
  s.add_dependency(%q<gettext>, ["= 1.93.0"])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zena
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.16.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gaspard Bucher
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-15 00:00:00 +01:00
12
+ date: 2010-01-16 00:00:00 +01:00
13
13
  default_executable: zena
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -80,7 +80,7 @@ dependencies:
80
80
  requirements:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
- version: 1.0.0
83
+ version: 1.0.2
84
84
  version:
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: pvande-differ
@@ -130,7 +130,7 @@ dependencies:
130
130
  requirements:
131
131
  - - ">="
132
132
  - !ruby/object:Gem::Version
133
- version: 1.3.1
133
+ version: 1.3.14
134
134
  version:
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: yamltest
@@ -174,7 +174,7 @@ dependencies:
174
174
  version:
175
175
  - !ruby/object:Gem::Dependency
176
176
  name: jeweler
177
- type: :development
177
+ type: :runtime
178
178
  version_requirement:
179
179
  version_requirements: !ruby/object:Gem::Requirement
180
180
  requirements:
@@ -473,10 +473,6 @@ files:
473
473
  - bricks/captcha/patch/application_helper.rb
474
474
  - bricks/captcha/patch/site.rb
475
475
  - bricks/captcha/zafu/captcha.rb
476
- - bricks/delayed_job/README
477
- - bricks/delayed_job/migrate/20091104191643_create_delayed_jobs_table.rb
478
- - bricks/delayed_job/misc/init.rb
479
- - bricks/delayed_job/misc/tasks.rb
480
476
  - bricks/math/patch/application_helper.rb
481
477
  - bricks/sphinx/MIT-LICENSE
482
478
  - bricks/sphinx/README
@@ -493,6 +489,12 @@ files:
493
489
  - bricks/tags/test/unit/tags_test.rb
494
490
  - bricks/tags/test/zafu/tags.yml
495
491
  - bricks/toto.zip
492
+ - bricks/worker/README
493
+ - bricks/worker/migrate/20091104191643_create_delayed_jobs_table.rb
494
+ - bricks/worker/misc/deploy.rb
495
+ - bricks/worker/misc/init.rb
496
+ - bricks/worker/misc/tasks.rb
497
+ - bricks/worker/misc/worker
496
498
  - config/boot.rb
497
499
  - config/bricks.yml
498
500
  - config/database_example.yml
@@ -590,6 +592,7 @@ files:
590
592
  - db/migrate/20091101184952_add_session_table.rb
591
593
  - db/migrate/20091123175137_add_single_access_token.rb
592
594
  - db/migrate/20091124161608_rebuild_fullpath.rb
595
+ - db/migrate/20100115134729_rebuild_fullpath_after_fix.rb
593
596
  - db/schema.rb
594
597
  - doc/README_FOR_APP
595
598
  - doc/fixtures.graffle
@@ -1828,9 +1831,6 @@ files:
1828
1831
  - script/performance/benchmarker
1829
1832
  - script/performance/profiler
1830
1833
  - script/plugin
1831
- - script/process/inspector
1832
- - script/process/reaper
1833
- - script/process/spawner
1834
1834
  - script/runner
1835
1835
  - script/server
1836
1836
  - script/set_revision
@@ -1,2 +0,0 @@
1
- require 'delayed_job'
2
- require 'delayed/tasks'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../../config/boot'
3
- require 'commands/process/inspector'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../../config/boot'
3
- require 'commands/process/reaper'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../../config/boot'
3
- require 'commands/process/spawner'