Pow — A Great Server for your Mac Bat Cave

Somehow I stumbled across this great little tool  — oh yeah, John Nunemaker mentioned “powder,” which was “Syntactic sugar for http://pow.cx/

Huh? Syntactic what? For “pow” what? John hasn’t steered me wrong yet, so I decided I needed to look at what Pow was. In 37Signals own words:

Pow: Zero-configuration Rack Server for Mac OS X

In other words:

You can run a bunch of your rails apps all at once, with ease.

This is worth the effort to try and get running to see if it will help ease how you work with multiple Rails apps.

Since my experience was a bit off from the awesome-looking Screencast teaser, I figured I would share it in case others might benefit from the troubleshooting.

Once I solved the Pow-not-working-like-magic-from-the-start problems, it worked right out of the box with a Rails3 App. Not so much with my Rails2 apps. So, you can either try to do it the Rails3 way from the start (see below for instructions), or barge ahead and see how far you get (knowing now what I do for Rails2, barging is probably a pretty safe bet).

Yes, I am repeating what is in the main website… but then aggregating common troubleshooting experiences ad fixes below, to save you (and my colleagues) time.

Install Pow:

$ curl get.pow.cx | sh

Be certain you see “*** Installed” or it is not! (See Troubleshooting section below if need be.)

jonsmac2-2:.pow jon$ curl get.pow.cx | sh
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
100  2722  100  2722    0     0  17322      0 --:--:-- --:--:-- --:--:-- 34455
*** Installing Pow 0.2.2...
*** Installing local configuration files...
*** Starting the Pow server...
*** Installed

If you get upset, just uninstall:

$ curl get.pow.cx/uninstall.sh | sh
Symbolic Link to Rails3 App
Symbolic Link to Rails3 App

Configure:

$ cd ~/.pow
$ ln -s /path/to/myapp

To the right is an example. Name the link if you do not want to use the default folder name. For example:

ln -s ~/railsprojects/first_app jkfirstapp

This allows you to then enter the following into the browser, using the symbolic link name (or the default folder name):

http://jkfirstapp.dev

If that didn’t work, continue onward, your journey will be short (I hope).

Troubleshooting

I was disappointed when the magic didn’t happen right away. Boy does the Ruby community spoil us! So a hunting I will go…

Create a Rails3 App

If you are only doing Rails2, see below for the config.ru fix. Otherwise, creating a vanilla Rails3 app is a good way to test that Pow is properly configured. Here is a simple Rails3 app (from Michael Hartl’s Ruby on Rails3 Tutorial):

mkdir ~/railsprojects
rails new first_app

edit the Gemfile:

gem 'rails', '3.0.1'
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'

Then execute:

bundle install
rails server

It should be running with the default server page.

I got Nothing!

If pow did not install, or you get seemingly NOTHING when going to the browser webpage, look no further than here. The following worked for me (and others). Seems that the permissions are not quite right sometimes:

before:

-rw-rw-r--   1 jon  staff   518B Apr 18 13:42 cx.pow.powd.plist

So I ran this:

jonsmac2-2:.pow jon$ launchctl load -Fw ~/Library/LaunchAgents/cx.pow.powd.plist
jonsmac2-2:.pow jon$ chmod 644 ~/Library/LaunchAgents/cx.pow.powd.plist
jonsmac2-2:.pow jon$ curl get.pow.cx | sh

And, after the re-install, the perms ended up as you might expect:

-rw-r--r--   1 jon  staff   518B Apr 18 13:42 cx.pow.powd.plist

Checking It’s Running

This is admittedly odd output for a “working” install, but it gives you at least one data point to compare what you get versus this. Do the following:

cd ~/Library/Application Support/Pow/Current/bin
jonsmac2-2:bin jon$ ./pow

On my Mac it results in:

node.js:134
    throw e; // process.nextTick error, or 'error' event on first tick
    ^
Error: EADDRINUSE, Address already in use
at HttpServer._doListen (net.js:1089:5)
at net.js:1060:14
at Object.lookup (dns.js:159:5)
at HttpServer.listen (net.js:1054:20)
at Array.<anonymous> (/Users/jon/Library/Application Support/Pow/Versions/0.2.2/lib/daemon.js:34:27)
at EventEmitter._tickCallback (node.js:126:26)

Domain Isn’t Setup

If you see this:

No such app
No such application can be found!

Then you know you have screwed up the symbolic link.

Try again, and be careful and exact.

Trouble Accessing Dev domains

Some folks needed this simple fix:

touch /etc/resolver/dev

Rails2: Cannot GET /? –> config.ru is Missing!

That’s right, you see: Cannot GET / in the browser. Bet you never saw that before!

This means that you are missing the Rackup config.ru file in your application’s root. Try adding this file (you can see it in the folder screenshot above):

# This file is used by Rack-based servers to start the application.
require "./config/environment"
use Rails::Rack::LogTailer
use Rails::Rack::Static
run ActionController::Dispatcher.new

Pow Can’t Start Your App

This is most likely, genuinely, truly your error… Sorry to say!

The error below is because the config.ru was completely wrong (I was trying the Rails3 project file (duh — it invokes a class in a module named after the app itself)):

Pow can’t start your application.

/Users/jon/railsprojects/track_my_league/tml raised an exception during boot.
NameError: uninitialized constant FirstApp
/Users/jon/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:443:in `load_missing_constant'
/Users/jon/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing'
/Users/jon/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:92:in `const_missing'
/Users/jon/railsprojects/track_my_league/tml/config.ru:4
/Users/jon/Library/Application Support/Pow/Versions/0.2.2/node_modules/nack/lib/nack/builder.rb:4:in `instance_eval'
/Users/jon/Library/Application Support/Pow/Versions/0.2.2/node_modules/nack/lib/nack/builder.rb:4:in `initialize'
/Users/jon/railsprojects/track_my_league/tml/config.ru:1:in `new'
/Users/jon/railsprojects/track_my_league/tml/config.ru:1

Here the error is that I do not have the gem environment set up properly with RVM (using .rvmrc). Easily diagnosed because I can’t even start the app manually!

SystemExit: exit
./config/boot.rb:66:in `exit'
./config/boot.rb:66:in `load_rails_gem'
./config/boot.rb:54:in `load_initializer'
./config/boot.rb:38:in `run'
./config/boot.rb:11:in `boot!'
./config/boot.rb:110
./config/environment.rb:7:in `require'
./config/environment.rb:7
/Users/jon/railsprojects/tml/TML/config.ru:3:in `require'
/Users/jon/railsprojects/tml/TML/config.ru:3
/Users/jon/Library/Application Support/Pow/Versions/0.2.2/node_modules/nack/lib/nack/builder.rb:4:in `instance_eval'
/Users/jon/Library/Application Support/Pow/Versions/0.2.2/node_modules/nack/lib/nack/builder.rb:4:in `initialize'
/Users/jon/railsprojects/tml/TML/config.ru:1:in `new'
/Users/jon/railsprojects/tml/TML/config.ru:1

Hope this helps!

RVM Install Troubleshooting

All I wanted to do was sit down with Mike Hartl’s “Ruby on Rails 3 Tutorial” yesterday. Hours later, with nothing to show other than a zillion open terminals, I punted and watched the Flyers beat the Sabres despite playing like girls (I know, unfair to girls!). Then I went to bed.

So I must have had a dorked up installation of RVM or something, because when I tried to install Ruby 1.9.2 and Rails 3 and upgrade RVM I ran into <ahem> “issues.” I was getting weird errors like:

error installing rails i18n requires rubygems version 1.3.5
gem_runner.rb:85:in `<top (required)>': undefined method `load_plugins'

After exploring all sorts of similar woes that other people had and not really getting that magic googullet (Google Bullet), I decided to go all nuclear (apologies to Japanese readers). I was able to run:

rvm implode

Which made “rvm -v” fail to find rvm — a good thing. It meant I had uninstalled RVM. (Or so I thought!)

I also deleted the RVM stuff from the bash_profile file(s). Just to attempt to eliminate voodoo dolls.

But I still ran into stupid errors (stupid voodoo dolls!):

error installing RVM fatal: Not a git repository (or any of the parent directories): .git

After much pain and suffering (well, only in a wimpy software relative sense), my guess is that I installed rvm as sudo at one point or installed the gem, or somehow had things “cross-eyed.” I don’t know…

I guess I should be more diligent, because in general you get spoiled by Ruby and gems and Rails and the general euphoria of how easy things are. Until they aren’t.

Today, I ended up fixing my system by looking for “rvm” on my system, and cleaning up leftovers. The crumbs from my sloppy eating at the trough of Ruby, I suppose.

I saw some directories holding rvm docs. I whacked them.

I saw some directories with rvm source, archives… Gone.

I uninstalled the rvm gem. (Oops. Who put that there?)

Finally, I retried the install:

jonsmac$ bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

And added this to ~/.bash_profile And I restarted terminal because I always forget how to do that source ~/.bash_profile thing…

jonsmac2-2:~ jon$ rvm -v
rvm 1.6.2 by Wayne E. Seguin (wayneeseguin@gmail.com) [https://rvm.beginrescueend.com/]

Shazam! No errors. Thanks Wayne!

Now I can get past page 15 in Mike’s tutorial book!