Mongrel2 rack handler won't daemonize - ruby-on-rails-3

I am trying to deploy an app with Mongrel2-rack-rails3 stack. I am using khi-rack-mongrel2 handler for ruby rack. The problem is that even if I setup everything for local development, I can't make rails server daemonize itself by running it with -d option. While starting without daemonization option I get following output:
% rails s Mongrel2
=> Booting Mongrel2
=> Rails 3.0.9 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
The handler starts and I can make requests to my rails app. However If I start my server with -d option I get this:
% rails s Mongrel2 -d
=> Booting Mongrel2
=> Rails 3.0.9 application starting in development on http://0.0.0.0:3000
The handler starts, but does not daemonize itself. Can someone point me out to the issue at hand?
Here are the contents of my config.ru file:
require ::File.expand_path('../config/environment', __FILE__)
Rack::Handler::Mongrel2.run(MyProject::Application,
:recv => 'tcp://127.0.0.1:2050',
:send => 'tcp://127.0.0.1:2051',
:uuid => 'my_project'
)

Related

How can I get rails to use pg by default?

It's not a huge burden but I would really like to be able to change the default gem-set on my rails apps when I create them so that they're ready for Heroku.
What is the best way to go about doing this?
You can specify the database with -d when running rails new:
Usage:
rails new APP_PATH [options]
Options:
-d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
# Default: sqlite3
Description:
You can specify extra command-line arguments to be used every time
'rails new' runs in the .railsrc configuration file in your home directory.
So for PostgreSQL this is:
rails new myapp -d postgresql
To make this the default put -d postgresql into ~/.railsrc
Another option is to change gem 'sqlite3' to gem 'pg' in your Gemfile as suggested in Getting Started with Rails 3.x on Heroku.

apn_sender gem daemon not running

Im using apn_sender for rails 3 and i have been able to install the gem and get it working just fine by using
rake apn:sender
I have tried to get it started in production mode on a ubuntu box by starting the daemon and it does not seem to work. When i type
script/apn_sender --environment=production --verbose start
I dont see anything. No log present.
when i try to type
script/apn_sender status
It returns with
apn_sender: no instances running
Just trying to understand why it is not running.
i just solved this problem. Try to create a file called 'script' in generators/apn_sender/templates . .
Put this in your script file
# !/usr/bin/env ruby
# Daemons sets pwd to /, so we have to explicitly set RAILS_ROOT
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
require 'rubygems'
require 'apn'
require 'apn/sender_daemon'
APN::SenderDaemon.new(ARGV).daemonize
bash 'rails g apn_sender' in your terminal and will create 'script/apn_server' with same content as above
After that bash this code
./script/apn_server --environment=production --verbose start
it will create log/apn_sender.log . Try running
APN.notify('token',{:alert => '#' , :badge => 1})
or else in rails c to confirm if it works or not , and of course
rake apn:sender
Hope it will help :)
EDIT
You have to install redis and configure

Refinery error when pushing to Heroku

I've a Refinery app, works great locally.
Created a bamboo stack on Heroku.
When I try to push I can see this:
Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
Then I open it up in browser:
"We're sorry, but something went wrong."
$ heroku logs
Rendered vendor/bundle/ruby/1.9.1/gems/refinerycms-authentication-2.0.2/app/views/refinery/users/new.html.erb within refinery/layouts/login (82.3ms)
2012-03-15T14:43:25+00:00 app[web.1]: Completed 500 Internal Server Error in 1269ms
full output is here
Any help is great, thanks!
+++
Update:
Updated the stack to Cedar and made Ruby env 1.9.3
$ heroku config
DATABASE_URL => ..
GEM_PATH => vendor/bundle/ruby/1.9.1
LANG => en_US.UTF-8
PATH => bin:vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin
RACK_ENV => production
RAILS_ENV => production
RUBY_VERSION => ruby-1.9.3-p0
SHARED_DATABASE_URL => ..
$ heroku info --app mimacohuoncedar
=== mimacohuoncedar
Addons: Basic Logging, Shared Database 5MB
Database Size: (empty)
Git URL: git#heroku.com:mimacohuoncedar.git
Owner: ..
Repo Size: 9M
Slug Size: 19M
Stack: cedar
Web URL: http://mimacohuoncedar.herokuapp.com/
$ heroku logs now shows this:
this-updated
Where to go on? Thanks
Dont know if you managed to fix this but I ran into the same issue using the Cedar stack. Found this article on Heroku that seemed to do the trick for me. Ran the line in terminal and it pushed first time.
I am seeing this same error, and the accepted answer did not solve it for me;
This blog however, did the trick. The blog title refers to Rails 3.2, but I'm on 3.1 and was seeing this same error.
The blog recommended adding this line to application.rb.
config.assets.initialize_on_precompile = false
The meaning, as summarized from the article;
This option prevents the Rails environment from being loaded when the assets:precompile task is executed. Because Heroku precompiles assets before setting the database configuration, you need to set this configuration to false or you Rails application will try to connect to an unexisting database.
Added the line and pushed, everything seems good now.
That output looks suspiciously like Cedar stack and not Bamboo - give http://devcenter.heroku.com/articles/labs-user-env-compile a go. That should sort you out.

Rails 3 / whenever cron not firing

I am using whenever to fire a rake task every 5 minutes for my app.
schedule.rb:
every 5.minutes do
rake "audit",
:environment => 'development'
end
"whenever" in console:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash -l -c 'cd /Users/john/Sites/rambler && RAILS_ENV=development bundle exec rake audit --silent'
"rake audit" in console works properly.
So all looks good .... except it doesn't work. Nothing happens every five minutes.
Is this because I am trying to run it in development / local?
Thanks!
You need to update your cron file every time you change it.
After you have addded your cron job do this:
whenever --update-crontab 'project_name'
Also I only found whenever working fine in production mode only.
UPDATE:
I have found that we can use whenever in development mode also. Just add
set :environment, "development"
set :output, {:error => "log/error.log", :standard => "log/cron.log"}
to your scehdule.rb file. ( The log one is optional but still you can use that for testing purpose)
Finally I have solved how to run the gem Whenever. It's working good on production, but not in development mode (I think that to working good in dev mode you must do some tricks).
see this answer for working in dev mode: Cron not working in Whenever gem
Then, these are the processes to do:
install the gem
write your scheduler.rb file
push to the remote server
login to the remote server (for example with ssh)
see if whenever is good uploaded by running in terminal: whenever
update whenever crontab by running: whenever --update-crontab
restart the server crontab (for example in ubuntu): sudo service cron restart
check if crontab are good implemented on the server: crontab -l
That is!

Resque web interface loading error

I have installed Resque in Rails 3 using this tutorial.
The problem is when I'm trying to use the Resque web interface. When I go to {localhost}/resque/ , the browser is getting redirected to {localhost}/resque/resque/overview/true/false which essentially does not exist.
However {localhost}/resque/overview seems to open up the correct interface, although has broken links. (Like clicking on stats again redirects me to {localhost}/resque/resque/stats/resque/true/false, which is again non-existant)
Here is my config.ru file:
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
require 'resque/server'
require 'logger'
# Set the AUTH env variable to your basic auth password to protect Resque.
AUTH_PASSWORD = 'secret'
if AUTH_PASSWORD
Resque::Server.use Rack::Auth::Basic do |username, password|
password == AUTH_PASSWORD
end
end
run Rack::URLMap.new \
"/" => Marina::Application,
"/resque" => Resque::Server.new
It seems that it's a problem with Sinatra version 1.2.0. Using Sinatra 1.1.3 works fine. Details on this Resque open issue: https://github.com/defunkt/resque/issues#issue/221
From the issue description:
When I go to "/resque" route it
redirects to
"/resque/resque/overview/true/false"
and fail with 404 Sinatra error page.
Add sinatra 1.1.3 to Gemfile, run
"bundle update sinatra" and voila:
http://cl.ly/460d0C0x2N1W2D333j1f
As I'm new to Ruby and don't know yet what is a Gemfile :), I forced the installation of Sinatra 1.1.3 and it worked like a charm:
$ gem uninstall sinatra
$ gem install sinatra -v 1.1.3
Regards,
Deluan.