Archive | ruby

Finally, Resque & Supervisor have learned to get along!

Truly, they have so much to teach us all

holy confetti!

Like I said in my short “Daemon-ize your processes on the cheap” series, Resque was the tool that had given me the most grief when using Supervisor. No more!

How did I work such sorcery, you ask? Follow my 3-step formula for guaranteed success:

  1. Use the Resque 2.0.0 prerelease or newer.
  2. Use Supervisor 3.0.0 or newer.
  3. In the Supervisor config for your Resque workers, make sure you set:
    • an environment variable for HOME
    • an environment variable for PATH
    • a directory for Supervisor to cd to and run your worker from

To illustrate my point, here’s a cut-down example of my WORKING RESQUE CONFIG FOR SUPERVISOR! YAY! HOORAY! HUZZAH!

; Save this into your /etc/supervisor.d directory, build an awesome-app
; and wire this up to your totally_awesome worker. Watch MAGIC happen.
[program:awesome-worker]
command=/usr/bin/bundle exec resque work -q default -r ./app/workers/totally_awesome.rb
autostart=true
autorestart=true
stopsignal=QUIT
stdout_logfile=/var/log/supervisor/awesome-worker_stdout.log
stderr_logfile=/var/log/supervisor/awesome-worker_stderr.log
user=awesome
directory=/srv/applications/awesome-app
environment=PATH='/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin',HOME='/home/awesome'
view raw

But seriously, all confetti aside, so, so many thanks to the Resque team. Their work picking up the code base and running with it has really, really paid off. A big round of applause to everyone who contributed to improving Resque.

Arkham Party!

Literary beta testing: Build Awesome Command-Line Applications in Ruby

David Copeland (@davetron5000), author of GLI (Git-like Interface Command Parser) has written a book called Build Awesome Command-Line Applications in Ruby. I’ve been beta-testing the book while it was going through the publishing process, and it is excellent. Of note: it focuses on writing command suites (like the rails command or git) and stand-alone command-line applications (like rsync).

Build Awesome Command-Line Applications in Ruby

So like I mentioned up there, I initially grabbed the book around its second or third beta release, figuring that while it was still in the process of becoming a Real Book I sometimes feel like I’m still in the process of becoming a Real Admin so, you know, what the hell, let’s work through it together.

I know a number of developers who only know Ruby in the context of the Rails framework (and maybe related Rake tasks) and this book is an exceptional guide to using Ruby for more than just Rails applications. Command-line tooling has long been an area of interest for me as working in operations means often having to perform a number of repetitive tasks which lend themselves well to being scripted; good admins write good scripts. More stray observations after the jump →.