Steve Klabnik changelog.com/posts

BDSM: Yes, Bash is a Real Programming Language

Wayne Seguin is the only Rubyist I know that’s not really known for writing Ruby. When writing RVM, Wayne built it in Bash shell scripts, and as it grew, it got big and unwieldy. Wayne, being the kind of person he is, decided to make Bash more respectable rather than just move to a better language.

Hence BDSM. It stands for “Badass Delectable Scripting Modules”, and that’s what it does: gives you some great tools for writing larger programs in Bash script. The first thing that it’s been applied to has been deployments. You can use BDSM to set up your application’s environment in the same way that you can use RVM to set up your Ruby environment.

Check it out, here’s an example from the RVM deployments page:

appuser$ bdsm bdsmrc      # Put a default ~/.bdsmrc in place.
appuser$ vim ~/.bdsmrc     # Update settings, specifically repository_url, etc...
appuser$ bdsm rails setup # This sets up ~/shared path etc
appuser$ bdsm deploy      # Updates ~/current with a fresh release.
appuser$ vim ~/shared/config/database.yml # setup your db connection info.
appuser$ cd ~/current
appuser$ gem install bundler && bundle install # Be sure that 'gem "unicorn"' is in Gemfile first, no version.
appuser$ bdsm unicorn start
root# bdsm nginx package install
root# chmod go+rx /home/appuser # This makes sure that Nginx can read the dir.
root# bdsm nginx service appuser # This creates /etc/nginx/servers/appuser.conf configured for a unicorn UDS proxy by default.
root# bdsm nginx service start

You can follow along with the comments, but that gets you set up with a system ready to deploy Rails apps. When you have a second app on the same box, you make a new user, and do the first half again.

I’ve done this with two small apps on a VPS, and it’s really awesome. It gives me 90% of the feel of Heroku, but for only $15/month. Heh. Here’s what I did: Since the deployed apps are stored in /home/appuser/current, I make a /home/appuser/code, and that holds the git repo. I set that up as ‘production’ in git, and add a post-commit hook that automatically, runs bdsm deploy && bdsm unicorn restart, and now, ever time I git push production, my site just redeploys. And it’s totally separate from the other app on the server.

Really, all of this is enabled by having these modules provide a common interface to each package. “bdsm unicorn restart” is the same as “bdsm nginx restart”, which makes it really easy to get up and going, start using a different package, etc. It’s all great stuff.

Anyway, this is a tiny little overview of what BDSM can do right now. Wayne’s got big plans for the future, so keep an eye on this cool little project.

[Github] [Website] [README]


Discussion

Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00