Category Archives: Uncategorized

Add additional domain to OpenDKIM

Yet another step-by-step for my own reference.

1. Generate keys for new domain


mkdir /etc/opendkim/keys/example.com
/usr/sbin/opendkim-genkey -D /etc/opendkim/keys/example.com/ -d example.com -s default
chown -R opendkim:opendkim /etc/opendkim/keys/example.com
mv /etc/opendkim/keys/example.com/default.private /etc/opendkim/keys/example.com/default

2. Edit KeyTable

vi /etc/opendkim/KeyTable

Add new line


default._domainkey.example.com example.com:default:/etc/opendkim/keys/example.com/default

3. Add domain to SigningTable

vi /etc/opendkim/SigningTable

Add a new line:


*@example.com default._domainkey.example.com

4. Add appropriate entries to TXT records for example.com

Done

SAVEPOINT exception with Rails 3.1 on Jenkins


ActiveRecord::StatementInvalid:
SQLite3::SQLException: near "SAVEPOINT": syntax error: SAVEPOINT active_record_1

Was getting the above error, and found that I needed to upgrade CentOS default version of sqlite.  Pretty simple right?

Problems arose:

  1. CentOS packages didn’t have the newer versions.  So I couldn’t use yum update.
  2. After manually building an updated version of sqlite3 from source, Jenkins was still using the old version of sqlite.
  3. Sqlite3 is dependency on a whole bunch of other CentOS packages, so I couldn’t uninstall the default sqlite3 package.

Thanks to Stackoverflow again, all I really needed to do was manually install the sqlite rubygem pointing to the updated static libraries, as per:


bundle config build.sqlite3 \
--with-sqlite3-include=$HOME/sqlite3.7.7.1/include \
--with-sqlite3-lib=$HOME/sqlite3.7.7.1/lib \
--with-sqlite3-dir=$HOME/sqlite3.7.7.1/bin
bundle install

Filtering Rails Logs by IP

(alternate Post Title: My First Gem, please be gentle)

Filtering rails logs is like trying eat soup with a fork in space while going through a black hole.  Ok, not that bad, but it takes some work.

Why would you want to filter logs by IP?

  • Load balancers: My production boxes at work get pounded by the load balancers to make sure they are there.  All that activity fills up our rails logs with repetitive noise that’s useless.  useless.  useless.  It would be great to remove those log entries.
  • Low volume side projects: My side projects have very low volumes, but I still want them snappy and responsive when they get that 15th hit for the day at 11pm.  So I have cron jobs which hit my side project sites on a regular basis.  Again, this fills my logs with noise.

Enter Distilled

Distilled gem allows you to filter out rails logs by IP.  Its pretty easy to setup, just install the gem, and create a one line initializer to set the IP addresses.

SampleApp::Application.config.middleware.swap(

Rails::Rack::Logger,

Distilled::DistilledLogger,

:filtered_ips => ['123.456.789.1', '127.0.0.1']

)

Searching within vi

To search for the next occurence of the text ‘maybe’ from the current cursor position, type:

/maybe

Search backward from the current position by using ? instead of / in the command.

Once you have searched for something, you can find the next occurrence by pressing nor the previous occurrence with N.

Searching in vi/vim is enhanced with regular expressions. For example, to find the next occurence of the text ‘Total’ that occurs at the beginning of a line, use:

/^Total

Thanks to this source.

Create local Ruby on Rails documentation for offline use

Having your own local version of Ruby on Rails documentation has its benefits, including offline use, merged documentation for Ruby and Rails, and having docs for the exact versions that your current project uses.

Creating them is pretty simple thanks to the sdoc gem.

Create a docs directory and install sdoc

Create a home for your Ruby and Rails docs:


mkdir railsdoc
cd railsdoc

sdoc provides all the magic to generate searchable ruby docs in HTML.  So the first thing to do is to install the sdoc gem.  I use RVM, so I created its own gemspec with a .rvmrc file:


rvm use --create ruby-1.9.2-p290@railsdoc

Either way you’ll need to install sdoc.


sudo gem install sdoc

Step 1 – Download sources


git clone https://github.com/rails/rails.git
git clone https://github.com/ruby/ruby.git

Step 2a – Generate ruby docs


cd ruby

Now here you have to decide what version of ruby you want to document.  Using git, checkout the version / tag you want.  (In the following example, I switching to ruby version 1.9.2-p290)  Then have sdoc create the docs.


git co v1_9_2_290
sdoc -o doc/ruby ruby
cd ..

Step 2b – Generate rails docs

Repeat for the rails doc.  Here I’m documenting rails version 3.2.0.


cd rails
git co v3.2.0
sdoc --fmt=sdoc -g -o doc/rails -A rails
cd ..

Step 3 – Merge Rails Docs

Now that we’ve generated our ruby docs and rails docs, now its time to merge them into on directory.  sdoc provides a command to merge them.

I would change the title of the command below to reflect what versions of ruby and rails you have.


sdoc-merge --title "Ruby 1.9.2-p290 and Rails 3.2.0" --op merged --names "Ruby,Rails" doc/ruby doc/rails

Done

That’s it folks.

Point your browser to “merged/index.html” and rejoice in your merged, local, and searchable Ruby on Rails docs!

If you’re osx you can run the following to open it up:


open merged/index.html

Updating

With your railsdoc directory, you can easily update the docs by:

  • Updating the git repos (git fetch origin)
  • Checking out the new version you want to document (git co vXYZ)
  • Repeat Steps 2a, 2b and 3