Lines 6-28
APACHE_RC_CONF="/etc/conf.d/apache2"
Link Here
|
6 |
# List of init script verbs that should be passed forward |
6 |
# List of init script verbs that should be passed forward |
7 |
RC_VERBS="start stop restart checkconfd configtest modules virtualhosts configdump fullstatus graceful gracefulstop reload" |
7 |
RC_VERBS="start stop restart checkconfd configtest modules virtualhosts configdump fullstatus graceful gracefulstop reload" |
8 |
|
8 |
|
9 |
load_rc_config() { |
9 |
|
10 |
[ -f "${APACHE_RC_CONF}" ] || return 1 |
10 |
function is_systemd() { |
11 |
if ! grep -q '^[[:space:]]*APACHE2_OPTS' ${APACHE_RC_CONF} ; then |
11 |
[ $(ps --no-headers -o comm 1) == "systemd" ] && return 0 |
12 |
echo "Cannot find APACHE2_OPTS in ${APACHE_RC_CONF}" |
12 |
return 1 |
13 |
exit 1 |
13 |
} |
14 |
fi |
14 |
|
15 |
. ${APACHE_RC_CONF} |
15 |
function load_rc_config() { |
16 |
export APACHE2_OPTS |
16 |
[ -f "${APACHE_RC_CONF}" ] || return 1 |
17 |
export SERVERROOT="${SERVERROOT:-/usr/@LIBDIR@/apache2}" |
17 |
if ! grep -q '^[[:space:]]*APACHE2_OPTS' ${APACHE_RC_CONF} ; then |
18 |
export CONFIGFILE="${CONFIGFILE:-/etc/apache2/httpd.conf}" |
18 |
echo "Cannot find APACHE2_OPTS in ${APACHE_RC_CONF}" |
|
|
19 |
exit 1 |
20 |
fi |
21 |
. ${APACHE_RC_CONF} |
22 |
export APACHE2_OPTS |
23 |
export SERVERROOT="${SERVERROOT:-/usr/lib64/apache2}" |
24 |
export CONFIGFILE="${CONFIGFILE:-/etc/apache2/httpd.conf}" |
25 |
} |
26 |
|
27 |
# Basically the code from '/etc/init.d/apache2::reload()', updated to run without open-rc |
28 |
function reload() { |
29 |
RELOAD_TYPE="${RELOAD_TYPE:-graceful}" |
30 |
|
31 |
if [ "${RELOAD_TYPE}" = "restart" ]; then |
32 |
${APACHE2} ${APACHE2_OPTS} -k restart |
33 |
elif [ "${RELOAD_TYPE}" = "graceful" ]; then |
34 |
${APACHE2} ${APACHE2_OPTS} -k graceful |
35 |
else |
36 |
echo "${RELOAD_TYPE} is not a valid RELOAD_TYPE. Please edit /etc/conf.d/apache2" |
37 |
fi |
38 |
} |
39 |
|
40 |
# Basically the code from '/etc/init.d/apache2::fullstatus()', updated to run without open-rc |
41 |
function fullstatus() { |
42 |
LYNX="${LYNX:-lynx -dump}" |
43 |
STATUSURL="${STATUSURL:-http://localhost/server-status}" |
44 |
|
45 |
if ! command -v $(set -- ${LYNX}; echo $1) 2>&1 >/dev/null; then |
46 |
echo 'lynx not found! you need to emerge www-client/lynx' |
47 |
else |
48 |
${LYNX} ${STATUSURL} |
49 |
fi |
50 |
return $? |
19 |
} |
51 |
} |
20 |
|
52 |
|
21 |
# If first parameter is a verb defined in $RC_VERBS, pass the command to init script. |
53 |
# Basically the code from '/etc/init.d/apache2::checkconfd()', updated to run without open-rc |
22 |
# In other cases, compile command line and run the command on apache binary. |
54 |
function checkconfd() { |
23 |
if echo "${RC_VERBS}" | grep -q -- "${1}" ; then |
55 |
if [ ! -d ${SERVERROOT} ]; then |
24 |
exec /etc/init.d/apache2 "${@}" |
56 |
echo "SERVERROOT does not exist: ${SERVERROOT}" |
25 |
else |
57 |
return 1 |
26 |
load_rc_config || exit 1 |
58 |
fi |
27 |
${APACHE2} ${APACHE2_OPTS} -d ${SERVERROOT} -f ${CONFIGFILE} "${@}" |
59 |
} |
|
|
60 |
|
61 |
# Basically the code from '/etc/init.d/apache2::checkconfig()', updated to run without open-rc |
62 |
function configtest() { |
63 |
checkconfd || return 1 |
64 |
|
65 |
OUTPUT=$( ${APACHE2} ${APACHE2_OPTS} -t 2>&1 ) |
66 |
ret=$? |
67 |
if [ $ret -ne 0 ]; then |
68 |
echo "apache2 has detected an error in your setup:" |
69 |
printf "%s\n" "${OUTPUT}" |
70 |
fi |
71 |
|
72 |
return $ret |
73 |
} |
74 |
|
75 |
# Basically the code from '/etc/init.d/apache2::configdump()', updated to run without open-rc |
76 |
function configdump() { |
77 |
INFOURL="${INFOURL:-http://localhost/server-info}" |
78 |
|
79 |
if ! command -v $(set -- ${LYNX}; echo $1) 2>&1 >/dev/null; then |
80 |
echo "lynx not found! you need to emerge www-client/lynx" |
81 |
else |
82 |
echo "${APACHE2} started with '${APACHE2_OPTS}'" |
83 |
for i in config server list; do |
84 |
${LYNX} "${INFOURL}/?${i}" | sed '/Apache Server Information/d;/^[[:space:]]\+[_]\+$/Q' |
85 |
done |
86 |
fi |
87 |
} |
88 |
|
89 |
|
90 |
# If systemd IS NOT detected, run the legacy apache2ctl code |
91 |
if ! is_systemd; then |
92 |
# If first parameter is a verb defined in $RC_VERBS, pass the command to init script. |
93 |
# In other cases, compile command line and run the command on apache binary. |
94 |
if echo "${RC_VERBS}" | grep -q -- "${1}" ; then |
95 |
exec /etc/init.d/apache2 "${@}" |
96 |
else |
97 |
load_rc_config || exit 1 |
98 |
${APACHE2} ${APACHE2_OPTS} -d ${SERVERROOT} -f ${CONFIGFILE} "${@}" |
99 |
fi |
100 |
exit 0 |
28 |
fi |
101 |
fi |
29 |
- |
102 |
|
|
|
103 |
# If systemd IS detected, load the config and parse the argument |
104 |
load_rc_config || exit 1 |
105 |
|
106 |
# Append the server root and configuration file parameters to the |
107 |
# user's APACHE2_OPTS. |
108 |
APACHE2_OPTS="${APACHE2_OPTS} -d ${SERVERROOT}" |
109 |
APACHE2_OPTS="${APACHE2_OPTS} -f ${CONFIGFILE}" |
110 |
|
111 |
case $1 in |
112 |
# Original apachectl options |
113 |
# See: https://httpd.apache.org/docs/2.4/programs/apachectl.html |
114 |
start|stop|restart|status) |
115 |
/bin/systemctl $1 apache2.service |
116 |
ERROR=$? |
117 |
;; |
118 |
|
119 |
reload) |
120 |
reload |
121 |
ERROR=$? |
122 |
;; |
123 |
|
124 |
fullstatus) |
125 |
fullstatus |
126 |
ERROR=$? |
127 |
;; |
128 |
|
129 |
graceful) |
130 |
configtest || exit 1 |
131 |
/bin/systemctl reload apache2.service |
132 |
ERROR=$? |
133 |
;; |
134 |
|
135 |
gracefulstop|graceful-stop) |
136 |
configtest || exit 1 |
137 |
/bin/systemctl stop apache2.service |
138 |
ERROR=$? |
139 |
;; |
140 |
|
141 |
configtest) |
142 |
configtest |
143 |
ERROR=$? |
144 |
;; |
145 |
|
146 |
checkconfd) |
147 |
checkconfd |
148 |
ERROR=$? |
149 |
;; |
150 |
|
151 |
configdump) |
152 |
configtest || exit 1 |
153 |
configdump |
154 |
ERROR=$? |
155 |
;; |
156 |
|
157 |
virtualhosts) |
158 |
configtest || exit 1 |
159 |
${APACHE2} ${APACHE2_OPTS} -S |
160 |
ERROR=$? |
161 |
;; |
162 |
|
163 |
modules) |
164 |
configtest || exit 1 |
165 |
${APACHE2} ${APACHE2_OPTS} -M 2>&1 |
166 |
ERROR=$? |
167 |
;; |
168 |
|
169 |
# For all other options fall back to the legacy way of handling them |
170 |
*) |
171 |
${APACHE2} ${APACHE2_OPTS} "${@}" |
172 |
ERROR=$? |
173 |
;; |
174 |
esac |
175 |
|
176 |
exit $ERROR |