June 17th, 2008 cschneid
I’ve previously written about deploying Sinatra to Dreamhost, both with FastCGI, and also Passenger (mod_rails). This howto will cover how to deploy Sinatra to a load-balanced reverse-proxy setup using Lighttpd and Thin.
1) Install Lighttpd and Thin
# Figure out lighttpd yourself, it should be handled by your
# linux distro's package manager
# For thin:
gem install thin
2) Create your rackup file - the “require ‘app’” line should require the actual sinatra app you have written.
require 'sinatra'
Sinatra::Application.default_options.merge!(
:run => false,
:env => :production
)
require 'app'
run Sinatra.application
3) Setup a config.yml - change the /path/to/my/app path to reflect reality.
---
environment: production
chdir: /path/to/my/app
address: 127.0.0.1
user: root
group: root
port: 4567
pid: /path/to/my/app/thin.pid
rackup: /path/to/my/app/config.ru
log: /path/to/my/app/thin.log
max_conns: 1024
timeout: 30
max_persistent_conns: 512
daemonize: true
4) Setup lighttpd.conf - change mydomain to reflect reality. Also make sure the first port here matches up with the port setting in config.yml.
$HTTP["host"] =~ "(www\.)?mydomain\.com" {
proxy.balance = "fair"
proxy.server = ("/" =>
(
( "host" => "127.0.0.1", "port" => 4567 ),
( "host" => "127.0.0.1", "port" => 4568 )
)
)
}
5) Start thin and your application . I have a rake script so I can just call “rake start” rather than typing this in. It’s just a few lines to do that.
thin -s 2 -C config.yml -R config.ru start
Go to mydomain.com/ and see the result! Everything should be setup now, check it out at the domain you setup in your lighttpd.conf file.
Variations - nginx - I haven’t looked into the config file syntax, but there isn’t any reason that this exact same approach wouldn’t work with nginx. Thin and the rackup file stay the same, while the nginx layer has to be configured to reverse proxy to the thin install.
Variations - More Thin instances - To add more thin instances, change the -s 2 parameter on the thin start command to be how ever many servers you want. Then be sure lighttpd proxies to all of them by adding more lines to the proxy statements. Then restart lighttpd and you’re done.
Posted in Linux, Programming, Ruby, Sinatra, System Admin | 1 Comment »
June 8th, 2008 cschneid
I don’t like deployment via FastCGI that much. It’s just too unstable, and random for my tastes. So when I saw that Passenger was going to support Rack, I knew I had to get that working on Dreamhost.
Once I started going at it, it only took me a few minutes to make everything work. You can find documentation at the Passenger Github repository.
Steps:
- Setup your account to support mod_rails
- Create the directory structure
- Make a rackup file (config.ru)
- Create a very simple Sinatra application
1) Setting up the account
- Domains -> Manage Domains -> Edit (web hosting column)
- Enable “Ruby on Rails Passenger (mod_rails)”
- Add the public directory to the web directory box. So if you were using “gittr.com”, it would change to “gittr.com/public”
- Save your changes
2) Creating the directory structure
domain.com/
domain.com/tmp
domain.com/public
# a vendored version of sinatra - not necessary if you use the gem
domain.com/sinatra
3) Creating a rackup file
# This file goes in domain.com/config.ru
require 'sinatra/lib/sinatra.rb'
require 'rubygems'
Sinatra::Application.default_options.merge!(
:run => false,
:env => :production
)
require 'test.rb'
run Sinatra.application
4) A very simple Sinatra application
# this is test.rb referred to above
get '/' do
"Worked on dreamhost"
end
get '/foo/:bar' do
"You asked for foo/#{params[:bar]}"
end
And that’s all there is to it! Once it’s all setup, point your browser at your domain, and you should see a “Worked on Dreamhost” page. To restart the application after making changes, you need to run “touch tmp/restart.txt”.
Posted in Programming, Ruby, Sinatra, System Admin | 14 Comments »
May 3rd, 2008 cschneid
I hate cmd.exe. Not the shell itself, it’s not that horrible (although nowhere near what bash is), but the tiny un-resizeable window is horrible. The rectangular copy… wtf.
So there seem to be a few options for alternative consoles, but of course, Vista 64 sucks hard enough in the compatability area that there isn’t a single good solution.
Console2 -The error case on this one is weird. It starts the internal shell up just fine, but due to a Vista drawing issue, it doesn’t actually draw text to the screen. The bug (feature?) is limited to 64 bit versions of windows, and looks like it hits XP64 as well. Either way, if you can’t see what you’re typing, or the response, the terminal isn’t very useful.
PuttyCyg - again, doesn’t work on Vista 64. I went into it a while back, and it just couldn’t hook up to the cygwin install I had (default everything…). Never did get much more in depth than that.
Ponderosa - Hey, something that works! Nice tabbed interface, and runs the cygwin shell just fine. Downsides: doesn’t run the cmd.exe shell by default (you can run cygwin’s bash shell, then type “cmd.exe” and it’ll run it).
So now I have a working shell window in Windows that doesn’t suck. Woot.
Posted in System Admin, Windows | No Comments »
April 29th, 2008 cschneid
Since I’m using Slicehost for my VPS hosting, and I’m cheap, I only have 256 megs of ram to work with. I run lighttpd, which then forces me to use php-cgi (via fastcgi) as the php executable. All of this is then running on Gentoo.
Anyway, what I’m getting to is how to setup PECL-APC (php accelerator / bytecode cache) on this platform.
Turns out all the scary messages in FAQs saying APC doesn’t work with CGI interfaces don’t apply to the fast-cgi implementation that Lighttpd uses.
emerge -uDv php5/pecl-apc
And then you’re done.
Hopefully my rambling was enough to get you going. To tweak, go check out /etc/php/php5-cgi/ext/apc.ini
Also, to verify this whole thing, you need a phpinfo() page… like:
<?php phpinfo(); ?>
Posted in Linux, System Admin | No Comments »