Why you need to manage Ruby sessions

Huston, we have a problem…

$ cd tmp/sessions/
$ rm *
-bash: /bin/rm: Argument list too long

Opening up mc and deleting by hand helped. There were 22507 session files taking up about 1.7MB of space. I suppose it’s time to look at other session storing methods.

9 Responses to “Why you need to manage Ruby sessions”

  1. Luke Says:

    Are Ruby sessions similar to PHP sessions? And if yes, doesn’t rails have a mechanism for purging old and expired sessions?

    Did you try:

    rm -f tmp/sessions
    mkdir tmp/sessions

    This way you avoid the argument expansion thing, I think. To tell you the truth I actually never had that issue in bash.

  2. Luke Says:

    Also, in worst case, you can always set up a cronjob to purge that directory every day/week/month (whichever seems appropriate).

  3. Paul Goscicki Says:

    Yea, I know all that (apart from the rm -f idea). This post was supposed to be a joke .)

  4. Luke Says:

    Ah, ok. Got it. :)

  5. Dayne Says:

    Or you can use the handy find command (helpful if you put in a cronjob)
    # find sessions older than a week and toast them
    find tmp/sessions -atime +7 -exec rm {} \;
    # to see what it would delete w/o deleting it:
    find tmp/sessions -atime +7 -exec echo {} \;

    turn that into a script and put into your crontab to run nightly at 3am
    0 3 * * * /home/user/rails/cleanup_sessions.sh

  6. trench Says:

    Paul, noticed you watched Flags of our Fathers. Just to let you know, Letters from IWO JIMA was awesome.

  7. Paul Goscicki Says:

    Yeah, that’s what I’ve figured out judging by the awards alone. I really can’t wait to see it! :)

  8. Evan Says:

    rake tmp:sessions:clear

  9. Paul Goscicki Says:

    Evan: Oh, believe me, I know. It seems that you just did not get the joke. But don’t worry, you are not alone. Apparently I must work more on my comedy skills .)

Leave a Reply