27 February 2007

Clearing Out Rails file-bases Sessions with cron

Adapted from Agile Web Development on Rails:
The session handler in Rails doesn’t do automated housekeeping. This means that once the data for a session is created, it isn’t automatically cleared out after the session expires. This can quickly spell trouble. The default file-based session handler will run into trouble long before the database-based session handler will, but both handlers will create an endless amount of data. Since Rails doesn’t clean up after itself, you’ll need to do it yourself. The easiest way is to run a script periodically, you could put the following command into a script
that will delete files that haven’t been touched in the last 1 hour every morning at 4am.

In the bash, run the command:
crontab -e

You'll enter a command line editor vi like, type "I" and copy-paste the following command:
0 4 * * * cd ~/YOUR_RAILS_APPS_HOME_FOLDER_HERE/; find tmp/sessions -name 'ruby_sess.*' -amin +60 -exec rm -rf {} \;

To save, type ESC, then wq in order to save the file and quit.

As far as I am concerned, I can't stand these command line software which don't give a clue about how to use them. I am sooooo looking forward a rebirth of some Pao Alto 70 spirit in the domain of User Interface: I want to see 3D, vocal commands, predictive User Interfaces !!! Damn the Monopoles!!!!

No comments: