cron作业上的nginx logrotate错误

Chr*_*ris 11 cron ubuntu logrotate nginx

我在 Digital Ocean VPS 上运行 Ubuntu 14.04 LTS 和 nginx,偶尔会收到这些关于失败的 cron 作业的电子邮件:

主题

cron test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )

电子邮件的正文是:

/etc/cron.daily/logrotate: 错误: 为'/var/log/nginx/*.log' 运行部分运行共享 postrotate 脚本时出错: /etc/cron.daily/logrotate 退出并返回代码 1

关于如何解决这个问题的任何想法?

更新:

/var/log/nginx/*.log {
  weekly
  missingok 
  rotate 52 
  compress 
  delaycompress
  notifempty 
  create 0640 www-data adm
  sharedscripts
  prerotate
      if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
          run-parts /etc/logrotate.d/httpd-prerotate; \
      fi
  endscript 
  postrotate 
      invoke-rc.d nginx rotate >/dev/null 2>&1
  endscript 
}
Run Code Online (Sandbox Code Playgroud)

更新:

$ sudo invoke-rc.d nginx rotate
initctl: invalid command: rotate
Try `initctl --help' for more information.
Run Code Online (Sandbox Code Playgroud)

X T*_*ian 11

帖子轮换操作似乎不正确

尝试

invoke-rc.d nginx reload >/dev/null 2>&1
Run Code Online (Sandbox Code Playgroud)

如果您查看该nginx命令,您将看到它将接受的操作。还有你收到的消息说检查initctl --help

xtian@fujiu1404:~/tmp$ initctl help
Job commands:
  start                       Start job.
  stop                        Stop job.
  restart                     Restart job.
  reload                      Send HUP signal to job.
  status                      Query status of job.
  list                        List known jobs.
Run Code Online (Sandbox Code Playgroud)

所以重新加载应该工作并向nginx发送HUP信号以强制重新打开日志文件。


小智 5

正如另一个答案中提到的,问题是invoke-rc.d nginx rotate返回一个错误,指出rotate不支持该操作。有趣的是,它service nginx rotate可以毫无问题地工作。

我的猜测是invoke-rc.d包装器不支持实际 nginx init 脚本支持的所有操作。

更改invoke-rc.d nginx rotateservice nginx rotate应该可以解决问题。