大网数据广告活动
服务器运维问答

logrotate postrotate seems not being executed

· 52CE 我爱测

I have this configuration on Ubuntu 20.04: /home/impulse/nginx/log/*/notice.log /home/impulse/nginx/log/*/access.status_ok.log /home/impulse/nginx/log/*/access.status_erro.log { daily nomail dateext rotate 31 dateyesterday create…

问题原文

原帖链接 · Niloct · CC BY-SA 4.0

I have this configuration on Ubuntu 20.04:

/home/impulse/nginx/log/*/notice.log /home/impulse/nginx/log/*/access.status_ok.log /home/impulse/nginx/log/*/access.status_erro.log {
  daily
  nomail
  dateext
  rotate 31
  dateyesterday
  create root root
  notifempty
  nocompress
  extension .log
  # Script to notify nginx that logfile changed.
  postrotate
    docker exec -ti impulse_web sudo pkill -HUP nginx
  endscript
}

docker binary is only allowed via sudo on the server. The postrotate script is not being executed.

My question is, under which account does logrotate run ? And, can I log its execution to track why this isn't being applied ?

The script works when called on the terminal with sudo.

My current log dir:

-rw-r--r-- 1 root root 3073955 fev  3 11:02 access.status_ok-20210128.log
-rw-r--r-- 1 root root       0 jan 29 00:00 access.status_ok.log

Since access.status_ok.log is empty, the logrotate fails. And nginx keeps logging in the old file because the postrotate failed.

已采纳解答

原帖链接 · Niloct · CC BY-SA 4.0

This issue had 2 misunderstandings:

And one main FACEPALM reason:

  • docker exec in the postrotate script must not had the -ti options, because it's not running in an interactive terminal.....

The debug logs from systemd were there all the time, but they were NOT recorded in /var/log/syslog. The following helped:

https://unix.stackexchange.com/questions/225401/how-to-see-full-log-from-systemctl-status-service

https://askubuntu.com/questions/1083537/how-do-i-properly-install-a-systemd-timer-and-service

Do systemd unit files have to be reloaded when modified?

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-02-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。