Cleaning up stale rails sessions (removing ruby_sess files)

I’m not sure if something isn’t set up correctly of if this is just a fact of life with rails but the sessions it creates never seem to go away. I think before rails 1.1 the sessions where stored in /tmp and now they are stored in the apps directory along with everything else so they is probably no internal mechanism to delete them. I only noticed because after about a month of an certain app running the disk on the machine started to fill up. After digging a little I found 50K ruby_sess.* files hanging out in the rails session directory.

Anyway it was easy enough to clean up the stale ruby_sess files by going into the rails webapp/session directory and then running the following command:

find -type f -name "ruby_sess*" -exec rm -f {} \\;

I’m not sure why the app is creating sessions but it isn’t something that stores state so I didn’t have to worry about killing active sessions here. If you do need to worry about that you will probably want to toss a time on the find command.

After looking a little more I found a post about this that has a ruby way of cleaning up the sessions.

del.icio.us:Cleaning up stale rails sessions (removing ruby_sess files) digg:Cleaning up stale rails sessions (removing ruby_sess files) spurl:Cleaning up stale rails sessions (removing ruby_sess files) wists:Cleaning up stale rails sessions (removing ruby_sess files) simpy:Cleaning up stale rails sessions (removing ruby_sess files) newsvine:Cleaning up stale rails sessions (removing ruby_sess files) blinklist:Cleaning up stale rails sessions (removing ruby_sess files) furl:Cleaning up stale rails sessions (removing ruby_sess files) reddit:Cleaning up stale rails sessions (removing ruby_sess files) fark:Cleaning up stale rails sessions (removing ruby_sess files) blogmarks:Cleaning up stale rails sessions (removing ruby_sess files) Y!:Cleaning up stale rails sessions (removing ruby_sess files) smarking:Cleaning up stale rails sessions (removing ruby_sess files) magnolia:Cleaning up stale rails sessions (removing ruby_sess files) segnalo:Cleaning up stale rails sessions (removing ruby_sess files) gifttagging:Cleaning up stale rails sessions (removing ruby_sess files)

One Response to “Cleaning up stale rails sessions (removing ruby_sess files)”

  1. Mission Data Blog » Blog Archive » Cleaning Up Rails Sessions, Revisited Says:

    […] In an earlier post, we detailed a method for removing stale Rails session files. In more recent version of Rails, there is a Rake task built in for this administration task. […]

Leave a Reply