Back Issues

About a week and a half ago, I pulled a muscle in my back. I don’t know exactly what I did, but I do remember that I was putting on a sock. I don’t remember doing anything odd, but I do remember the sharp pain. I thought it might be something bad, but I proceeded through the day as usual. I had this same injury (though much worse) about 15 years ago, if not more. At that point, it hurt so badly that I had a hard time standing up. Now, I’m pretty much ok if I keep my back bent a little, but it hurts quite a bit when trying to straighten it. This leads to the odd situation where riding my bike feels really good, but going for a walk can be painful.

Based on my previous experience, I know that this just takes time to heal. I don’t believe I did any structural damage because it was no big deal when it happened. I’m not going to the doctor (yet) because when I went last time, I basically remember that I was told it just takes time…maybe two to six weeks.

Now I’m just trying to be patient. Normally I am a pretty patient person, but when I’m in pain that sort of goes out the window. I have been doing stretching exercises regularly because I know that’s a good thing. Lying in bed all day is not. And I keep repeating “patience, patience, patience” to myself. I haven’t gone to work the past two days simply because it’s more comfortable working while lying on the floor. And, quite frankly, it’s awkward lying on the floor in my office as it’s not totally private.

Why am I writing this? No idea. Maybe it’s just to warn people who think I’m being more of a bitch than usual that the pain is part of the problem. Maybe to empathize with people who have chronic pain. I know this will pass (patience, patience, patience). Or maybe just to pass the time. Who knows?

Ah, now I remember. In the event this ever happens again, I want to remember what helped and did not. First, don’t use a heating pad, use ice. It feels better. Avoid Ben Gay or anything like that at all costs. Get out the exercise ball and roll around on it as much as possible, both on your stomach and if you can, on your back. Don’t think getting drunk will help you to relax. You’ll still be in pain and have the added benefit of being nauseous as well. Try not to sit or lay in one position for long periods of time. It’s uncomfortable, but try to change positions every 20-30 minutes. Stretch a lot as soon as you get up.


Went for a nice bike ride this morning because it’s lovely out. Decided to ride to the bank to deposit a check and then take a ride along the lakefront. Did about 13 miles and felt pretty good. I just noticed on my Cyclemeter app that it tells me how many miles I biked overall last year. It’s close but I know that I don’t always remember to turn it on and I only got the app in April. So it’s probably a bit low. Anyway it says I rode 1131 miles last year. So far this year, I’ve ridden 102 miles. That’s pretty good. I didn’t think that I already rode that much this year. I think I now have a goal for the year. I need to do more than 1131 miles.

Production Gems

I’m not sure how I didn’t notice this before, but my deployment on an app was suddenly taking much longer that it had in the past. While I was watching it run, I noticed that when bundle install was running, it was saying installing each gem. I don’t know why I didn’t notice this before. I looked on my server and noticed that each release was about 177mb in size and the vendor/bundle directory was 173mb in size. I was reading the Bundler website when I saw this bit:

“If you use Capistrano, you should symlink vendor/bundle to shared/vendor_bundle so that bundler will share your installed gems between deployments (making things zippy if you didn’t make any changes), but still give you the benefits of isolation from other applications.”

As soon as I read that, I thought why was I never doing this? So I quickly copied all the gems to a shared directory and wrote a new capistrano task. I then did another deploy and it complete in less than a minute. Crazy that I didn’t notice this before. And just goes to show that I still have a lot to learn about Rails.

Lots to Learn about Assets

I upgraded a new app to use Rails 4.2 and bootstrap and I thought things were fine. However, when I went to the page today, css wasn’t working. It just never created the css files. Turns out that I needed to add the ‘sprockets-rails’ gem to my Gemfile because the asset pipeline is no longer a feature of rails 4. Once I ran bundle and commit this change to the repo, I could deploy and things worked fine.

Still Learning About Rails and Deployment

I had been feeling pretty good about my Rails skills and had been able to create and deploy a number of simple applications. Since simple applications are just about all I’m going to write, I was ok with things. But I was hanging on to earlier versions of things and it was starting to bug me. One big one was the capistrano gem. I knew there were big changes between version 2 and 3, and I had a pretty good setup using version 2. However, I know that things constantly change so I decided to dive in and start using capistrano version 3, 3.4.0 to be exact.

The first thing I found out is that version 3 is all about multistage deployment, where first you’d go to a staging server and then your production server. I’m fairly confident that this is something that I’m never going to do. I just don’t work on systems that require that much uptime. And my things are pretty simple, so there’s really no need for a staging server.

The other thing is that it’s really different from version 2. Very little from my old setup was going to be transferable to the new version. The good news is that I had a pretty good understanding of what needed to be done. The bad news was that I really didn’t have any idea of how to do some of it. So, in no particular order, here are some of the things I learned. This is going to be a long post, but I wanted to get my notes down someplace.

To get started, instead of running capify ., you run cap install.

$ cap install
mkdir -p config/deploy
create config/deploy.rb
create config/deploy/staging.rb
create config/deploy/production.rb
mkdir -p lib/capistrano/tasks
create Capfile

I never used to edit the old Capfile, but now I do.

# Load DSL and set up stages
require 'capistrano/setup'

# Include default deployment tasks
require 'capistrano/deploy'

# Include tasks from other gems included in your Gemfile
# For documentation on these, see for example:
# require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'  --uncommented
require 'capistrano/rails/assets'  --uncommented
# require 'capistrano/rails/migrations'
require 'capistrano/passenger'   --uncommented

# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

Here by uncommenting require ‘capistrano/bundler’, when you run cap deploy, the bundle install command will automatically run. So I no longer had to write a task for that.

The require ‘capistrano/passenger’ line automatically adds a deploy:restart command to the deployment. Another task I no longer need.

Require ‘capistrano/rails/assets’ gives the tasks:
cap deploy:cleanup_assets
cap deploy:compile_assets
cap deploy:normalize_assets
cap deploy:rollback_assets

Here compile_assets is the task that I’d mainly use.

I didn’t uncomment the migrations line because I like to run those manually. I don’t change the database that often, so when I do I’m pretty careful about it.

Since I only have a single server, it’s just production. I had to edit the file config/deploy/production.rb. The example file that was created was much longer than what I needed. Here is all that I ended up with in mine:

set :user, ENV["USER"]
server '', user: fetch(:user), roles: %w{web app db}, primary: true

Here you can see one of the new things in capistrano 3. To get the variable user, you have to use the fetch command.

Once those files are ready to go, now I could start working on the basic deploy.rb file. With capistrano 2, I tried to set up my deployments to always use the same commands where all I had to change was the name of the application to have things set. So I want to do the same thing here. Here’s what I ended up with.

# config valid only for current version of Capistrano
lock '3.4.0'

set :application, "high-school-registration"
set :repo_url, "put the repo location here"

# Need this to upload special files
set :local_home, "/Users/candh/Documents/ruby/#{fetch(:application)}"

set :deploy_to, "/local/data1/web/app/#{fetch(:application)}"
set :scm, :git
set :pty, true
set :linked_files, %w{config/database.yml config/secrets.yml}
set :linked_dirs, %w{public/system}

namespace :setup do 
  desc "Upload files not in repo"
  task :upload_files do 
    on roles(:all) do |host|
      execute :mkdir, "-p", ("#{shared_path}" + "/config")
      execute :mkdir, "-p", ("#{shared_path}" + "/system")
      upload! "#{fetch(:local_home)}/config/database.yml", "#{shared_path}/config/database.yml"
      upload! "#{fetch(:local_home)}/config/secrets.yml", "#{shared_path}/config/secrets.yml"

namespace :deploy do
  namespace :web do
    desc 'Disable server'
    task :disable do
      on roles(:all) do |host|
        template ="#{fetch(:local_home)}/config/deploy/templates/maintenance.html.erb")).result(binding)
        upload!, "#{release_path}/public/system/maintenance.html"
        execute :chmod, "644", "#{release_path}/public/system/maintenance.html"

    desc 'Enable server'
      task :enable do
        on roles(:all) do |host|
          execute :rm, "#{release_path}/public/system/maintenance.html"

	after :restart, :clear_cache do
	  on roles(:web), in: :groups, limit: 3, wait: 10 do
	    # Here we can do anything such as:
	    # within release_path do
	    #   execute :rake, 'cache:clear'
	    # end


There’s a lot going on in this file. Since ALL of my rails apps are in my ~/Documents/ruby directory, I like to set the variable application with the name of the app. I then use this same name for the repo on github and the location for the final deployment. Local_home is a new variable that I set because I couldn’t find anything in capistrano 3 that gave me the local Rails.root. By setting this, I can run my tasks that upload certain files (like database.yml and secrets.yml) that aren’t in my repo. It’s also used in my disable/enable tasks.

The linked_files and linked_dirs variables are ones that are automatically linked to the original files in shared. So this is another task that I didn’t have to write. Note though that you will get an error if you run deploy without having your own copies of those files/directories already present.

That’s basically it. The other big change is that you have to tell the cap program which stage you’re running on. So all of my old cap whatever commands are now cap production whatever commands. I haven’t found a way to just default to production always.

$ cap production deploy:check  (makes required directories)
$ cap production setup:upload_files (puts my files on in the repo on the server and makes some other directories)
$ cap production deploy

At this point, I’d then log onto the server and run my migration and seed the database manually. Then, as things change the sequence of commands would be:

$ cap production deploy:web:disable
$ cap production deploy
$ cap production deploy:web:enable

That basically copies my capistrano 2 workflow to capistrano 3. I still wonder if I should just go back to capistrano 2, since I only have the one stage. But, at least, I’ve figured out how to do it.

A Splendid Torch

This is the true joy of life, the being used up for a purpose recognized by yourself as a mighty one; being a force of nature instead of a feverish, selfish little clod of ailments and grievances, complaining that the world will not devote itself to making you happy.

I am of the opinion that my life belongs to the community, and as long as I live, it is my privilege to do for it whatever I can. I want to be thoroughly used up when I die, for the harder I work, the more I live. Life is no ‘brief candle’ to me. It is a sort of splendid torch which I have got hold of for a moment, and I want to make it burn as brightly as possible before handing it on to future generations.

–George Bernard Shaw

Spring is Coming

I don’t know if it’s because I’m getting older or if we had a particularly snowy winter, but I cannot wait for spring to come. Today makes me happy because spring training starts and I can watch a game on tv and see the outdoors not covered in snow. Something that makes me even happier is that today signups open for 30 Days of Biking. This is a group that asks people to pledge to ride their bike every day in April. That’s it. The idea is that if you ride every day at the start of biking season, you’ll be more inclined to think to use the bike for small errands and things during the rest of the summer. It’s brilliant in its simplicity. It doesn’t cost a thing. The idea is just to get you out biking. And as an added bonus, they’ll donate a bike to a kid in need for every 30 riders who sign up. I did it last year with my sister and a friend and it was fun. On the day that we spent 15 hours in the car on the way back from Boston, I did have to borrow my nephew’s bike at 10:30pm to ride to the corner, but I’m happy to say that I rode every day. And it’s a great reason to get together a group and go for a group ride. So I just pledged again this morning and am looking forward to it. I’ve already ridden a bit this winter, but spring riding is so much more fun. So if anyone else wants to pledge, I say go for it! And if you’re looking for someone to go for a ride with in April (or quite frankly anytime), let me know. I’m in!