From 2955b689fd08b2d63725b103f354ba3b8232de83 Mon Sep 17 00:00:00 2001 From: Brian Hall Date: Mon, 3 Jun 2013 22:57:43 -0400 Subject: [PATCH 1/3] update to support thinking_sphinx v3 --- cookbooks/sphinx/recipes/default.rb | 38 +++++++++++++------ cookbooks/sphinx/templates/default/ts.yml.erb | 10 +++++ 2 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 cookbooks/sphinx/templates/default/ts.yml.erb diff --git a/cookbooks/sphinx/recipes/default.rb b/cookbooks/sphinx/recipes/default.rb index d140b5cb..78be3a34 100644 --- a/cookbooks/sphinx/recipes/default.rb +++ b/cookbooks/sphinx/recipes/default.rb @@ -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 @@ -29,6 +32,19 @@ 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 +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." @@ -38,7 +54,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 @@ -52,7 +68,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, @@ -66,7 +82,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 @@ -114,7 +130,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, @@ -139,11 +155,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({ @@ -173,7 +189,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 @@ -222,7 +238,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', @@ -248,8 +264,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 diff --git a/cookbooks/sphinx/templates/default/ts.yml.erb b/cookbooks/sphinx/templates/default/ts.yml.erb new file mode 100644 index 00000000..3f62e80a --- /dev/null +++ b/cookbooks/sphinx/templates/default/ts.yml.erb @@ -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 + From f9fb310f8b78a601edbbf9681df5bf00f83843b0 Mon Sep 17 00:00:00 2001 From: Brian Hall Date: Thu, 13 Jun 2013 13:35:07 -0400 Subject: [PATCH 2/3] add ts_searchd file to repo and add remote_file command to copy it to /engineyard/bin when flavor set to 'ts' --- cookbooks/sphinx/files/default/ts_searchd | 62 +++++++++++++++++++++++ cookbooks/sphinx/recipes/default.rb | 9 ++++ 2 files changed, 71 insertions(+) create mode 100644 cookbooks/sphinx/files/default/ts_searchd diff --git a/cookbooks/sphinx/files/default/ts_searchd b/cookbooks/sphinx/files/default/ts_searchd new file mode 100644 index 00000000..78d7b294 --- /dev/null +++ b/cookbooks/sphinx/files/default/ts_searchd @@ -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 {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 \ No newline at end of file diff --git a/cookbooks/sphinx/recipes/default.rb b/cookbooks/sphinx/recipes/default.rb index 78be3a34..4e27b454 100644 --- a/cookbooks/sphinx/recipes/default.rb +++ b/cookbooks/sphinx/recipes/default.rb @@ -44,6 +44,15 @@ version sphinx_version action :install end + + remote_file "/engineyard/bin/ts_searchd" do + owner "root" + group "root" + mode 0744 + source "ts_searchd" + action :create + end + end if ! File.exists?("/data/#{appname}/current") From 090d4aa508a53e404fa0485c6590b900c4a15afc Mon Sep 17 00:00:00 2001 From: Brian Hall Date: Thu, 13 Jun 2013 14:07:47 -0400 Subject: [PATCH 3/3] set file mode to 755 instead of 744 --- cookbooks/sphinx/recipes/default.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookbooks/sphinx/recipes/default.rb b/cookbooks/sphinx/recipes/default.rb index 4e27b454..a5344187 100644 --- a/cookbooks/sphinx/recipes/default.rb +++ b/cookbooks/sphinx/recipes/default.rb @@ -48,7 +48,7 @@ remote_file "/engineyard/bin/ts_searchd" do owner "root" group "root" - mode 0744 + mode 0755 source "ts_searchd" action :create end