LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-26-2008, 08:35 AM   #1
Swakoo
Member
 
Registered: Apr 2005
Distribution: Red Hat / Fedora / CentOS
Posts: 508

Rep: Reputation: 30
Logrotate: don't seem to be able to restart service (apache)


Hi guys,

I have in my server, 2 instances of apache 2.0.54.
One is relying on java's Policy Agent, one is not.

Anyway, I am trying to use logrotate to rotate the logs so as to save some space... but I realise the service is not being restarted as the process ID is the same...

this is the logrotate conf I used
Quote:
/var/log/httpd/*log {
daily
rotate 5
missingok
notifempty
sharedscripts
postrotate
apachectl -f conf/withpa.conf stop
apachectl -f conf/httpd.conf restart
apachectl -f conf/withpa.conf start
endscript
nocompress
}

the instance with pa have to be stop and then start, thus so

am I doing it wrongly?

Also, I am thinking of backing up the logs to a remote server using scp on a daily basis... but can't think of a good way to let the script copy the latest log... since the logs are being rotated and then renamed...

any pointers?
thanks!
 
Old 01-26-2008, 01:31 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
I stopped using logrotate for Apache a while back and now I let Apache rotate the logs itself. From the man page for rotatelogs:
Code:
 CustomLog "|bin/rotatelogs /var/logs/logfile 86400" common

       This  creates the files /var/logs/logfile.nnnn where nnnn is the system time at which the log nominally starts
       (this time will always be a multiple of the rotation time, so you can synchronize cron scripts  with  it).  At
       the end of each rotation time (here after 24 hours) a new log is started.
              
            CustomLog "|bin/rotatelogs -l /var/logs/logfile.%Y.%m.%d 86400" common
 
Old 01-26-2008, 01:41 PM   #3
Swakoo
Member
 
Registered: Apr 2005
Distribution: Red Hat / Fedora / CentOS
Posts: 508

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by gilead View Post
I stopped using logrotate for Apache a while back and now I let Apache rotate the logs itself. From the man page for rotatelogs:
Code:
 CustomLog "|bin/rotatelogs /var/logs/logfile 86400" common

       This  creates the files /var/logs/logfile.nnnn where nnnn is the system time at which the log nominally starts
       (this time will always be a multiple of the rotation time, so you can synchronize cron scripts  with  it).  At
       the end of each rotation time (here after 24 hours) a new log is started.
              
            CustomLog "|bin/rotatelogs -l /var/logs/logfile.%Y.%m.%d 86400" common
cool i didn't know you could do that.. i'll check it out.. thanks!
 
Old 01-28-2008, 12:37 AM   #4
Swakoo
Member
 
Registered: Apr 2005
Distribution: Red Hat / Fedora / CentOS
Posts: 508

Original Poster
Rep: Reputation: 30
hi guys.. but just thought i carry on from my initial question


if i do logrotate, how do I ensure the service restart? is my way correct?
 
Old 01-28-2008, 01:06 PM   #5
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
The example in the logrotate man page uses a postrotate option to re-start the daemon:
Code:
"/var/log/httpd/access.log" /var/log/httpd/error.log {
  rotate 5
  www@my.org
  size=100k
  sharedscripts
  postrotate
    /sbin/killall -HUP httpd
  endscript
}
 
Old 02-03-2008, 09:24 PM   #6
Swakoo
Member
 
Registered: Apr 2005
Distribution: Red Hat / Fedora / CentOS
Posts: 508

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by gilead View Post
The example in the logrotate man page uses a postrotate option to re-start the daemon:
Code:
"/var/log/httpd/access.log" /var/log/httpd/error.log {
  rotate 5
  www@my.org
  size=100k
  sharedscripts
  postrotate
    /sbin/killall -HUP httpd
  endscript
}
yeah but mine is self-compiled.. will it catch it?
Or does the flag -HUP mean that?
 
Old 02-03-2008, 09:31 PM   #7
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
Your Apache is self-compiled? No problem, mine is too and logrotate works properly here.
 
Old 02-04-2008, 06:33 AM   #8
Swakoo
Member
 
Registered: Apr 2005
Distribution: Red Hat / Fedora / CentOS
Posts: 508

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by gilead View Post
Your Apache is self-compiled? No problem, mine is too and logrotate works properly here.


actually my concern is if my apache is being restarted properly.
Initially I have the misconception that if i restart it, the process ID will be different.. but apparently not.. so how do I see if apache restarted successfully?

also.. for logrotate.. is it essential for the service to be restarted after rotation?

lastly.. what does the -HUP mean? does it mean that it will restart the process?
 
Old 02-04-2008, 12:50 PM   #9
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
I need to use the killall on my setup. If you want to see the different effects, try it with and without, but make sure that you hit your web servers with requests before and after so you can see which log files are being used. httpd should be still running, you can use netstat to confirm it:
Code:
netstat -tunape | grep httpd
The HUP signal causes Apache to re-read its config files and re-initialise.
 
Old 02-09-2008, 03:47 AM   #10
Swakoo
Member
 
Registered: Apr 2005
Distribution: Red Hat / Fedora / CentOS
Posts: 508

Original Poster
Rep: Reputation: 30
hi there, i've used the -HUP but to no avail. (/sbin/killall -HUP httpd)
My logs are rotated, but it won't write to the new logfiles, unless i manually restart apache.

I've now write a script to restart apache, and have point logrotate to restart it.. will know tomorrow if it works.
Meanwhile... how do you guys do it? My apache is self-compiled. I am running multiple instances of apache in the same machine, so I have to restart all of them.

thanks!
 
Old 02-09-2008, 01:13 PM   #11
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
The problem you're describing is the reason I use Apache's rotatelogs utility. If you manage to get it working the way you described earlier, can you post your final config please?
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
what is the difference between service network reload and service network restart ? markraem Linux - Networking 3 11-21-2007 03:08 PM
restart logrotate? stefaandk Linux - Newbie 2 11-27-2006 07:16 PM
How do I set the regulatory daemon to restart when I restart the network service? zahadumy Linux - Networking 0 11-05-2006 11:24 AM
Restart apache service without password prompt? Phaethar Linux - Software 2 07-06-2004 01:28 PM
Apache logrotate teeno Linux - Software 4 08-06-2003 10:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration