solo2500
Posts: 123
Joined: Sat Jul 09, 2016 12:38 am

logrotate question

Sun Sep 04, 2016 7:58 pm

If I create a log file... say XXX.log and it's not in the normal spot in the file structure for .log file. (/var/log/) will the logrotate function still work with it?
THANKS!!!
I'm a total novice, non-programer (...basically a hack.)

User avatar
DougieLawson
Posts: 39124
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: logrotate question

Sun Sep 04, 2016 9:25 pm

Logrotate has a bunch of config files in /etc/logrotate.d those define the rules for rotating various logs. Create your own file and you can do your own thing.

For example here's /etc/logrotate.d/mosquitto

Code: Select all

/var/log/mosquitto/mosquitto.log {
        rotate 7
        daily
        compress
        size 100k
        nocreate
        missingok
        postrotate
                /usr/bin/killall -HUP mosquitto
        endscript
}
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

npaisnel
Posts: 74
Joined: Sun Aug 05, 2018 4:23 pm

Re: logrotate question

Thu Aug 23, 2018 11:12 am

OK, I see two different methods to add a log file to be created.

Either:
create a separate file in the directory
/etc/logrotate.d

or

add an entry within
/etc/logrotate.conf


What is the difference between the two and where should I add an entry to rotate my heyu log file
/etc/heyu/heyu.log.ttyUSB0

DirkS
Posts: 10363
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: logrotate question

Thu Aug 23, 2018 11:39 am

I think the main .conf file is generally used for systemwide parameters, etc.
You would use files in /etc/logrotate.d for application-specific configuration

npaisnel
Posts: 74
Joined: Sun Aug 05, 2018 4:23 pm

Re: logrotate question

Thu Aug 23, 2018 11:58 am

OK, well I tried creating my own file in /etc/logrotate.d

I actually just copied it from one of the other files and changed a few details.

this is it

Code: Select all

/etc/heyu/heyu.log.ttyUSB0 {
  rotate 4
  weekly
  size 100k
  compress
  delaycompress
  missingok
  notifempty
  }
But using the -d switch to run it in vebose logging mode gives this:

Code: Select all

pi@raspberrypi:/etc/logrotate.d $ sudo logrotate -d --force /etc/logrotate.d/heyu
reading config file /etc/logrotate.d/heyu
error: /etc/logrotate.d/heyu:1 lines must begin with a keyword or a filename (possibly in double quotes)
error: /etc/logrotate.d/heyu:9, unexpected text after }
error: /etc/logrotate.d/heyu:10 lines must begin with a keyword or a filename (possibly in double quotes)
Reading state from file: /var/lib/logrotate/status
Allocating hash table for state file, size 64 entries
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state

Handling 1 logs

rotating pattern: /etc/heyu/heyu.log.ttyUSB0  forced from command line (4 rotations)
empty log files are not rotated, old logs are removed
considering log /etc/heyu/heyu.log.ttyUSB0
error: skipping "/etc/heyu/heyu.log.ttyUSB0" because parent directory has insecure permissions (It's world writable or w                   ritable by group which is not "root") Set "su" directive in config file to tell logrotate which user/group should be use                   d for rotation.
Creating new state
                                                                                                                     [ W                   pi@raspberrypi:/etc/logrotate.d $

DirkS
Posts: 10363
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: logrotate question

Thu Aug 23, 2018 12:19 pm

It looks like logrotate is very particular about the conf file layout.
Not sure what causes the errors but you could comment out any empty lines and remove any spaces in front of the closing bracket ('}')

re the access error at the end of the output: it actually says what' wrong.
It does not like log directories that are not secured.
Normally directories in '/etc' are owned by root, but I think /etc/heyu is not
BTW: /etc/ is not really the best directory for log files. I would move it to /var/log

npaisnel
Posts: 74
Joined: Sun Aug 05, 2018 4:23 pm

Re: logrotate question

Thu Aug 23, 2018 1:05 pm

Well I tried moving it and now the application 'heyu' cant write to the log file

Code: Select all

pi@raspberrypi:/ $ heyu restart
Config Line 12: Insufficient r/w permission for LOG_DIR directory /var/log/
Quitting due to errors in configuration file '/etc/heyu/x10.conf'
pi@raspberrypi:/ $


the location of the log file is stored in x10.conf

so can't move the log file ...what else can be done ?

npaisnel
Posts: 74
Joined: Sun Aug 05, 2018 4:23 pm

Re: logrotate question

Thu Aug 23, 2018 1:15 pm

OK, I am getting to grips with this Linux stuff..

I solved that myself. Rather than move the log file I changed the world permissions of the containing folder

sudo chmod 775 heyu

Code: Select all

pi@raspberrypi:/etc $ sudo chmod 775 heyu
pi@raspberrypi:/etc $ sudo logrotate -d --force /etc/logrotate.d/heyu
reading config file /etc/logrotate.d/heyu
Reading state from file: /var/lib/logrotate/status
Allocating hash table for state file, size 64 entries
Creating new state
Handling 1 logs
rotating pattern: /etc/heyu/heyu.log.ttyUSB0  forced from command line (6 rotations)
empty log files are not rotated, old logs are removed
considering log /etc/heyu/heyu.log.ttyUSB0
Creating new state
  Now: 2018-08-23 14:13
  Last rotated at 2018-08-23 14:00
  log needs rotating
rotating log /etc/heyu/heyu.log.ttyUSB0, log->rotateCount is 6
dateext suffix '-20180823'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /etc/heyu/heyu.log.ttyUSB0.6.gz to /etc/heyu/heyu.log.ttyUSB0.7.gz (rotatecount 6, logstart 1, i 6),
renaming /etc/heyu/heyu.log.ttyUSB0.5.gz to /etc/heyu/heyu.log.ttyUSB0.6.gz (rotatecount 6, logstart 1, i 5),
renaming /etc/heyu/heyu.log.ttyUSB0.4.gz to /etc/heyu/heyu.log.ttyUSB0.5.gz (rotatecount 6, logstart 1, i 4),
renaming /etc/heyu/heyu.log.ttyUSB0.3.gz to /etc/heyu/heyu.log.ttyUSB0.4.gz (rotatecount 6, logstart 1, i 3),
renaming /etc/heyu/heyu.log.ttyUSB0.2.gz to /etc/heyu/heyu.log.ttyUSB0.3.gz (rotatecount 6, logstart 1, i 2),
renaming /etc/heyu/heyu.log.ttyUSB0.1.gz to /etc/heyu/heyu.log.ttyUSB0.2.gz (rotatecount 6, logstart 1, i 1),
renaming /etc/heyu/heyu.log.ttyUSB0.0.gz to /etc/heyu/heyu.log.ttyUSB0.1.gz (rotatecount 6, logstart 1, i 0),
log /etc/heyu/heyu.log.ttyUSB0.7.gz doesn't exist -- won't try to dispose of it
renaming /etc/heyu/heyu.log.ttyUSB0 to /etc/heyu/heyu.log.ttyUSB0.1
compressing log with: /bin/gzip
pi@raspberrypi:/etc $




















npaisnel
Posts: 74
Joined: Sun Aug 05, 2018 4:23 pm

Re: logrotate question

Thu Aug 23, 2018 1:21 pm

npaisnel wrote:
Thu Aug 23, 2018 1:15 pm
OK, I am getting to grips with this Linux stuff..

I solved that myself. Rather than move the log file I changed the world permissions of the containing folder

sudo chmod 775 heyu


No well that did not work. now doing that heyu no longer has permission to write to its own folder
it seems to need /etc/heyu/ set to 777



So back to my earlier question...what next ?

I see this but have no idea what it means or what to do :

Code: Select all

considering log /etc/heyu/heyu.log.ttyUSB0
error: skipping "/etc/heyu/heyu.log.ttyUSB0" because parent directory has insecure permissions (It's world writable or writable by group which is not "root") Set "su" directive in config file to tell logrotate which user/group should be used for rotation.
Creating new state

DirkS
Posts: 10363
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: logrotate question

Thu Aug 23, 2018 1:48 pm

npaisnel wrote:
Thu Aug 23, 2018 1:21 pm
So back to my earlier question...what next ?

I see this but have no idea what it means or what to do :

Code: Select all

considering log /etc/heyu/heyu.log.ttyUSB0
error: skipping "/etc/heyu/heyu.log.ttyUSB0" because parent directory has insecure permissions (It's world writable or writable by group which is not "root") Set "su" directive in config file to tell logrotate which user/group should be used for rotation.
Creating new state
That msg suggests using a different user for logrotate with the 'su <user> <group>' keyword
See https://www.systutorials.com/docs/linux ... tate.conf/
So you would add e.g.

Code: Select all

su pi pi
to your .conf file replace 'pi' with the owner of /etc/heyu

npaisnel
Posts: 74
Joined: Sun Aug 05, 2018 4:23 pm

Re: logrotate question

Thu Aug 23, 2018 2:52 pm

Yes , thanks.. I had been trying that but the age old problem of man-pages. They are only any use if you are an experienced user and understand what they tell you. Being a novice at this , man-pages are near as useless as you can get, without someone giving an example. They never seem to have any examples of how to use all the extra commands or the one you need within the 'man page'

I have found that line has to go in the individual page within the logrotate.d directory and not within the logrotate.conf file itself


seems to be working now

Code: Select all

/etc/heyu/heyu.log.ttyUSB0 {
  su pi pi
  rotate 4
  weekly
  size 100k
  compress
  delaycompress
  missingok
  notifempty
  }


Return to “Beginners”