|
|
#1 |
|
Prospect
Join Date: Jan 2002
Location: North San Diego County
Posts: 31
|
What is the command line entry to stop and start Apache?
I have a script to rotate the access_log and error_log, but Apache seems to need to stop and restart to use the new log files. Is there a better way to rotate the logs? Thanks Dennis |
|
|
|
|
|
#2 |
|
League Commissioner
Join Date: Jan 2002
Posts: 5,536
|
$ man httpd
...DESCRIPTION httpd is the Apache HyperText Transfer Protocol (HTTP) server program. It is designed to be run as a standalone daemon process. When used like this it will create a pool of child processes to handle requests. To stop it, send a TERM signal to the initial (parent) process. The PID of this process is written to a file as given in the configu- ration file... so, you get the parent pid process run file from the http.conf file... Code:
$ egrep -i ^pidfile /etc/httpd/httpd.conf
PidFile "/private/var/run/httpd.pid"
$ egrep -i ^pidfile /etc/httpd/httpd.conf | \
cut -d" " -f2
"/private/var/run/httpd.pid"
$ egrep -i ^pidfile /etc/httpd/httpd.conf | \
cut -d" " -f2 | xargs cat
1908
$ ps -lp 1908 # the correct process? yes, PPID = 1
UID PID PPID ...STAT TT TIME COMMAND
0 1908 1 ... ?? 0:00.07 /usr/sbin/httpd
$ kill -TERM `egrep -i ^pidfile /etc/httpd/httpd.conf | \
cut -d" " -f2 | xargs cat`
bash: kill: (1908) - Operation not permitted
Code:
kill -TERM `egrep -i ^pidfile /etc/httpd/httpd.conf | \
cut -d" " -f2 | xargs cat`
# rotate logs here
/usr/sbin/httpd # fire up http service
# move/rename logfiles mv x _x # does this unlink httpd from the logs ? that is, if an http request comes # in before the HUP below, will httpd write to a new log ? kill -HUP <the pid magic above> # will hangup give httpd new log brains ? # handle moved log files i wonder what the official method is? Last edited by mervTormel; 06-22-2002 at 04:53 PM. |
|
|
|
|
|
#3 |
|
League Commissioner
Join Date: Jan 2002
Posts: 5,536
|
disregard all of the above, except as an exercise of learning.
see man pages for apachectl Code:
$ man apachectl
NAME
apachectl - Apache HTTP server control interface
SYNOPSIS
apachectl command [...]
OPTIONS
...
start, stop, restart, graceful
...
|
|
|
|
|
|
#4 |
|
League Commissioner
Join Date: Jan 2002
Posts: 5,536
|
it's sometimes interesting to take this backwards approach to investigation, but since all of this has been done before, it's expeditious to go straight to the horse's mouth, the apache documentation...
http://httpd.apache.org/docs/logs.html#rotation |
|
|
|
|
|
#5 |
|
Prospect
Join Date: Jan 2002
Location: North San Diego County
Posts: 31
|
Merv
Thanks for the link to the rotation info at apache.org. The info at http://httpd.apache.org/docs/logs.html#rotation was just what I was looking for. I took that and the standard rotation code in the 'daily' script cron runs and came up with a new file rotate_httpd.logs which I scheduled to run daily in cron. Once I am sure it is working properly, I will probably change it to a weekly cron job. So far this appears to work properly- Code:
#!/bin/sh -
#
# @(#)monthly 8.1 (Berkeley) 6/9/93
# modified to rotate Apache Logs 6/22/02
#
PATH=/bin:/usr/bin:/sbin:/usr/sbin
host=`hostname -s`
echo "Subject: $host Apache Log Rotate run output"
echo ""
echo -n "Rotating Apache log files:"
cd /var/log/httpd/
for i in access_log error_log; do
if [ -f "${i}" ]; then
echo -n " ${i}"
if [ -x /usr/bin/gzip ]; then gzext=".gz"; else gzext=""; fi
if [ -f "${i}.6${gzext}" ]; then mv -f "${i}.6${gzext}" "${i}.7${gzext}"; fi
if [ -f "${i}.5${gzext}" ]; then mv -f "${i}.5${gzext}" "${i}.6${gzext}"; fi
if [ -f "${i}.4${gzext}" ]; then mv -f "${i}.4${gzext}" "${i}.5${gzext}"; fi
if [ -f "${i}.3${gzext}" ]; then mv -f "${i}.3${gzext}" "${i}.4${gzext}"; fi
if [ -f "${i}.2${gzext}" ]; then mv -f "${i}.2${gzext}" "${i}.3${gzext}"; fi
if [ -f "${i}.1${gzext}" ]; then mv -f "${i}.1${gzext}" "${i}.2${gzext}"; fi
if [ -f "${i}.0${gzext}" ]; then mv -f "${i}.0${gzext}" "${i}.1${gzext}"; fi
if [ -f "${i}" ]; then
mv -f "${i}" "${i}.0";
apachectl graceful;
sleep 600;
if [ -x /usr/bin/gzip ]; then
gzip -9 "${i}.0";
fi;
fi
touch "${i}" && chmod 644 "${i}"
fi
done
|
|
|
|
|
|
#6 |
|
League Commissioner
Join Date: Jan 2002
Posts: 5,536
|
note that in the daily/weekly/monthly maintenance scripts, there are callouts to .local scripts, and that's a good place to put your host's maintenance scripts, and take an entry out of crontab...
Code:
$ grep '\.local' /etc/{d*,w*,m*}y
/etc/daily:if [ -f /etc/daily.local ]; then
/etc/daily: echo "Running daily.local:"
/etc/daily: sh /etc/daily.local
/etc/weekly:if [ -x /usr/libexec/makewhatis.local ]; then
/etc/weekly: makewhatis.local "${MANPATH}"
/etc/weekly:if [ -f /etc/weekly.local ]; then
/etc/weekly: echo "Running weekly.local:"
/etc/weekly: sh /etc/weekly.local
/etc/monthly:if [ -f /etc/monthly.local ]; then
/etc/monthly: echo "Running monthly.local:"
/etc/monthly: sh /etc/monthly.local
|
|
|
|
![]() |
|
|