-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapache2ctl
More file actions
executable file
·80 lines (70 loc) · 1.88 KB
/
apache2ctl
File metadata and controls
executable file
·80 lines (70 loc) · 1.88 KB
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
#!/bin/sh
# DASH compatible.
#
# Wrap calls to apache2ctl. If necessary, build the error_log pipes
# needed by error2syslog.
#
# Replace the system apache2ctl by creating a diversion, like so:
#
# dpkg-divert --add --rename --divert /usr/sbin/apache2ctl.distrib \
# /usr/sbin/apache2ctl
#
#
# Then install this script as /usr/sbin/apache2ctl.
ARGV="${@}"
a2c='/usr/sbin/apache2ctl.distrib'
httpd_conf='/www/etc/apache2/httpd.conf'
log_pipe_dir='/var/spool/apache2'
user='root'
group='www-data'
gawk_inc='BEGIN { IGNORECASE=1 }/^[[:space:]]*Include[[:space:]]/ {print $2}'
gawk_log='BEGIN { IGNORECASE=1 }/^[[:space:]]*ErrorLog[[:space:]]/ {print $2}'
createAccessLogPipe() {
if ! [ -p ${log_pipe_dir}/access_log ]
then
mkfifo -m 0660 "${log_pipe_dir}/access_log"
fi
}
findErrorLogs() {
# Process Apache2 configuration files and:
# 1) Echos ErrorLog file-paths
# 2) processes included configurations
local _conf _inc _log
_conf=${1}
for _log in $(gawk "${gawk_log}" ${_conf})
do
echo "${_log}"
done
for _inc in $(gawk "${gawk_inc}" ${_conf})
do
[ -e "${_inc}" ] || continue
findErrorLogs "${_inc}"
done
}
createErrorLogPipes() {
# Create ErrorLog Pipes
# 1) remove error_log directory
# 2) create error_log directory
# 3) create a fifo for each ErrorLog
local _log
rm -rf "${log_pipe_dir}/error_logs"
mkdir -m 0770 "${log_pipe_dir}/error_logs"
for _log in $(findErrorLogs ${httpd_conf} | sort -u)
do
mkfifo -m 0660 "${_log}"
done
}
# Build error_log pipes
case ${ARGV} in
start|restart|graceful)
if ! [ -d ${log_pipe_dir} ]
then
mkdir -m 0770 "${log_pipe_dir}"
fi
createAccessLogPipe
createErrorLogPipes
chown -R ${user}:${group} "${log_pipe_dir}"
;;
esac
# Invoke apache2ctl
${a2c} ${ARGV}