File: start_apache.cgi

package info (click to toggle)
webmin-virtual-server 2.50-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,608 kB
  • ctags: 392
  • sloc: perl: 15,687; makefile: 95; sh: 8
file content (73 lines) | stat: -rwxr-xr-x 2,091 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/local/bin/perl
# start_apache.cgi
# Start apache with the server root from the config files

require './virtual-server-lib.pl';
$access{'stop'} || &error($text{'start_ecannot'});
&require_apache();
&ReadParse();
&error_setup($apache::text{'start_err'});

&clean_environment();

if ($apache::config{'start_cmd'}) {
	# use the configured start command
	if ($apache::config{'stop_cmd'}) {
		# execute the stop command to clear lock files
		&system_logged("( $apache::config{'stop_cmd'} ) >/dev/null 2>&1");
		}
	$out = &backquote_logged("( $apache::config{'start_cmd'} ) 2>&1");
	&reset_environment();
	if ($?) {
		&error("<pre>$out</pre>");
		}
	}
elsif (-x $apache::config{'apachectl_path'}) {
	# use the apachectl program
	$out = &backquote_logged("( $apache::config{'apachectl_path'} start ) 2>&1");
	&reset_environment();
	if ($out =~ /\S/ && $out !~ /httpd started/) {
		&error("<pre>$out</pre>");
		}
	}
else {
	# start manually
	$cmd = "$apache::config{'httpd_path'} -d $apache::config{'httpd_dir'}";
	if ($apache::config{'httpd_conf'}) { $cmd .= " -f $apache::config{'httpd_conf'}"; }
	$temp = &tempname();
	$rv = &system_logged("( $cmd ) >$temp 2>&1 </dev/null");
	$out = `cat $temp`;
	unlink($temp);
	&reset_environment();
	if ($out =~ /\S/ && $out !~ /httpd started/) {
		&error("<pre>$cmd :\n$out</pre>");
		}
	}

# check if startup was successful. Later apache version return no
# error code, but instead fail to start and write the reason to
# the error log file!
sleep(3);
$conf = &apache::get_config();
$pid = &get_apache_pid();
if (!$pid || !kill(0, $pid)) {
	# Not running..  find out why
	$errorlogstr = &apache::find_directive_struct("ErrorLog", $conf);
	$errorlog = $errorlogstr ? $errorlogstr->{'words'}->[0]
				 : "logs/error_log";
	if ($out =~ /\S/) {
		&error("<pre>$out</pre>");
		}
	elsif ($errorlog eq 'syslog' || $errorlog =~ /^\|/) {
		&error($apache::text{'start_eunknown'});
		}
	else {
		$errorlog = &apache::server_root($errorlog, $conf);
		$out = `tail -5 $errorlog`;
		&error("<pre>$out</pre>");
		}
	}
&webmin_log("start", "web");
&redirect("");