I am having two small apps having search in it. They are completly two different apps with different database etc.
Now the issue is coming up pid file.At a time only on application is searching cause when I do
rake ts:start
on one it says another instance is already running.
How can I change this so that sphinx keep running for both the applications. I am using Capistrano for development.
Structure is something like this:
/home/me/my_app_1/production/current
/home/me/my_app_2/production/current
In both apps you have to create a config/sphinx.yml which can contain various configuration variables and one of them allows you to specify the port of the sphinx server. When you define the port manually in one app like this:
development:
port: 9313
test:
port: 9314
production:
port: 9316
and in the other:
development:
port: 9317
test:
port: 9318
production:
port: 9319
Then call rake ts:rebuild in both applications. Thinking sphinx will generate new config files for sphinx that setup different sphinx instances for each app and each environment in the app.
Related
My rails project running on server nginx + passenger. I noticed that thinking sphinx cannot respond to asynchronous connections. I run in two tabs on browser search query, and one of the responses returned this error:
Error connecting to Sphinx via the MySQL protocol. Error connecting to Sphinx via the MySQL protocol. Can't connect to MySQL server on '127.0.0.1' (111) ...
thinking_sphinx.yml:
development:
quiet_deltas: true
mysql41: 9311
bin_path: "/usr/bin"
searchd_binary_name: searchd
indexer_binary_name: indexer
min_infix_len: 3
min_word_len: 2
html_strip: 1
index_exact_words: 1
min_stemming_len: 4
charset_type: "utf-8"
test:
mysql41: 9311
production:
mysql41: 9311
No such problems on localhost, server on WebRick.
What could I do, to avoid this. There is only one thinking-sphinx process. Maybe I can increase it's number.
Thanks in advance!
Update
I rebuilt thinking sphinx, I haven't done it for long time, now it doesn't falling, maybe thing was in it. But I am still interested in how to run serveral ts processes, or it is unecessary.
Via the help files:
You can run as many Sphinx instances as you wish on one machine - but each must be bound to a different port. You can do this via the config/thinking_sphinx.yml file - just add a setting for the port for the specific environment using the mysql41 setting (or port for pre-v3):
staging:
mysql41: 9313
My goal is to have 2 databases and 2 deployments of rails on the same server. I want to have the regular production server using the production database. Then I want to be able to deploy to a different web address that will use a different database. My goal is to be able to push the backup first and make sure all the migrations etc. work in the full environment. I would then push it to the main server.
The issue I seem to run into is that the database.ml file only lists the 3 database types. The passenger environment will also assume that its running in production and would migrate the main MySQL database even if I deploy the code to a different directory. Whats the best way around this? Was wondering if it is simple or if it involves setting lots of variables in lots of places? Any suggestions would be great!
You can add other database types to database.yml as you see fit.
staging:
adapter: postgresql
host: mydb_host
database: mydb_staging
etc...
You can copy config/environments/production.rb to config/environments/staging.rb and leave it as is so the two environments are exactly the same, or tweak staging.rb as you see fit.
Now you have a staging environment! Use it where appropriate, e.g.:
rake RAILS_ENV=staging db:migrate
I am not a passenger expert, but know that my shop has both staging and production instances of apps running on the same server under passenger, so it can be done. Google can probably instruct you better on configuring that than I can.
I want to run the same rails app several times with a few configuration differences on the same server. Each app must have its own:
database
ports
cookie_store key(not sure if needed)
secret_key_base
Let's say I want to run the same code multiple times to service different cities:
newyork.myapp.com and boston.myapp.com. I wonder what would be the best way to store and use the different configurations.
Use environments:
Add a file to config/environments, one for each site you want to host. Name it something along the lines of 'production_[city]', replacing [city] with the city name. Copy the production.rb file contents into each.
in config/database.yml find the 'production' block of yml and duplicate it once for each site you want to host. Rename the root node of each block to production_[city], matching the filenames above. For example:
production_ny:
adapter: mysql2
username: my_user
password: my_pa$$w0rd%&*#
database: production_ny
This takes care of the database settings per app.
Assuming Rails 4, your secret key base will be in config/secrets.yml under an environment node, as per config/database.yml so just add an entry per site:
production_ny:
secret_key_base: xxxxxxxx1111111122222223333333344444444...
All sites will need an end-point. Using a different domain for each would give you separate cookies and sessions for free. Or you could go the subdomain route:
http://guides.rubyonrails.org/configuring.html#deploy-to-a-subdirectory-relative-url-root
tldr:
In your config/environments/production_ny.rb:
config.relative_url_root = "/ny"
for example. Then set up your webserver to handle subdirectories. You may need to add a path to cookies in order to scope them to the virtual directory. Just use:
Rails.configuration.relative_url_root
Ports, again, will have to be set up at the webserver level. (Apache, nginx, etc.)
To see if it all works, try this in the command-line:
RAILS_ENV=production_ny bundle exec rails s
This should start a development style webserver for you to access, but use the production_ny environment.
You will need to create and set up your database as normal - create, migrate, seed.
The final step is setting the RAILS_ENV environment variable to production_[city] per app using your web server. The steps to do this will depend on your technology choice.
I've made 2 apps, App A and App B. App A's sole purpose is to allow users to sign up and App B's purpose is to take select users from App A email them. Since App A & B were created independently & are hosted in 2 separate Heroku instances, how can App B access the users database in App A? Is there a way to push certain relevant rows from App A to App B?
There is currently no way of sharing databases between Heroku apps.
You might be able to use the Amazon RDS add-on to run a dedicated MySQL instance.
The alternative is going to be creating an API and pushing data between the apps. You can run a background process to push the data in and out.
You can connect several Heroku instances on the same shared PostgreSQL database, given by the shared-database:5mb free add-on on Heroku.
On the instance on which you have the database, type:
$ heroku config
This will show a lot of settings, in which you'll see something like this:
DATABASE_URL => postgres://fbksgiuqlv:BuIvJDfS_eOBDJDZCc9SP#ec2-104-20-247-168.compute-1.amazonaws.com/fbksgiuqlv
This is the database connection string that your instances will be using.
Then on the other instances, overwrite the DATABASE_URL config variable by typing:
$ heroku config:add DATABASE_URL=your_new_connection_string
So tinkered a little around and did as below and it worked
prompt$ heroku console
Ruby console for your-app.heroku.com
>> dbconfig = YAML.load(File.read('config/database.yml'))
=> {"production"=>{"encoding"=>"unicode", "port"=>5432, "adapter"=>"postgresql", "username"=>"xxxxxxxxxxxxxx", "database"=>"xxxxxxxxxxxxx", "host"=>"kklasfdsfjsfdsfsd.fsdf.dsfdsf", "password"=>"xxxxxxxxxxxxxxxxxx"}}
puts dbconfig.to_yaml
---
production:
encoding: unicode
port: 5432
adapter: postgresql
username: xxxxxxxxxxx
database: xxxxxxxxxxxxxxx
host: ec2-50-2323kskdsakd231.amazonaws.com
password: xxxxxxxxxxxxxx
Then copy and paste the yaml to a connection for the other DB
and it works!!! For me!!!
I was looking into this as well and I noticed that it seems like it is now possible to actually do this.
See: http://newsletterer.heroku.com/2011/07 ("did you know" section at the bottom)
Basically you set up one app, retrieve the app database url, and add that url to the config of the other app, like so:
$ heroku config | grep DATABASE_URL --app sushi
DATABASE_URL => postgres://lswlmfdsfos:5FSLVUSLLT123#ec2-123-456-78-90.compute-1.amazonaws.com/ldfoiusfsf
Then, set the DATABASE_URL for new apps to this value:
$ heroku config:add DATABASE_URL=postgres://lswlmfdsfos:5FSLVUSLLT123#ec2-123-456-78-90.compute-1.amazonaws.com/ldfoiusfsf --app sushi-analytics
Adding config vars: DATABASE_URL => postgres://lswlm...m/ldfoiusfsf
Restarting app... done, v74.
That's it — now both apps will share one database.
I haven't tried this yet, but I am about to give it a shot, as I too was thinking about splitting an existing app into two apps. Let's hope this actually works!
Heroku actually overwrites the database.yml file that you have checked in, you can verify this by using the "heroku shell" command and typing cat config/databse.yml
They make up a bunch of random stuff that is used per application. I don't believe its possible to stop them from doing that.
You might be able to do this if you use schemas with PostgreSQL.
I have two different rails applications running thinking_shpinx, and one seems to not be using the correct index.
I tried setting the port in the sphinx.yml but it seems to not have any effect.
Matthew, had you set port in sphinx.yml on a per-environment basis?
ie:
development:
port: 3312
test:
port: 3313
production:
port: 3312
Needed to kill searchd and clear the pids in /log