December 2008
4 posts
1 tag
Monit And My Sql
Usually Monit will be happy to watch MySQL with the following configuration:
check process mysqld with pidfile "/var/run/mysqld/mysqld.pid"
group database
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if cpu > 60% for 2 cycles then alert
if cpu > 80% for 10 cycles then restart
if failed port 3306 protocol mysql then restart
If you...
1 tag
Dynamically Generated Classes
To create a class with a dynamic name in Ruby, create a new Class object and then set it as a constant within Object:
Object.const_set('ChunkyBacon', Class.new)
=> ChunkyBacon
>> ChunkyBacon.new
=> #<ChunkyBacon:0x5ef740>
You can use this to good effect with ActiveResource, creating arbitrary restful resources as you go:
Object.const_set(model,...
1 tag
Absolute Paths From Relative Paths In Bash
There doesn’t seem to be a nice, cross-platform way of deriving the absolute path from a relative one in Bash.
(`readline -f .` works in Linux, but doesn’t seem to work in OS X).
Here is a small program written in Python which does exactly that:
#!/usr/bin/env python
import os, sys
if len(sys.argv) < 2:
print 'usage: %s <PATHS>' % sys.argv[0]
raise SystemExit(1)
directory =...
1 tag
Custom 404 Pages With Passenger
On failing to match a route, Rails 2.1.2 appears to rescue the ActionController::RoutingError with its stock template (/action_controller/templates/rescues/layout.erb) and then returns an upstream 404 error code — even if you’ve defined a custom rescue_from in ActionController:
rescue_from ActionController::RoutingError, :with => :render_404
With your Mongrel/Thin and Apache/Nginx combo this...