Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to support thinking_sphinx v3 #109

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions cookbooks/sphinx/files/default/ts_searchd
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/sh
# This script starts and stops the searchd
# This script belongs in /engineyard/bin/searchd
###############################################################################
export PATH=/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.1.2
###############################################################################
usage() {
echo "Usage: $0 <appname> {start, stop, configure, reindex} [environment]"
exit 1
}
if [ $# -lt 2 ]; then usage; fi
if [ -z "$3" ]; then
FRAMEWORK_ENV=production
else
FRAMEWORK_ENV="$3"
fi
###############################################################################
LOGBASE=/var/log/engineyard/sphinx/$1
PIDFILE=/var/run/sphinx/$1.pid
CONFIGFILE=/data/$1/shared/config/sphinx.yml
GEMFILE=/data/$1/current/Gemfile
OUTPUT=$LOGBASE/searchd.log
USER=`stat -c"%U" /data/$1/current`
COMMAND=""
###############################################################################
export RAILS_ENV="$FRAMEWORK_ENV"
export RACK_ENV="$FRAMEWORK_ENV"
export HOME="/home/$USER"
if [ -f $GEMFILE ]; then
COMMAND="bundle exec"
fi
if [ -d /data/$1/current ]; then
cd /data/$1/current
if [ ! -f $CONFIGFILE ]; then
echo "$CONFIGFILE doesn't exist! Exiting" >> $OUTPUT 2>&1
fi
# handle the second param, don't start if already existing
case "$2" in
start)
echo "Starting searchd"
$COMMAND rake ts:start >> $OUTPUT 2>&1
;;
stop)
echo "Stopping searchd"
$COMMAND rake ts:stop >> $OUTPUT 2>&1
;;
configure)
echo "Configuring your searchd indexes"
$COMMAND rake ts:configure >> $OUTPUT 2>&1
;;
reindex)
echo "Reindexing your searchd indexes against the live server"
$COMMAND rake ts:index >> $OUTPUT 2>&1
;;
*)
usage
;;
esac
else
echo "/data/$1/current doesn't exist."
usage
fi
47 changes: 36 additions & 11 deletions cookbooks/sphinx/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
appname = "myapp"

# Uncomment the flavor of sphinx you want to use
# Set this to "ts" if you are using thinking-sphinx v3
flavor = "thinking_sphinx"
#flavor = "ultrasphinx"

template_file_name = flavor == 'ts' ? flavor : 'sphinx'

# If you want to install on a specific utility instance rather than
# all application instances, uncomment and set the utility instance
# name here. Note that if you use a utility instance, your very first
Expand All @@ -29,6 +32,28 @@

cron_interval = nil #If this is not set your data will NOT be indexed

if flavor == 'ts'
# thinking-sphinx v3 recommends v 2.0.5+ so we need to install it
sphinx_version = '2.0.6'

enable_package "app-misc/sphinx" do
version sphinx_version
end

package "app-misc/sphinx" do
version sphinx_version
action :install
end

remote_file "/engineyard/bin/ts_searchd" do
owner "root"
group "root"
mode 0755
source "ts_searchd"
action :create
end

end

if ! File.exists?("/data/#{appname}/current")
Chef::Log.info "Sphinx was not configured because the app must be deployed first. Please deploy it then re-run custom recipes."
Expand All @@ -38,7 +63,7 @@
if ['solo', 'app', 'app_master'].include?(node[:instance_role])
run_for_app(appname) do |app_name, data|
ey_cloud_report "Sphinx" do
message "configuring #{flavor}"
message "configuring #{flavor == 'ts' ? 'thinking_sphinx' : flavor}"
end

directory "/data/#{app_name}/shared/config/sphinx" do
Expand All @@ -52,7 +77,7 @@
owner node[:owner_name]
group node[:owner_name]
mode 0644
source "sphinx.yml.erb"
source "#{template_file_name}.yml.erb"
variables({
:app_name => app_name,
:address => sphinx_host,
Expand All @@ -66,7 +91,7 @@
if node[:name] == utility_name
run_for_app(appname) do |app_name, data|
ey_cloud_report "Sphinx" do
message "configuring #{flavor}"
message "configuring #{flavor == 'ts' ? 'thinking_sphinx' : flavor}"
end

directory "/var/run/sphinx" do
Expand Down Expand Up @@ -114,7 +139,7 @@
owner node[:owner_name]
group node[:owner_name]
mode 0644
source "sphinx.yml.erb"
source "#{template_file_name}.yml.erb"
variables({
:app_name => app_name,
:address => sphinx_host,
Expand All @@ -139,11 +164,11 @@
cwd "/data/#{app_name}/current"
end

ey_cloud_report "indexing #{flavor}" do
message "indexing #{flavor}"
ey_cloud_report "indexing #{flavor == 'ts' ? 'thinking_sphinx' : flavor}" do
message "indexing #{flavor == 'ts' ? 'thinking_sphinx' : flavor}"
end

execute "#{flavor} index" do
execute "#{flavor == 'ts' ? 'thinking_sphinx' : flavor} index" do
command "bundle exec rake #{flavor}:index"
user node[:owner_name]
environment({
Expand Down Expand Up @@ -173,7 +198,7 @@
if ['solo', 'app', 'app_master'].include?(node[:instance_role])
run_for_app(appname) do |app_name, data|
ey_cloud_report "Sphinx" do
message "configuring #{flavor}"
message "configuring #{flavor == 'ts' ? 'thinking_sphinx' : flavor}"
end

directory "/var/run/sphinx" do
Expand Down Expand Up @@ -222,7 +247,7 @@
owner node[:owner_name]
group node[:owner_name]
mode 0644
source "sphinx.yml.erb"
source "#{template_file_name}.yml.erb"
variables({
:app_name => app_name,
:address => 'localhost',
Expand All @@ -248,8 +273,8 @@
cwd "/data/#{app_name}/current"
end

ey_cloud_report "indexing #{flavor}" do
message "indexing #{flavor}"
ey_cloud_report "indexing #{flavor == 'ts' ? 'thinking_sphinx' : flavor}" do
message "indexing #{flavor == 'ts' ? 'thinking_sphinx' : flavor}"
end

execute "#{flavor} index" do
Expand Down
10 changes: 10 additions & 0 deletions cookbooks/sphinx/templates/default/ts.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<%= @node[:environment][:framework_env] %>:
log: /var/log/engineyard/sphinx/<%= @app_name %>/searchd.log
query_log: /var/log/engineyard/sphinx/<%= @app_name %>/query.log
pid_file: /var/run/sphinx/<%= @app_name %>.pid
address: <%= @address %>
mysql41: 9312
mem_limit: <%= @mem_limit %>
configuration_file: /data/<%= @app_name %>/shared/config/sphinx/<%= @node[:environment][:framework_env] %>.sphinx.conf
indices_location: /var/log/engineyard/sphinx/<%= @app_name %>/indexes