Permalink
Browse files

Initial check in

  • Loading branch information...
0 parents commit 7bbbd848630359b326214ba58653b3b2b8d2954f @IamNaN committed Oct 26, 2012
Showing with 155 additions and 0 deletions.
  1. +5 −0 Gemfile
  2. +44 −0 Gemfile.lock
  3. +1 −0 Procfile
  4. +77 −0 README.md
  5. +18 −0 config/private_pub.yml
  6. +10 −0 private_pub.ru
@@ -0,0 +1,5 @@
+source 'https://rubygems.org'
+
+gem 'private_pub'
+gem 'thin'
+gem 'foreman'
@@ -0,0 +1,44 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ addressable (2.3.2)
+ cookiejar (0.3.0)
+ daemons (1.1.9)
+ em-http-request (1.0.3)
+ addressable (>= 2.2.3)
+ cookiejar
+ em-socksify
+ eventmachine (>= 1.0.0.beta.4)
+ http_parser.rb (>= 0.5.3)
+ em-socksify (0.2.1)
+ eventmachine (>= 1.0.0.beta.4)
+ eventmachine (1.0.0)
+ faye (0.8.6)
+ cookiejar (>= 0.3.0)
+ em-http-request (>= 0.3.0)
+ eventmachine (>= 0.12.0)
+ faye-websocket (>= 0.4.0)
+ rack (>= 1.0.0)
+ yajl-ruby (>= 1.0.0)
+ faye-websocket (0.4.6)
+ eventmachine (>= 0.12.0)
+ foreman (0.60.2)
+ thor (>= 0.13.6)
+ http_parser.rb (0.5.3)
+ private_pub (1.0.3)
+ faye
+ rack (1.4.1)
+ thin (1.5.0)
+ daemons (>= 1.0.9)
+ eventmachine (>= 0.12.6)
+ rack (>= 1.0.0)
+ thor (0.16.0)
+ yajl-ruby (1.1.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ foreman
+ private_pub
+ thin
@@ -0,0 +1 @@
+web: bundle exec rackup private_pub.ru -s thin -p $PORT -E production
@@ -0,0 +1,77 @@
+## Heroku + private_pub ##
+
+### Background ###
+
+Faye ([github](http://github.com/faye/faye)) is a rack-based messaging system that allows web clients to communicate.
+
+Ryan Bates created private_pub ([github](http://github.com/ryanb/private_pub)) to easily add Faye to Rails projects. There is a Railscast for that [here](http://http://railscasts.com/episodes/316-private-pub).
+
+Heroku can be restrictive given memory and processor constraints, especially at the free level, so running any Faye server concurrently with a rails app isn't stable.
+
+This project makes it easy by giving you a barebones private_pub that runs as a separate app on Heroku.
+
+### Installation ###
+
+Setting up heroku_private_pub is pretty easy, just clone, edit one file, and push to Heroku. Of course, there's a little handwaving for you, so here are the excruciating details.
+
+1. Clone heroku_private_pub to your development computer, in a new project folder (not the same as your rails project). In this example we'll call it 'mypubserver':
+
+ ```
+ ~> cd projects
+ ~/projects> git clone git://github.com/IamNaN/heroku_private_pub mypubserver
+ Cloning into 'mypubserver'...
+ remote: Counting objects: 15, done.
+ remote: Compressing objects: 100% (11/11), done.
+ remote: Total 15 (delta 3), reused 14 (delta 2)
+ Receiving objects: 100% (15/15), done.
+ Resolving deltas: 100% (3/3), done.
+ ~/projects> cd mypubserver
+ ~/projects/mypubserver>
+ ```
+2. Open `config/private_pub.yaml` and replace MY_KEY with the same one you have in the `private_pub.yml` of your rails project. Also, replace MY_APP with the name of the heroku app where *this* private_pub server will be install (this is different from the name of your rails app). Save this file.
+3. Run the bundler to install the gems
+ ```
+ ~/projects/mypubserver> bundle install
+ ```
+3. Commit the changes locally.
+ ```
+ ~/projects/mypubserver> git commit -am "Adding my configuration info"
+ ```
+5. Install the heroku gem if you haven't already. They are "sunsetting" (a nice way of saying leaving you in the dark) the heroku gem soon in favor of a less-rails-y toolbelt. I'll abandon heroku when they abandon the gem, so maybe someone else will contribute that update.
+ ```
+ ~/projects/mypubserver> gem install heroku
+ ```
+6. Create your heroku app with the heroku tool installed by the gem.
+ ```
+ ~/projects/mypubserver> heroku apps:create mypubserver
+ Creating mypubserver... done, stack is cedar
+ http://mypubserver.herokuapp.com/ | git@heroku.com:mypubserver.git
+ Git remote heroku added
+ ```
+7. Push it to heroku.
+ ```
+ ~/projects/mypubserver> git push heroku master
+ ```
+
+After you have verified everything is working as expected (see Troubleshooting below) you can delete this project. However, it is handy if you ever want to watch the traffic going through your Faye server (see "What's It Saying?" below).
+
+If it is unlikely you'll ever need it again. In the even that you find yourself needing it again, you can just pull it from Heroku thusly:
+```
+git clone git@heroku.com:mypubserver.git mypubserver
+```
+
+Make your changes, commit them, and push them again just like we did above.
+
+### Troubleshooting ###
+
+#### Is It Running? ####
+You can test that your new Faye server running properly by browsing to the app. In the above example, we would go to http://mypubserver.herokuapp.com should see a plain text message "Sure you're not looking for /faye?"
+
+#### Is It Configured? ####
+If that is working but your messages aren't finding their way between your app and clients, double check the settings in `config\private_pub.yml` match those in the same file in your rails project.
+
+#### What's It Saying? ####
+If that's correct but you're still seeing problems, then check out the log to see what the problem is.
+```
+~/projects/mypubserver> heroku logs --tail
+```
@@ -0,0 +1,18 @@
+# Development and Test environment configurations are listed here
+# for convenience but generally shouldn't be used.
+#
+# Replace YOUR_APP with the heroku app name and YOUR_TOKEN with the
+# same token used in private_pub.yml of your rails project.
+
+development:
+ server: "http://localhost:9292/faye"
+ secret_token: "MY_KEY"
+
+test:
+ server: "http://localhost:9292/faye"
+ secret_token: "MY_KEY"
+
+production:
+ server: "http://MY_APP.herokuapp.com:9292/faye"
+ secret_token: "MY_KEY"
+ signature_expiration: 86400 # one day
@@ -0,0 +1,10 @@
+# Run with: rackup private_pub.ru -s thin -E production
+require "bundler/setup"
+require "yaml"
+require "faye"
+require "private_pub"
+
+Faye::WebSocket.load_adapter('thin')
+
+PrivatePub.load_config(File.expand_path("../config/private_pub.yml", __FILE__), ENV["RAILS_ENV"] || "development")
+run PrivatePub.faye_app

0 comments on commit 7bbbd84

Please sign in to comment.