forked from rubber/rubber
/
deploy-sphinx.rb
112 lines (93 loc) · 3.38 KB
/
deploy-sphinx.rb
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# installs, starts and stops sphinx
#
# Please note that all tasks are executed as runner. So sphinx will run under
# the same userid as mongrel. This is important to allow delta indexes (mongrel
# has to send a sighup to searchd).
#
# * installation is ubuntu specific
# * start and stop tasks are using the thinking sphinx plugin
namespace :rubber do
namespace :sphinx do
rubber.allow_optional_tasks(self)
after "rubber:install_packages", "rubber:sphinx:custom_install"
task :custom_install, :roles => :sphinx do
# install sphinx from source
ver = "0.9.9"
rubber.sudo_script 'install_sphinx', <<-ENDSCRIPT
# check if already installed
if [ -x /usr/local/bin/searchd ]
then echo 'Found sphinx searchd on system'
if /usr/local/bin/searchd --help | grep 'Sphinx #{ver}'
then echo 'Sphinx version matches, no further steps needed'
exit 0
fi
fi
echo 'Installing / Upgrading sphinx #{ver}'
TMPDIR=`mktemp -d` || exit 1
cd $TMPDIR
echo 'Downloading'
wget -qN http://www.sphinxsearch.com/files/sphinx-#{ver}.tar.gz
echo 'Unpacking'
tar xf sphinx-#{ver}.tar.gz
cd sphinx-#{ver}
./configure
make
make install
cd ; rm -rf $TMPDIR
ENDSCRIPT
end
set :sphinx_root, Proc.new {"#{shared_path}/sphinx"}
after "deploy:setup", "rubber:sphinx:setup"
after "deploy:symlink", "rubber:sphinx:config_dir"
before "deploy:stop", "rubber:sphinx:stop"
after "deploy:start", "rubber:sphinx:start"
after "deploy:restart", "rubber:sphinx:restart"
before "deploy:cold" do
before "rubber:sphinx:start", "rubber:sphinx:index"
end
before "rubber:create_staging" do
before "rubber:sphinx:start", "rubber:sphinx:index"
end
desc "Do sphinx setup tasks"
task :setup, :roles => :sphinx do
# Setup links to sphinx config/index as they need to persist between deploys
rsudo "mkdir -p #{sphinx_root} #{sphinx_root}/config #{sphinx_root}/db"
rsudo "chown -R #{runner}:#{runner} #{sphinx_root}"
end
desc "Setup paths for sphinx runtime"
task :config_dir, :roles => :sphinx do
rsudo "rm -rf #{current_path}/sphinx"
rsudo "ln -sf #{sphinx_root} #{current_path}/sphinx"
end
# runs the given ultrasphinx rake tasks
def run_sphinx task
rsudo "cd #{current_path} && RAILS_ENV=#{RUBBER_ENV} #{fetch(:rake, 'rake')} #{task}", :as => runner
end
desc "Stops sphinx searchd"
task :stop, :roles => :sphinx do
run_sphinx 'ts:stop; exit 0'
end
desc "Starts sphinx searchd"
task :start, :roles => :sphinx do
# rake tasks that load rails env can be slow, so
# do multiple here as a performance tweak
# config always needs to be run before start as
# rubber generates a sphinx config file with new paths
run_sphinx 'ts:config ts:start'
end
desc "Restarts sphinx searchd"
task :restart, :roles => :sphinx do
# rake tasks that load rails env can be slow, so
# do multiple here as a performance tweak
run_sphinx 'ts:config ts:stop ts:start'
end
desc "Configures sphinx index"
task :config, :roles => :sphinx do
run_sphinx 'ts:config'
end
desc "Builds sphinx index"
task :index, :roles => :sphinx do
run_sphinx 'ts:index'
end
end
end