Select Page
Using Foreman with Upstart & Capistrano

Using Foreman with Upstart & Capistrano

Foreman is a great tool for running multiple processes along side your rails project. Processes like Redis, SidekiqFaye or any other process that doesn’t run within Rails itself. Foreman runs in your development environment as well as your production environments. To use Foreman in production, you have to export it’s config file in one of the following formats:

Since most of the servers we work on are Ubuntu, and (newer versions of) Ubuntu come with Upstart preinstalled, we generate the Foreman export script to Upstart.

When recently deploying a customer’s project, we noticed that the Foreman Sidekiq process wasn’t starting up.

The Procfile we were working with had this content:

Exporting it generated these files:

Isolated the Sidekiq Upstart script and ran it by itself:

Resulted in:

Unfortunately there was no log output in the usual place: /var/log/upstart/myapp-staging-sidekiq-1.log
It would merely fail without a result.

After many hours of research, trial and error, the closest answer we came to was that bundle couldn’t be found (via PATH). Issue #443 states that you need to setup a .env file with your servers PATH because as of version 0.63 of Foreman it no longer assumes your PATH. However, most of our development happens on Macs so the environment variables are vastly different than the servers we deploy on. The solution that seems to work best for any server setup we deploy to is the following:

Notice that line 5 takes the current server’s path and assigns it to the .env file in the current directory. Line 6 and 7 setup the environment for the Foreman processes. This helps ensure the .env file is always running what the server is running as well as it gets updated when a new foreman:export command is executed.

Please let us know if you found this helpful.

Sublime Text Editor Random Caret Height and Width

Sublime Text Editor Random Caret Height and Width

Recently when working in Sublime Text Editor I’ve noticed that my caret changed from it’s usual look and feel to something that was extra wide and extra tall!

Sublime Caret Random Size

This didn’t bother me too much until it started covering up brackets or quotes under the extra width of the caret. I’m not sure why this happens but after a long search I was finally able to fix it:

Under “Preferences” > “Settings User” just add this:

That’s all it takes to get your original caret back.
This fix comes from this forum entry.

Want to learn other cool Sublime Text tweaks? Checkout this blog post: 5 great visual tweaks for Sublime Text

New Alfred 2 Workflows

New Alfred 2 Workflows

Alfred Workflows

A few years ago I heard of this small app called Alfred. I started playing with it while it was still in its first Beta. After a few days of using it I know it was an app that would make a huge change in my workflow. I also knew I wanted to support the developers as much as I could so I bought the app as a “Mega Supporter”. Now I never thought that I would get anything extra for this, but it turns out that the developers wanted to thank their supporters by giving them early access to Alfred 2. (more…)

User does not respond to ‘devise’ method

I’ve recently went back to an old project and it seems to have stopped working giving me this error:

[read full stack trace at: gist]
Since I didn’t really change anything, I was surprised to see it break. So I tried to do what it said, I changed that I had a require statement for my ORM which was Mongoid. I had: (in config/devise.rb)

(more…)

Access to the webpage was denied on chrome

Access to the webpage was denied on chrome

While working hard at getting an application up and running for a lunch tomorrow, I ran into this annoying screen:

 

Access to the webpage was denied
Not really reading the message fully, I thought maybe my web server is throwing some sort of error that was telling chrome to stop the request. Quick google for “Access to the webpage was denied passenger” didn’t really return anything useful, however then I remembered that I switched to Pow a while back, so I google again for “Access to the webpage was denied pow” but that was even less useful.

 

So I re-read the message and followed the included link from the message and found this:

 

Chrome net internals httpThrottling
Unchecking the checkbox removed this feature.

 

Why this happens

(more…)

Wicked_PDF working in Rails 3.1

I recently updated one of my apps to Rails 3.1 and found that my PDF generating tests were failing because they were unable to find the CSS or images to use in the PDF.

So I started playing around, and here is what I got:

In your app, add a new initializer (or edit your existing wicked_pdf.rb initializer) and put the following:

As you can see in the code, I also replaced the background urls with correct references, this is assuming that you’re keeping your CSS images in the same location as your normal images (which I don’t see a reason why not but of course you can always tweak the script)

Possible Issues

Pow.cx

I had one issue with my generated PDF using pow.cx, my CPU would jump to 100% (on the pow process) and the page would timeout. After upgrading to the latest version of pow (0.3.2) using this command:

I was able to see my PDFs without an issue.

Additional Sources:

http://blog.phusion.nl/2011/08/14/rendering-rails-3-1-assets-to-string/
https://github.com/mileszs/wicked_pdf/issues/48

Small update: (14/02/2012)

Small change to the above code to fix issue that prevented CSS from being rendered correctly.

Cucumber visiting pages using different formats

Ever wonder how you can write a cucumber test that would test how your web app responds to a different format, something like JSON or XML?
I was trying to do the following:

Running this code I would get a “Can’t find mapping from “the feeds page using json” to a path.

Trying to figure out how I can do this, I tried to write a new step, like this:

but this resulted in: Ambiguous match of “I go to the feeds page using json”

So, I posted the question on StackOverFlow and it seems everyone was thinking the same way I was.

I continued playing  with this idea and here is how I solved the problem:

Modifying the paths.rb file, I changed (Changes are in bold)

This way I don’t have to modify anything else in my features and everything just works.

RVM install ruby-1.8.7-p330 fails

Today I’m thinking of getting back into so good old work and I read there is a new patch to Ruby, version p330. So I figure that RVM (Ruby Version Manager) being so easy and quick to update, I’d do the good old “rvm get head, rvm reload, rvm update 1.8.7” and I’m off to the races.

Well it wasn’t quite as simple. I ended up with an error:
ruby-1.8.7-p330 - #fetching
ruby-1.8.7-p330 - #extracting ruby-1.8.7-p330 to /Users/andrew/.rvm/src/ruby-1.8.7-p330
ruby-1.8.7-p330 - #extracted to /Users/andrew/.rvm/src/ruby-1.8.7-p330
ruby-1.8.7-p330 - #configuring
ruby-1.8.7-p330 - #compiling
Error running 'make ', please read /Users/andrew/.rvm/log/ruby-1.8.7-p330/make.log
There has been an error while running make. Halting the installation.

When I looked into the the make.log, It had this to say:
readline.c: In function ‘username_completion_proc_call’:
readline.c:730: error: ‘username_completion_function’ undeclared (first use in this function)
readline.c:730: error: (Each undeclared identifier is reported only once
readline.c:730: error: for each function it appears in.)

So, I figured this was going to take too long to deal with, and moved on to working on my projects. That is till I opened up my project and and did a “rvm [email protected]” and it come up with:
warn: ruby ruby-1.8.7-p330 is not installed.
To install do: 'rvm install ruby-1.8.7-p330'

Great! Now I can’t upgrade, and I can’t work with what I have!

Long story short, I figured out that I was missing readline (now I’m sure I’ve installed in a long while ago, but I think I was missing the latest version). Also, rvm install readline resulted in an “Unrecognized command line argument: ‘readline’ ( see: ‘rvm usage’ )

Turns out RVM updated it’s command to install readline to:
rvm package install readline

Update: (Nov 10, 2011)
If you’re using a newer version of RVM, package has been renamed to pkg, so the command to install readline would be:
rvm pkg install readline

However this didn’t fix my install issue, still got the same error. Luckily I found a post that pointed out that my rvm may not know where readline is (odd, as I used rvm to install readline). Running this command allowed me to install it correctly:
rvm install 1.8.7 -C –with-readline-dir=/Users/andrew/.rvm/usr
[Notice: ‘andrew’ is my username on my mac, yours might be different]

rvm install 1.8.7 -C --with-readline-dir=$rvm_path/usr

Like always, I’m hoping this helps some people out.

Let me know if you have any issues.