Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm just being lazy here, but does any one have already writen bash script for stopping tomcat service, archive it's log files (zip would be nice) and reboot the server? (Using logrotate or any other tool)

I want create cron job with following script:

#!/bin/bash
service tomcat stop
# now I don't know what to do with logrotate or something else
init 6

Please help.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You can make a config file for logrotate that takes care of the log rotation. You can place it outside of logrotate.d and then just use it when calling logrotate manually.

Sample:

/path/to/logs/*.log {
        missingok
        rotate 30
        compress
        delaycompress
        notifempty
        create 640 tomcat tomcat
        sharedscripts
}

And then make your script

#!/bin/bash
service tomcat stop
logrotate -f /path/to/your/newly/created/conf/for/logrotate.conf
init 6
share|improve this answer
    
Can I do just /path/to/logs/* { so all files in the folder are included? –  Mat Banik Mar 11 '11 at 2:18
    
Yeah you can do that –  Frands Hansen Mar 11 '11 at 2:19

Instead of trying to hope someone wrote one Super Script that does it all, start by writing a script that archives the log files when its run. If it's fast, add it to the K* scripts after tomcat is stopped during reboot or halt runlevels. If it's slow, some distributions just kill everything after a couple of seconds if their halt script takes "too long". Add it to the startup ahead of starting tomcat.

Then, just shutdown -r now and it'll be taken care of.

share|improve this answer
    
do you have script that is archiving log files? And are you willing to share it? –  Mat Banik Mar 10 '11 at 23:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.