I have installed a ubuntu 12.04 remote server with elasticsearch.
I have installed elasticsearch with:
sudo apt-get update
sudo apt-get install openjdk-7-jre-headless -y
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.20.6.deb
sudo dpkg -i elasticsearch-0.20.6.deb
sudo service elasticsearch start
I get with sudo elasticsearch status:
* ElasticSearch Server is running with pid 2483
My elasticsearch remote server is working fine:
ubuntu12#juan:~/Escritorio/myapp$ curl http:/111.111.111.111:9200
{
"ok" : true,
"status" : 200,
"name" : "Hogan, Harold \"Happy\"",
"version" : {
"number" : "0.20.6",
"snapshot_build" : false
},
"tagline" : "You Know, for Search"
}
or with my subdomain:
ubuntu12#juan:~/Escritorio/myapp$ curl http://elasticsearchserver.mydomain.com:9200
{
"ok" : true,
"status" : 200,
"name" : "Hogan, Harold \"Happy\"",
"version" : {
"number" : "0.20.6",
"snapshot_build" : false
},
"tagline" : "You Know, for Search"
}
I can restart, start and stop elasticsearhc server.
sudo service elasticsearch restart
* Stopping ElasticSearch Server [ OK ]
* Starting ElasticSearch Server [ OK ]
I have a tire.rb file in config/initializer/ folder with the next code:
if Rails.env == 'production'
Tire.configure do
url "http://elasticsearchserver.mydomain.com:9200"
end
end
This is my capistrano task to reindex:
after "deploy:finalize_update", "deploy:elasticsearch:index_classes"
namespace :deploy do
namespace :elasticsearch do
desc 'run elasticsearch indexing via tire'
task :index_classes do
run "cd #{deploy_to}/current && bundle exec rake environment tire:import CLASS=Object FORCE=true "
end
end
end
I'm using mongodb as database, so I have not make migrations before reindexing.
This is capistrano error:
2013-04-06 14:25:50 executing `deploy:elasticsearch:index_classes'
#
#
** [out :: 111.111.111.111] Skipping index creation, cannot connect to Elasticsearch
** [out :: 111.111.111.111]
** [out :: 111.111.111.111] (The original exception was: #<Errno::ECONNREFUSED: Connection refused - connect(2)>)
** [out :: 111.111.111.111]
** [out :: 111.111.111.111] [IMPORT] Deleting index 'cvs'
** [out :: 111.111.111.111]
** [out :: 111.111.111.111] rake aborted!
** [out :: 111.111.111.111] Connection refused - connect(2)
** [out :: 111.111.111.111]
#
#
I have uploaded to production server the tire.rb file and I have tried:
bundle exec rake environment tire:import CLASS=Object FORCE=true
and I get the same result:
Skipping index creation, cannot connect to Elasticsearch
(The original exception was: #<Errno::ECONNREFUSED: Connection refused - connect(2)>)
[IMPORT] Deleting index objects'
rake aborted!
Connection refused - connect(2)
What am I doing wrong? How can I fix connection between tire/rails app and my elasticsearch server?
I think you just had the syntax wrong in your config/initializers/tire.rb,
see below
Tire.configure do
url "http://localhost:9200"
#you can uncomment the next line if you want to see the elasticsearch queries in their own seperate log
#logger "#{Rails.root}/log/es.log"
end
This is the syntax that it's working fine for me inside of tire.rb file
require 'tire'
Tire.configure { url "http://myremoteserver.com:9200" }
and now it's working fine!
Thank you!
Related
After update to rubber 3.1.0 and using postgres 9.3 on a 3.2.22 rails app i'm trying to deploy on Ec2 is showing this on the log:
** [out :: app01.foo.com] PG::ConnectionBad: FATAL: no pg_hba.conf entry for host "172.35.45.216", user "foo", database "foo_production", SSL on
** [out :: app01.foo.com]
** [out :: app01.foo.com] FATAL: no pg_hba.conf entry for host "172.35.45.216", user "foo", database "foo_production", SSL off
someone got the same problem?
I'm deploying a Rails app that uses PostgreSQL and HSTORE.
To deploy it, I'm ussing rubber.
Everything works, except for HSTORE not being properly enabled. When the migration that contains execute("CREATE EXTENSION hstore") runs, I get the following errors:
** [out :: production.---]
** [out :: production.---] -- execute("CREATE EXTENSION hstore")
** [out :: production.---]
** [out :: production.---] rake aborted!
** [out :: production.---] An error has occurred, this and all later migrations canceled:
** [out :: production.---]
** [out :: production.---] PG::Error: ERROR: permission denied to create extension "hstore"
** [out :: production.---] HINT: Must be superuser to create this extension.
The script that creates the postgres instance has this code:
create_user_cmd = "CREATE USER #{env.db_user} WITH NOSUPERUSER CREATEDB NOCREATEROLE"
so I think the problem might be related to the NOSUPERUSER attribute being set here.
Is there any way to enable hstore using rubber while keeping most of the generated files unchanged?
The problem is that rubber creates the DB user as NOSUPERUSER. My workaround is to create tasks that run before and after capistrano's deploy:migrate that will change the user to SUPERUSER and back.
Here's the code:
namespace :rubber do
namespace :project do
before "deploy:migrate", "rubber:project:add_pg_superuser_and_enable_hstore"
after "deploy:migrate", "rubber:project:remove_pg_superuser"
task :add_pg_superuser_and_enable_hstore,
:roles => [:postgresql_master, :postgresql_slave] do
alter_user_cmd = "ALTER USER #{rubber_env.db_user} SUPERUSER"
create_hstore_cmd = "CREATE EXTENSION IF NOT EXISTS hstore;"
rubber.sudo_script "add_superuser_create_hstore", <<-ENDSCRIPT
sudo -i -u postgres psql -c "#{alter_user_cmd}"
sudo -i -u postgres psql -c "#{create_hstore_cmd}"
ENDSCRIPT
end
task :remove_pg_superuser, :roles => [:postgresql_master,
:postgresql_slave] do
alter_user_cmd = "ALTER USER #{rubber_env.db_user} NOSUPERUSER"
rubber.sudo_script "add_superuser_create_hstore", <<-ENDSCRIPT
sudo -i -u postgres psql -c "#{alter_user_cmd}"
ENDSCRIPT
end
end
end
Another option is to not have a postgres superuser involved when deploying but create a template (or use the default one) and install the extension on the template. Then when you create a database it will have the extension installed.
Good answers here and here.
I just ran rake db:migrate directly on my server with no problems:
$ pwd
/var/www/vhosts/example.com/current
$ rake db:migrate
Then i tried to run it via a capistrano task and i get an error. The task and output are below. Why does rake db:migrate not work via my capistrano task?
task
namespace :deploy do
# run the db migrations
task :run_migrations, :roles => :db do
puts "RUNNING DB MIGRATIONS"
run "cd #{current_path}; rake db:migrate RAILS_ENV=#{rails_env}"
end
end
cap deploy:run_migrations
$ cap deploy:run_migrations
* executing `deploy:run_migrations'
RUNNING DB MIGRATIONS
* executing "cd /var/www/vhosts/example.com/current; rake db:migrate"
servers: ["example.com"]
[example.com] executing command
** [out :: example.com] (in /var/www/vhosts/example.com/releases/20121122011144)
** [out :: example.com] rake aborted!
** [out :: example.com] no such file to load -- rubygems
** [out :: example.com] /var/www/vhosts/example.com/releases/20121122011144/Rakefile:5:in `require'
** [out :: example.com] (See full trace by running task with --trace)
command finished in 390ms
failed: "sh -c 'cd /var/www/vhosts/example.com/current; rake db:migrate'" on example.com
EDIT
$ ruby -v
ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-linux]
$ which ruby
/usr/local/rvm/rubies/ruby-1.9.3-p125/bin/ruby
$ which rails
/usr/local/rvm/gems/ruby-1.9.3-p125/bin/rails
EDIT
When i added --trace to the db migrations, it looks like it's using /usr/lib/ruby/site_ruby/1.8/rake.rb, but from the looks of this:
$ which rake
/usr/local/rvm/gems/ruby-1.9.3-p125/bin/rake
i would have expected it to use rake at /usr/local/rvm/gems/ruby-1.9.3-p125/bin/rake rather than /usr/lib/ruby/site_ruby/1.8/rake.rb.
cap deploy's output from the deploy:run_migrations task
* executing `deploy:run_migrations'
RUNNING DB MIGRATIONS
* executing "cd /var/www/vhosts/example.com/current; rake db:migrate RAILS_ENV=production --trace"
servers: ["example.com"]
[example.com] executing command
** [out :: example.com] (in /var/www/vhosts/example.com/releases/20121123184358)
** [out :: example.com] rake aborted!
** [out :: example.com] no such file to load -- rubygems
** [out :: example.com] /var/www/vhosts/example.com/releases/20121123184358/config/boot.rb:1:in `require'
** [out :: example.com] /var/www/vhosts/example.com/releases/20121123184358/config/boot.rb:1
** [out :: example.com] /var/www/vhosts/example.com/releases/20121123184358/config/application.rb:1:in `require'
** [out :: example.com] /var/www/vhosts/example.com/releases/20121123184358/config/application.rb:1
** [out :: example.com] /var/www/vhosts/example.com/releases/20121123184358/Rakefile:5:in `require'
** [out :: example.com] /var/www/vhosts/famnfo.com/releases/20121123184358/Rakefile:5
** [out :: example.com] /usr/lib/ruby/site_ruby/1.8/rake.rb:1828:in `load'
** [out :: example.com] /usr/lib/ruby/site_ruby/1.8/rake.rb:1828:in `load_rakefile'
** [out :: example.com] /usr/lib/ruby/site_ruby/1.8/rake.rb:1900:in `run'
** [out :: example.com] /usr/bin/rake:8
command finished in 422ms
failed: "sh -c 'cd /var/www/vhosts/example.com/current; rake db:migrate RAILS_ENV=production --trace'" on example.com
EDIT
output after adding #Super Engineers code
* executing `bundle:install'
* executing "ls -x /var/www/vhosts/example.com/releases"
servers: ["example.com"]
[example.com] executing command
command finished in 572ms
* executing "cd /var/www/vhosts/example.com/releases/20121124160218 && bundle install --gemfile /var/www/vhosts/example.com/releases/20121124160218/Gemfile --path /var/www/vhosts/example.com/shared/bundle --deployment --quiet --without development test"
servers: ["example.com"]
[example.com] executing command
** [out :: example.com] You are trying to install in deployment mode after changing
** [out :: example.com] your Gemfile. Run `bundle install` elsewhere and add the
** [out :: example.com] updated Gemfile.lock to version control.
** [out :: example.com]
** [out :: example.com] You have added to the Gemfile:
** [out :: example.com] * mysql2
** [out :: example.com] * therubyracer
** [out :: example.com] * rvm-capistrano
** [out :: example.com] * passenger
** [out :: example.com]
** [out :: example.com] You have deleted from the Gemfile:
** [out :: example.com] * mysql
command finished in 999ms
*** [deploy:update_code] rolling back
* executing "rm -rf /var/www/vhosts/example.com/releases/20121124160218; true"
servers: ["example.com"]
[example.com] executing command
command finished in 826ms
failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell 'ruby-1.9.3-p125' -c 'cd /var/www/vhosts/example.com/releases/20121124160218 && bundle install --gemfile /var/www/vhosts/example.com/releases/20121124160218/Gemfile --path /var/www/vhosts/example.com/shared/bundle --deployment --quiet --without development test'" on example.com
EDIT
Entire deploy.rb file
require 'bundler/capistrano'
require 'rvm/capistrano'
# set environment
set :rails_env, "production"
# set the ruby version
set :rvm_ruby_string, 'ruby-1.9.3-p125'
set :rvm_type, 'webadmin'
# server username and password
set :user, 'super'
set :password, 'secret'
# subversion repo username and password
set :scm, :subversion
set :scm_username, "super"
set :scm_password, 'secret'
set :svnserver, "myreposerver"
set :repository, "myrepo"
# project info
set :server, ''
set :application, "FamNFo"
set :applicationdir, '/Volumes/Macintosh HD/Users/myname/Sites/example'
role :web, "example.com"
role :app, "example.com"
role :db, "example.com", :primary => true
set :use_sudo, true
# database config
#set :migrate_env, "#{rails_env}"
# specify the rvm type. We just want to use the system wide one since we're not currently specifying gemsets for each project
set :rvm_type, :system
# where to put the files
set :deploy_to, "/var/www/vhosts/example.com"
# fixes the "sorry, you must have a tty to run sudo" issue
default_run_options[:pty] = true
# precompiles the assets
load 'deploy/assets'
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
# restart the server
task :restart, :roles => :app do
run "/etc/init.d/http restart graceful"
end
# chmod the files
task :after_update_code, :roles => [:web, :db, :app] do
run "chmod 755 #{release_path}/public -R"
end
# install new gems
desc "run bundle install and ensure all gem requirements are met"
task :install do
run "cd #{current_path} && bundle install --without=test --no-update-sources --trace"
end
# run the db migrations
task :run_migrations, :roles => :db do
puts "RUNNING DB MIGRATIONS"
run "cd #{current_path}; rake db:migrate RAILS_ENV=#{rails_env} --trace"
end
# precompile assets
task :precompile_assets do
run "cd #{release_path}; bundle exec rake assets:precompile RAILS_ENV=#{rails_env}"
end
task :start do ; end
task :stop do ; end
# restart the server
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{sudo} /etc/init.d/httpd restart graceful"
end
end
# hook to run db migrations after code update
after("deploy:update", "deploy:run_migrations")
#after("deploy:update", "deploy:precompile_assets")
after "deploy:update", "deploy:install"
# if you want to clean up old releases on each deploy uncomment this:
after "deploy:restart", "deploy:cleanup" # leave the last 5 releases only
Its because of ruby conflict. I've faced same error. You will need to use rvm/capistrano gem. I'll paste some code from my cap file which will give you some idea about how to set the ruby version while deploying.
install the gem
gem install rvm-capistrano
in you deploy.rb file add these lines
require 'bundler/capistrano'
require 'rvm/capistrano'
set :rvm_ruby_string, "ruby-1.9.3-p125"
set :rvm_type, 'webadmin'
For more information you can visit this link rvm/capistrano
The relevant error here seems to be no such file to load -- rubygems.
Quite likely it is because of multiple ruby installations on the production server.
Check out this previous solution for a similar problem : https://stackoverflow.com/a/2896596/429758
Also, this thread on the capistrano mailing list is helpful: https://groups.google.com/forum/?fromgroups=#!topic/capistrano/JzVPRbQclY4
Are you using rvm/capistrano? With that you can specify the ruby version that you want to use on the server in your capistrano recipes. I suspect that when you run capistrano it's not using your rvm setup, when you login and run the rake task, your user is setup to use the rvm ruby version.
I'm new to Capistrano and having trouble debugging an error. Searching suggests this error could be an environment issue of picking up the wrong version of ruby (it's almost certainly not the referenced file as it works fine in test). Using a Capistrano task to dump the ruby version everything looks fine. Running the commands directly on the server works fine, too. I'm using rbenv on the server.
The error:
* executing `deploy:assets:precompile'
* executing "cd /home/deployer/apps/happenate/releases/20120424002545 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
servers: ["happenate.com"]
[happenate.com] executing command
** [out :: happenate.com] rake aborted!
** [out :: happenate.com] /home/deployer/apps/happenate/releases/20120424002545/config/initializers/session_store.rb:3: syntax error, unexpected ':', expecting $end
** [out :: happenate.com] ...sion_store :cookie_store, key: '_happenate_session'
** [out :: happenate.com] ^
Definitely some sort of ruby environment issue. After cleaning everything up with a proper rbenv environment, the error is gone.
been playing around with Capistrano to get an automated deploy between my server and my development machine. I've almost got it configured except that Capistrano doesn't seem to be able to start up my servers using the bundle exec command. I'm always receiving the following error:
EDIT: The config file now resides at /var/www/apps/current/thin.yml
...
* executing "sudo -p 'sudo password: ' bundle exec thin start -C /var/www/thin.config.yml"
servers: ["85.255.206.157"]
[85.255.206.157] executing command
** [out :: 85.255.206.157] Could not locate Gemfile
command finished in 216ms
failed: "sh -c 'sudo -p '\\''sudo password: '\\'' bundle exec thin start -C /var/www/thin.config.yml'" on 85.255.206.157
Only copied the last section that's relevant. The whole copying of the files etc works fine. It's just starting the cluster that seems to be failing.
Here is my deploy.rb file that handles all Capistrano stuff:
EDIT: The file has been modified to the following:
require "bundler/capistrano"
# define the application and Version Control settings
set :application, "ESCO Matching Demo"
set :repository, "svn://192.168.33.70/RubyOnRails/ESCO"
set :deploy_via, :copy
# Set the login credentials for Capistrano
set :user, "kurt"
# Tell Capistrano where to deploy
set :deploy_to, "/var/www/apps"
# Tell Capistrano the servers it can play with
server "85.255.206.157", :app, :web, :db, :primary => true
# Generate an additional task to fire up the thin clusters
namespace :deploy do
desc "Start the Thin processes"
task :start do
sudo "bundle exec thin start -C thin.yml"
end
desc "Stop the Thin processes"
task :stop do
sudo "bundle exec thin stop -C thin.yml"
end
desc "Restart the Thin processes"
task :restart do
sudo "bundle exec thin restart -C thin.yml"
end
desc "Create a symlink from the public/cvs folder to the shared/system/cvs folder"
task :update_cv_assets, :except => {:no_release => true} do
run "ln -s #{shared_path}/cvs #{latest_release}/public/cvs"
end
end
# Define all the tasks that need to be running manually after Capistrano is finished.
after "deploy:finalize_update", "deploy:update_cv_assets"
after "deploy", "deploy:migrate"
EDIT: This is my thin.yml file
---
pid: tmp/pids/thin.pid
address: 0.0.0.0
timeout: 30
wait: 30
port: 4000
log: log/thin.log
max_conns: 1024
require: []
environment: production
max_persistent_conns: 512
server: 4
daemonize: true
chdir: /var/www/apps/current
EDIT:
The following problems are occurring now:
I'm receiving the Cannot find GemFile error when running the cap deploy command from my system on the final step : the booting of the servers
Migrations are not performed
I can't seem to fire up the cluster manually either anymore. Only one instance of thin is starting up.
UPDATE:
Here is the gem env settings from the server I'm deploying to. This information is obtained by using the cap shell and then running the commands:
====================================================================
Welcome to the interactive Capistrano shell! This is an experimental
feature, and is liable to change in future releases. Type 'help' for
a summary of how to use the shell.
--------------------------------------------------------------------
cap> echo $PATH
[establishing connection(s) to 85.255.206.157]
Password:
** [out :: 85.255.206.157] /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
cap> gem env
** [out :: 85.255.206.157] RubyGems Environment:
** [out :: 85.255.206.157] - RUBYGEMS VERSION: 1.3.6
** [out :: 85.255.206.157] - RUBY VERSION: 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]
** [out :: 85.255.206.157] - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
** [out :: 85.255.206.157] - RUBY EXECUTABLE: /usr/bin/ruby1.8
** [out :: 85.255.206.157] - EXECUTABLE DIRECTORY: /usr/bin
** [out :: 85.255.206.157] - RUBYGEMS PLATFORMS:
** [out :: 85.255.206.157] - ruby
** [out :: 85.255.206.157] - x86_64-linux
** [out :: 85.255.206.157] - GEM PATHS:
** [out :: 85.255.206.157] - /usr/lib/ruby/gems/1.8
** [out :: 85.255.206.157] - /home/kurt/.gem/ruby/1.8
** [out :: 85.255.206.157] - GEM CONFIGURATION:
** [out :: 85.255.206.157] - :update_sources => true
** [out :: 85.255.206.157] - :verbose => true
** [out :: 85.255.206.157] - :benchmark => false
** [out :: 85.255.206.157] - :backtrace => false
** [out :: 85.255.206.157] - :bulk_threshold => 1000
** [out :: 85.255.206.157] - REMOTE SOURCES:
** [out :: 85.255.206.157] - http://rubygems.org/
Finally solved the problem...
First in order to get the bundle application to play nicely with the environemnt server, the following script does what it's supposed to be doing:
require "bundler/capistrano"
default_run_options[:pty] = true
# define the application and Version Control settings
set :application, "ESCO Matching Demo"
set :repository, "svn://192.168.33.70/RubyOnRails/ESCO"
set :deploy_via, :copy
set :user, "kurt"
set :deploy_to, "/var/www/apps"
# Tell Capistrano the servers it can play with
server "85.255.206.157", :app, :web, :db, :primary => true
# Generate an additional task to fire up the thin clusters
namespace :deploy do
desc "Start the Thin processes"
task :start do
run <<-CMD
cd /var/www/apps/current; bundle exec thin start -C config/thin.yml
CMD
end
desc "Stop the Thin processes"
task :stop do
run <<-CMD
cd /var/www/apps/current; bundle exec thin stop -C config/thin.yml
CMD
end
desc "Restart the Thin processes"
task :restart do
run <<-CMD
cd /var/www/apps/current; bundle exec thin restart -C config/thin.yml
CMD
end
desc "Create a symlink from the public/cvs folder to the shared/system/cvs folder"
task :update_cv_assets, :except => {:no_release => true} do
run <<-CMD
ln -s /var/www/shared/cvs /var/www/apps/current/public
CMD
end
end
# Define all the tasks that need to be running manually after Capistrano is finished.
after "deploy:finalize_update", "deploy:update_cv_assets"
after "deploy", "deploy:migrate"
This script can navigate nicely into the required deployment structures and execute the commands needed to control the Thin process. The problem was that the cd command was not done when running these as sudo. The reason behind this is that cv exist only in the shell and is not a known command to sudo.
The second problem was the thin configuration. Because there was a small type on the thin.yml the thin servers could not be started up. The script below fires up a cluster of 4 thin server running on port 4000 -> 4003.
---
pid: tmp/pids/thin.pid
address: 0.0.0.0
timeout: 30
wait: 30
port: 4000
log: log/thin.log
max_conns: 1024
require: []
environment: production
max_persistent_conns: 512
servers: 4
daemonize: true
chdir: /var/www/apps/current
Man, find out where is GEM_HOME or GEM_PATH is pointing. Must be it.