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.

Tags: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *