diff options
-rwxr-xr-x | config/squid3/33/squid.inc | 27 | ||||
-rwxr-xr-x | config/squid3/33/squid_cache.xml | 9 | ||||
-rw-r--r-- | config/squid3/33/swapstate_check.php | 8 |
3 files changed, 31 insertions, 13 deletions
diff --git a/config/squid3/33/squid.inc b/config/squid3/33/squid.inc index e6312d91..0c3b4d7e 100755 --- a/config/squid3/33/squid.inc +++ b/config/squid3/33/squid.inc @@ -105,7 +105,7 @@ function squid_check_clamav_user($user) } /* setup cache */ -function squid_dash_z() { +function squid_dash_z($cache_action='none') { global $config; //Do nothing if there is no cache config @@ -119,7 +119,12 @@ function squid_dash_z() { return; $cachedir =($settings['harddisk_cache_location'] ? $settings['harddisk_cache_location'] : '/var/squid/cache'); - + + if ($cache_action=="clean"){ + rename ($cachedir,"{$cachedir}.old"); + mwexec_bg("/bin/rm -rf {$cachedir}.old"); + } + if(!is_dir($cachedir.'/')) { log_error("Creating Squid cache dir $cachedir"); make_dirs($cachedir); @@ -363,9 +368,9 @@ function squid_deinstall_command() { $settings = array(); $cachedir =($settings['harddisk_cache_location'] ? $settings['harddisk_cache_location'] : '/var/squid/cache'); $logdir = ($settings['log_dir'] ? $settings['log_dir'] : '/var/squid/logs'); - update_status("Removing swap.state ... One moment please..."); + update_status("Removing cache ... One moment please..."); update_output_window("$plswait_txt"); - mwexec('rm -rf $cachedir/swap.state'); + mwexec_bg('rm -rf $cachedir'); mwexec('rm -rf $logdir'); update_status("Finishing package cleanup."); mwexec("/usr/local/etc/rc.d/sqp_monitor.sh stop"); @@ -730,19 +735,26 @@ function squid_install_cron($should_install) { $x=0; $rotate_job_id=-1; $swapstate_job_id=-1; + $cron_cmd=($settings['clear_cache']=='on' ? "/usr/local/pkg/swapstate_check.php clean; " : ""); + $cron_cmd .= SQUID_LOCALBASE."/sbin/squid -k rotate -f " . SQUID_CONFFILE; + $need_write = false; foreach($config['cron']['item'] as $item) { if(strstr($item['task_name'], "squid_rotate_logs")) { $rotate_job_id = $x; + if ($item['command'] != $cron_cmd){ + $config['cron']['item'][$x]['command']=$cron_cmd; + $need_write = true; + } } elseif(strstr($item['task_name'], "squid_check_swapstate")) { $swapstate_job_id = $x; } $x++; } - $need_write = false; switch($should_install) { case true: $cachedir =($settings['harddisk_cache_location'] ? $settings['harddisk_cache_location'] : '/var/squid/cache'); if($rotate_job_id < 0) { + $cron_item['command']=($settings['clear_cache']=='on' ? "/usr/local/pkg/swapstate_check.php clean; " : ""); $cron_item = array(); $cron_item['task_name'] = "squid_rotate_logs"; $cron_item['minute'] = "0"; @@ -751,7 +763,7 @@ function squid_install_cron($should_install) { $cron_item['month'] = "*"; $cron_item['wday'] = "*"; $cron_item['who'] = "root"; - $cron_item['command'] = "/bin/rm {$cachedir}/swap.state; ". SQUID_LOCALBASE."/sbin/squid -k rotate -f " . SQUID_CONFFILE; + $cron_item['command'] .= $cron_cmd; /* Add this cron_item as a new entry at the end of the item array. */ $config['cron']['item'][] = $cron_item; $need_write = true; @@ -967,10 +979,9 @@ pinger_program {$pinger_program} EOD; // Per squid docs, setting logfile_rotate to 0 is safe and causes a simple close/reopen. -// Rotating also ensures that swap.state is rewritten, so is useful even if the logs -// are not being rotated. $rotate = empty($settings['log_rotate']) ? 0 : $settings['log_rotate']; $conf .= "logfile_rotate {$rotate}\n"; +$conf .= "debug_options rotate={$rotate}\n"; squid_install_cron(true); $conf .= <<< EOD diff --git a/config/squid3/33/squid_cache.xml b/config/squid3/33/squid_cache.xml index a1682eaa..f60863c9 100755 --- a/config/squid3/33/squid_cache.xml +++ b/config/squid3/33/squid_cache.xml @@ -179,7 +179,14 @@ <option><name>diskd</name><value>diskd</value></option> <option><name>null</name><value>null</value></option> </options> - </field> + </field> + <field> + <fielddescr>Clear cache on log rotate</fielddescr> + <fieldname>clear_cache</fieldname> + <description><![CDATA[If set, Squid will clear cache and swap.state on every log rotate.<br> + This action will be executed automatically if the swap.state file is taking up more than 75% disk space,or the drive is 90%]]></description> + <type>checkbox</type> + </field> <field> <fielddescr>Level 1 subdirectories</fielddescr> <fieldname>level1_subdirs</fieldname> diff --git a/config/squid3/33/swapstate_check.php b/config/squid3/33/swapstate_check.php index 6ecfff3c..a0b3c98b 100644 --- a/config/squid3/33/swapstate_check.php +++ b/config/squid3/33/swapstate_check.php @@ -28,6 +28,7 @@ */ require_once('config.inc'); require_once('util.inc'); +require_once('squid.inc'); $pf_version=substr(trim(file_get_contents("/etc/version")),0,3); if ($pf_version > 2.0) @@ -46,13 +47,12 @@ if ($settings['harddisk_cache_system'] != "null"){ $diskusedpct = round((($disktotal - $diskfree) / $disktotal) * 100); $swapstate_size = filesize($swapstate); $swapstate_pct = round(($swapstate_size / $disktotal) * 100); - // If the swap.state file is taking up more than 75% disk space, // or the drive is 90% full and swap.state is larger than 1GB, // kill it and initiate a rotate to write a fresh copy. - if (($swapstate_pct > 75) || (($diskusedpct > 90) && ($swapstate_size > 1024*1024*1024))) { - mwexec_bg("/bin/rm $swapstate; ". SQUID_LOCALBASE . "/sbin/squid -k rotate"); - log_error(gettext(sprintf("Squid swap.state file exceeded size limits. Removing and rotating. File was %d bytes, %d%% of total disk space.", $swapstate_size, $swapstate_pct))); + if (($swapstate_pct > 75) || (($diskusedpct > 90) && ($swapstate_size > 1024*1024*1024)) || $argv[1]=="clean") { + squid_dash_z('clean'); + log_error(gettext(sprintf("Squid cache and/or swap.state exceeded size limits. Removing and rotating. File was %d bytes, %d%% of total disk space.", $swapstate_size, $swapstate_pct))); } } ?>
\ No newline at end of file |