3 # Initialize the cache by running squid with the -z option
5 require './squid-lib.pl';
6 $access{'rebuild'} || &error($text{'icache_ecannot'});
8 $whatfailed = $text{'icache_ftic'};
10 # set user to run squid as..
11 &lock_file($config{'squid_conf'});
12 $conf = &get_config();
14 $in{'user'} || &error($text{'icache_ymcautrsa'});
15 @uinfo = getpwnam($in{'user'});
16 scalar(@uinfo) || &error($text{'icache_euser'});
17 @ginfo = getgrgid($uinfo[3]);
18 if ($squid_version < 2) {
19 $dir = { 'name' => 'cache_effective_user',
20 'values' => [ $in{'user'}, $ginfo[0] ] };
21 &save_directive($conf, "cache_effective_user", [ $dir ]);
24 $dir = { 'name' => 'cache_effective_user',
25 'values' => [ $in{'user'} ] };
26 &save_directive($conf, "cache_effective_user", [ $dir ]);
27 $dir = { 'name' => 'cache_effective_group',
28 'values' => [ $ginfo[0] ] };
29 &save_directive($conf, "cache_effective_group", [ $dir ]);
33 &unlock_file($config{'squid_conf'});
35 # Stop squid (if running)
36 &ui_print_unbuffered_header(undef, $text{'icache_title'}, "");
37 if ($pidstruct = &find_config("pid_filename", $conf)) {
38 $pidfile = $pidstruct->{'values'}->[0];
40 else { $pidfile = $config{'pid_file'}; }
41 if (open(PID, $pidfile)) {
42 <PID> =~ /(\d+)/; $pid = $1;
45 if ($pid && kill(0, $pid)) {
46 print "<p>$text{'clear_stop'}<br>\n";
47 &system_logged("$config{'squid_path'} -f $config{'squid_conf'} ".
48 "-k shutdown >/dev/null 2>&1");
49 for($i=0; $i<40; $i++) {
50 if (!kill(0, $pid)) { last; }
53 print "$text{'clear_done'}<br>\n";
57 # Initialize the cache
58 ($user, $group) = &get_squid_user($conf);
60 foreach $c (split(/\s+/, $in{'caches'})) {
64 &chown_files($user, $group, $conf);
65 $cmd = "$config{'squid_path'} -f $config{'squid_conf'} -z";
66 print "<p>", &text('icache_itscwtc',$cmd), "<br>\n";
68 &additional_log('exec', undef, $cmd);
69 open(INIT, "$cmd 2>&1 |");
76 # Try to re-start squid (if it was running before)
79 &system_logged("$config{'squid_path'} -sY -f $config{'squid_conf'} >$temp 2>&1 </dev/null &");
84 &system_logged("$config{'squid_path'} -k shutdown -f $config{'squid_conf'} >/dev/null 2>&1");
85 print "$text{'clear_failrestart'}<br>\n";
86 print "<pre>$errs</pre>\n";
91 &ui_print_footer("", $text{'icache_return'});