Archive for the 'ar_mailer' Category
Now that GitHub has a gem server it allows the process of managing your own fork or customisation of a gem ridiculously easy. No need for your own gem server or shipping around gem files, just put it up on github and nominate it as a gem in the project config. GitHub will automatically compile the gems using a gemspec file if present. All the info you need is here so I won’t recap it any further.
A gem which I find essential for Rails apps which send out emails is ar_mailer by Eric Hodel of Seattle Ruby Brigade and Ruby Hitsquad fame and now the maintainer of RubyGems. But there a couple of things missing. One is the need for pid files to be generated when running as a daemon to allow effective management with monitoring tools and such.
Well there just so happened to be a patch by Dylan Egan in the ar_mailer forums to add this feature, but it has been overlooked for a long time. So I thought this would be a good chance to fork it and use the GitHub gem system as well. Its now forked it and patched with some tweaks to get it working and a few fixes for the tests which broke due to changes in the latest ZenTest gem.
The project for the gem is here. To use the new gem you need to remove the old one because of the way github names your gems. It uses github username as a prefix to the gem name. This means the old gem will be loaded instead of the new gem when required in your app. But the binary will be used from the new gem causing nasty problems.
To install, first add GitHub as a gem source
sudo gem sources -a http://gems.github.com
sudo gem install adzap-ar_mailer
Now when the binary is run in daemon mode you will get the pid file you need. You can specify the pid file location in the command options like so
ar_sendmail -d -p ./log/ar_sendmail.pid
Any relative paths are expanded from the app directory. You can of course use an absolute path if you wish. The file gets removed on exit as you would expect.
The other major addition is not as visible. Its a Ruby based init.d script for managing mailer startup for one or more apps. It uses a yaml based config file where you specify the app settings for each app that needs a mailer instance running. See the README and demo config for more info.
Ruby, my hammer, is starting to make everything look a nail!
Remember this is GitHub, don’t like what I have done, then fork off!
If you are getting an error running the ar_sendmail binary, this is due to GitHub to setting the permission on gem binary files incorrectly. The error would be
/usr/bin/ar_sendmail:19:in `load': no such file to load -- ar_sendmail (LoadError) from /usr/bin/ar_sendmail:19
To fix it you need to run this ugly (please let me know a better way to get a gem path!!)
GEMS_PATH=`gem env path` GEM_NAME='adzap-ar_mailer' sudo chmod 755 $GEMS_PATH/gems/$GEM_NAME*/bin/*
Now you should be able to execute it as a normal user.
Fixed the update fix and made it version non-specific
GitHub fixed the file permissions issue so the work around is not needed anymore.