Pow’s not responding and I think I might cry.
I love Pow. Seriously, I love it. It really is the easiest way to build Rails and Rack apps in OS X. The only thing* I don’t like about about Pow is when it doesn’t work.
Has this happened to you? You are plugging along, knocking out your stories in Pivotal Tracker and you take a break or stop for the night. You come back to your computer in full mindset that the code you are about to write is going to save the world or make you a billion dollars (hopefully both). You craft some beautiful code, click refresh on your browser, and wait patiently to bask in your own glory only to be greeted by a timeout error. No matter what you do, you can’t get pow to respond. If you check the status, you get something like this
$ curl -H host:pow localhost/config.json
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>502 Proxy Error</title>
</head><body>
<h1>Proxy Error</h1>
<p>The proxy server received an invalid
response from an upstream server.<br />
The proxy server could not handle the request <em><a href="/config.json">GET /config.json</a></em>.<p>
Reason: <strong>Error reading from remote server</strong></p></p>
<hr>
<address>Apache/2.2.20 (Unix) DAV/2 PHP/5.3.6 with Suhosin-Patch Server at pow Port 80</address>
</body></html>
Frustrating, right? Reboot, still not working! I can count the number of times this has happened by the self-inflicted cuts on my arm and hairless patches on my head. Is this your story? If so, fear not my friend. For the great Mike Sutton has solved this issue and incredible Matthew Ratzloff over at Built From Source wrote a nice little post about it.
The basic gist is to save a shell script called “pow-restart” with the following contents and execute it whenever Pow stops responding.
#!/bin/bash
# Restarts Pow when DNS fails to resolve
lsof | grep 20560 | awk '{print $2}' | xargs kill -9
launchctl unload ~/Library/LaunchAgents/cx.pow.powd.plist
launchctl load ~/Library/LaunchAgents/cx.pow.powd.plist
Huge thanks to both Mike and Matt for finding and posting this info. I owe you both a beer.
*There are actually of lot of things I don’t like. More on this later.

