Commit 299c850a authored by Nigel McNie's avatar Nigel McNie
Browse files

Implement a cron job to delete old session files. Fixes #570.

We haven't been clearing out session files since I first chose to make us hash the session directory back in 2006. Talk about a timebomb...

The cron job uses `find' and `xargs' to do the removing. These tools are required on debian (as part of findutils), and are installed in /usr/bin. I haven't bothered with a configuration directive for specifying a path to them for now, but that might be necessary later.
(cherry picked from commit 335d66a7)
parent 7c7ed40b
......@@ -1340,6 +1340,19 @@ function auth_handle_account_expiries() {
}
/**
* Clears out old session files
*
* This should be run once every now and then (once a day is good), to clean
* out session files of users whose sessions have timed out.
*/
function auth_remove_old_session_files() {
// Note: read the manpage for find and xargs to understand what is going on
// here. In particular, -mtime +1 means files older than about two days
// will be removed
exec('find ' . escapeshellarg(get_config('dataroot') . 'sessions') . ' -type f -mtime +1 | xargs -n 1000 -r rm');
}
function auth_generate_login_form() {
if (!get_config('installed')) {
return;
......
......@@ -965,6 +965,17 @@ function xmldb_core_upgrade($oldversion=0) {
// large degree of protection, but when MySQL finally supports this
// we will be able to add it
}
// Install a cron job to delete old session files
$cron = new StdClass;
$cron->callfunction = 'auth_remove_old_session_files';
$cron->minute = '30';
$cron->hour = '20';
$cron->day = '*';
$cron->month = '*';
$cron->dayofweek = '*';
insert_record('cron', $cron);
}
return $status;
......
......@@ -688,6 +688,7 @@ function core_install_firstcoredata_defaults() {
'auth_clean_partial_registrations' => array('5', '0', '*', '*', '*'),
'auth_handle_account_expiries' => array('5', '10', '*', '*', '*'),
'activity_process_queue' => array('*/5', '*', '*', '*', '*'),
'auth_remove_old_session_files' => array('30', '20', '*', '*', '*'),
);
foreach ($cronjobs as $callfunction => $times) {
$cron = new StdClass;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment