LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-28-2012, 11:10 AM   #1
srinadi
LQ Newbie
 
Registered: Aug 2012
Posts: 1

Rep: Reputation: Disabled
postrotate in logrotate


Hi All,

I am a newbie to linux and working on RHEL. I tried to implement logrotation for apache logs and stuck at restarting a process after apache restart.My script is as below

/usr/local/apache2/access_log {
weekly
rotate 25
compress
create
postrotate
/usr/local/apache2/bin/apachectl restart > /dev/null 2>&1
if [ -f /usr/local/apache2/logs/httpd.pid ];then
sudo -u reto ./usr/local/Misc/Start_Stream.sh > /dev/null 2>&1
fi
endscript
}
when i execute this script with root user, Apache is getting started but the script in the condition which has to be run with reto user is not executing..Any inputs please.
Thanks in Advance.
 
Old 08-28-2012, 12:31 PM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,476

Rep: Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020
Here's one that does work:
Code:
/var/log/httpd/*_log {
  rotate 10
  notifempty
  missingok
  size=5M
  compress
  delaycompress
  sharedscripts
  postrotate
    /etc/rc.d/rc.httpd restart
  endscript
}
For your purposes, you'd edit the log location to
Code:
/usr/local/apache2/access_log {
(possibly changing "access_log" to "*_log" to catch both the access_log and error_log).

You would edit the /etc/rc.d/rc.httpd restart to your system's actual start up program (the one that executes at boot) if it includes the restart directive, or simply to edit the apachectl line, adding the -k option:
Code:
/usr/local/apache2/bin/apachectl -k restart > /dev/null 2>&1
You most likely do not need
Code:
if [ -f /usr/local/apache2/logs/httpd.pid ];then
sudo -u reto ./usr/local/Misc/Start_Stream.sh > /dev/null 2>&1
fi
If you have a special purpose for those, leave them in place but do the following.

See Stopping and Restarting at http://httpd.apache.org/docs/2.2/stopping.html; essentially, the -k option sends a TERM signal to the running process causing it to kill off all of its children. Can't hurt, might help.

You might also want to change the size=5M (which is a test for the log size being 5 megabytes) to some other value depending upon how large your logs get in a week.

Hope this helps some.

Last edited by tronayne; 08-28-2012 at 12:36 PM.
 
Old 08-28-2012, 09:45 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
logrotate like cron really requires full/absolute paths to ensure stuff will run
Code:
sudo -u reto ./usr/local/Misc/Start_Stream.sh > /dev/null 2>&1
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] logrotate or logrotate.conf; problems with sftp slufoot80 Linux - Server 1 11-05-2011 08:50 AM
Logrotate - Purpose of rotate and postrotate fizeelinux Linux - Newbie 5 07-14-2010 05:00 AM
error running postrotate script linux_bud Linux - Server 1 04-05-2010 03:29 AM
error running postrotate script farslayer Linux - General 1 07-19-2007 02:41 AM
Logrotate problem - postrotate: command not found humbletech99 Linux - General 2 01-14-2007 11:49 AM


All times are GMT -5. The time now is 01:47 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration