Go Back   The macosxhints Forums > OS X Help Requests > Networking



Reply
 
Thread Tools Rate Thread Display Modes
Old 06-22-2002, 02:56 PM   #1
dennisj
Prospect
 
Join Date: Jan 2002
Location: North San Diego County
Posts: 31
Question Stop and Start Apache

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
dennisj is offline   Reply With Quote
Old 06-22-2002, 04:51 PM   #2
mervTormel
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
so, get that magic working, then you can script something like
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
there's probably a better way without diminishing service. hmm, like...

# 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.
mervTormel is offline   Reply With Quote
Old 06-22-2002, 05:03 PM   #3
mervTormel
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
...
see graceful about log file maintenance.
mervTormel is offline   Reply With Quote
Old 06-22-2002, 05:14 PM   #4
mervTormel
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
mervTormel is offline   Reply With Quote
Old 06-23-2002, 01:12 AM   #5
dennisj
Prospect
 
Join Date: Jan 2002
Location: North San Diego County
Posts: 31
Lightbulb Rotating httpd logs

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
dennisj is offline   Reply With Quote
Old 06-23-2002, 01:23 AM   #6
mervTormel
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
mervTormel is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 06:17 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.