Capistrano 2.1 and Ultrasphinx

Posted on December 07, 2007

This Article is very much outdated.

Please Use this plugin: git://github.com/ruberion/ruberion_server_tools.git
or go to github and search for capistrano. ;)


Here is my capistrano configuration to use with ultrasphinx. Sphinx on gentoo. The default.base is very important. When you run rake ultrasphinx:configure, the new configuration file will be base on this default config file. Here is my capistrano configuration to use with ultrasphinx. Sphinx on gentoo. The default.base is very important. When you run rake ultrasphinx:configure, the new configuration file will be base on this default config file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81


before "deploy:setup", :config

# START
namespace :config do
  desc "Prepare config files and dirs in shared path." 
  task :default do
    # ... other tasks
    config.prepare_ultrasphinx
    # .. another task
  end
end

# Setup ultrashpinhx config files
namespace :config do
  desc "Create ultrasphinx base configuration in shared/config path" 
  task :prepare_ultrasphinx do
    sphinx_path = "#{sphinx_db}/#{application}/#{rails_env}"
    sphinx_port = sphinx_production_port
    ultrasphinx_base_config = ERB.new <<-EOF
indexer
{
  mem_limit = 256M 
}
searchd
{
  # Daemon options
  # What interface the search daemon should listen on and where to store its logs
  address = 0.0.0.0
  port = #{sphinx_port}
  log = #{sphinx_path}/log/searchd.log
  query_log = #{sphinx_path}/log/query.log
  read_timeout = 5
  max_children = 300
  pid_file = #{sphinx_path}/log/searchd.pid
  max_matches = 100000
}
client
{
  # Client options
  # Name of the Aspell dictionary (two letters max)
  dictionary_name = ap
  # How your application connects to the search daemon (not necessarily the same as above)
  server_host = localhost
  server_port = #{sphinx_port}
}

source
{
  # Individual SQL source options
  sql_range_step = 5000   
  strip_html = 0
  index_html_attrs =
  sql_query_post =
}
index
{
  # Index building options
  path = #{sphinx_path}
  docinfo = extern # just leave this alone
  morphology = stem_en
  stopwords = # /path/to/stopwords.txt
  min_word_len = 2
  min_infix_len = 1
  enable_star = 1
  charset_type = utf-8 # or sbcs (Single Byte Character Set)
  charset_table = 0..9, A..Z->a..z, -, _, ., &, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F,U+C5->U+E5, U+E5, U+C4->U+E4, U+E4, U+D6->U+F6, U+F6, U+16B, U+0c1->a, U+0c4->a, U+0c9->e, U+0cd->i, U+0d3->o, U+0d4->o, U+0da->u, U+0dd->y, U+0e1->a, U+0e4->a, U+0e9->e, U+0ed->i, U+0f3->o, U+0f4->o, U+0fa->u, U+0fd->y, U+104->U+105, U+105, U+106->U+107, U+10c->c, U+10d->c, U+10e->d, U+10f->d, U+116->U+117, U+117, U+118->U+119, U+11a->e, U+11b->e, U+12E->U+12F, U+12F, U+139->l, U+13a->l, U+13d->l, U+13e->l, U+141->U+142, U+142, U+143->U+144, U+144,U+147->n, U+148->n, U+154->r, U+155->r, U+158->r, U+159->r, U+15A->U+15B, U+15B, U+160->s, U+160->U+161, U+161->s, U+164->t, U+165->t, U+16A->U+16B, U+16B, U+16e->u, U+16f->u, U+172->U+173, U+173, U+179->U+17A, U+17A, U+17B->U+17C, U+17C, U+17d->z, U+17e->z,
}
EOF
    # make sure we have shared/config/ultrasphinx"
    run "mkdir -p #{shared_path}/config/ultrasphinx"
    # make the link, perhaps it should in "deploy:after_symlink" name space
    run "ln -nfs #{shared_path}/config/ultrasphinx #{current_path}/config/ultrasphinx"
    put ultrasphinx_base_config.result, "#{shared_path}/config/ultrasphinx/default.base"
    run "mkdir -p #{sphinx_path}"
    run "mkdir -p #{sphinx_path}/log"
  end

end

Some tasks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25


# ==========================
# Sphinx Server Tasks
# ==========================
desc "Update Index"
task :sphinx_update_index, :roles => :app do
  invoke_command "cd #{current_path} && rake ultrasphinx:index RAILS_ENV=#{rails_env}"
end

desc "Stop Sphinx"
task :sphinx_daemon_stop, :roles => :app do
  invoke_command "cd #{current_path} && rake ultrasphinx:daemon:stop RAILS_ENV=#{rails_env}"
end

desc "Start Sphinx"
task :sphinx_daemon_start, :roles => :app do
  invoke_command "cd #{current_path} && rake ultrasphinx:daemon:start RAILS_ENV=#{rails_env}"
end

desc "Restart Sphinx"
task :sphinx_daemon_restart, :roles => :app do
  invoke_command "#{current_path} && rake ultrasphinx:daemon:restart RAILS_ENV=#{rails_env}"
end