-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapacherestart
executable file
·99 lines (84 loc) · 1.82 KB
/
apacherestart
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/perl -w
# Mit Jul 14 11:48:57 MEST 2004
(my $email='XXX%YYY,ch')=~ tr/%,/@./;
use strict;
use Time::HiRes "sleep";
$0=~ /(.*?)([^\/]+)\z/s or die "?";
my ($mydir, $myname)=($1,$2);
sub usage {
print STDERR map{"$_\n"} @_ if @_;
print "$myname [ init.d/]apachex
(Christian Jaeger <$email>)
";
exit @_ ? 1 : 0;
}
my @args;
my $DEBUG=0;
for (my $i=0; $i<=$#ARGV; $i++) {
local $_=$ARGV[$i];
if (/^--?h(elp)?$/) {
usage
} elsif ($_ eq '--') {
push @args, @ARGV[$i+1..$#ARGV];
last;
} elsif (/^--?d(ebug)?$/) {
$DEBUG=1;
# } elsif (/^--?X(?:XXX(?:=(.*))?)?$/) {
# if (defined $1) {
# $XXX=$1
# } else {
# $XXX=$ARGV[++$i] or usage "missing argument for '$_' option";
# }
} elsif (/^-./) {
usage("Unknown option '$_'\n");
} else {
push @args, $_
}
}
usage unless @args;
use Chj::xopen qw(xopen_read);
use Chj::xperlfunc;
for my $apachectl (@args) {
$apachectl=~ m|/| or do {
$apachectl= "/etc/init.d/$apachectl";
};
my $pidfile= do {
my $cnt=(xopen_read $apachectl)->xcontent;
sub getvar {
my ($name)=@_;
my ($rawval)=$cnt=~ /^\s*\Q$name\E\s*=\s*(\S+)/m;
$rawval=~ s%
\$\{?([a-z]\w*)\}?
%
my ($name)=$1;#
getvar($name);
%sgexi;
$rawval
}
getvar("PIDFILE")
};
#print "PIDFILE ist: $pidfile\n";
sub is_running {
if (-e $pidfile) {
if (my $pid=eval {
(xopen_read $pidfile)->xreadline;
}) {
chomp $pid;
return kill 0,$pid;
} else {
if ($@){ warn $@};
return 0
}
} else {
return 0
}
}
if (is_running){
xsystem $apachectl,"stop";
}
while(is_running){
sleep 0.1;
}
#sleep 0.2;#really needed? also vorher als ich nur -e file gemacht hab, war es nie nötig.
xsystem $apachectl,"start";
}