5

I'm new to logrotate on linux machines... here's what I have set up in my app's logrotate.d file:

/var/log/myapp.log {
daily
missingok
create 0660 root utmp
rotate 1
}

I set owner permissions on the myapp.log file for the account that runs the app in question, using chmod, directly from the bash shell.

when the app first runs, everything is fine. It logs just fine and it's all good. But when the log gets rotated, it deletes the log file and then tries to recreate the log file and it gives a permission denied error:

/bin/bash: /var/log/myapp.log: Permission denied

I know I'm doing something wrong with either the logrotate config file or chmod or something... can someone point me in the right direction and help me fix the problem?

Kiril Kirov
  • 37,467
  • 22
  • 115
  • 187
Derick Bailey
  • 72,004
  • 22
  • 206
  • 219

1 Answers1

7

I set owner permissions on the myapp.log file for the account that runs the app in question, using chmod, directly from the bash shell.

...so unless "the account that runs the app in question" is root, the config option

create 0660 root utmp

is wrong, because that is asking logrotate to create a new myapp.log (after it has rotated the original myapp.log to myapp.log.0) with permissions 0660 owned by user root and group utmp. Replacing these with the attributes required by your app should solve the problem.

Matthew Slattery
  • 45,290
  • 8
  • 103
  • 119
  • i was suspecting this... i'm not familiar with the permissions that i would need to set, unfortunately. you have any links, info, or recommendations of what to try? i just need to log / rotate the one file in /var/log – Derick Bailey Jun 02 '11 at 00:38
  • 1
    `man chmod` explains numeric permission modes; try `ls -l /var/log/myapp.log` while it's in a working state to show current permissions (in text form, e.g. `-rw-r-----` corresponds to `0640`), user and group. (Alternatively, `man logrotate` suggests that simply using `create` without additional parameters will cause it to use the same attributes as the original log file.) – Matthew Slattery Jun 02 '11 at 01:12
  • everything appears to be working now. thanks for the help, Matthew! – Derick Bailey Jun 02 '11 at 12:55