cron 작업에서 nginx logrotate 오류

cron 작업에서 nginx logrotate 오류

저는 Digital Ocean VPS에서 Ubuntu 14.04 LTS 및 nginx를 실행하고 있으며 때때로 실패한 크론 작업에 대한 다음 이메일을 받습니다.

주제

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 
}

고쳐 쓰다:

$ sudo invoke-rc.d nginx rotate
initctl: invalid command: rotate
Try `initctl --help' for more information.

답변1

회전 후 작업이 잘못된 것 같습니다.

노력하다

invoke-rc.d nginx reload >/dev/null 2>&1

명령 을 보면 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.

따라서 다시 로드가 작동하고 HUP 신호를 nginx에 보내 로그 파일을 강제로 다시 열어야 합니다.

답변2

다른 답변에서 언급했듯이 문제는 작업이 지원되지 않는다는 invoke-rc.d nginx rotate오류가 반환된다는 것입니다. rotate흥미롭게도 service nginx rotate아무런 문제 없이 실행되었습니다.

invoke-rc.d내 생각엔 래퍼가 실제 nginx init 스크립트가 지원하는 모든 작업을 지원하지 않는 것 같습니다 .

invoke-rc.d nginx rotate으로 변경하면 service nginx rotate문제가 해결됩니다.

답변3

initctl옵션이 지원되지 않아서 제거되었는지 여부는 확실하지 않지만 rotate이로 인해 영향을 받는 유일한 사람은 아니며 Launchpad에 이 문제에 대한 공개 버그 보고서가 있습니다.

위와 아래의 다른 답변에서 언급했듯이 nignx logrotate 파일을 편집하고 문제가 있는 줄을 바꿀 수 있습니다

invoke-rc.d nginx reload >/dev/null 2>&1

다른 유효한 대안을 사용하면

start-stop-daemon --stop --signal USR1 --quiet --pidfile /run/nginx.pid --name nginx
# or 
service nginx rotate >/dev/null 2>&1
# or
[ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`

어떤 방법을 선택하든 패키지에서 관리하는 파일을 변경하고 있다는 점에 유의하세요. 파일을 변경한 후에는 더 이상 업데이트되지 않으며 차이점을 수동으로 해결하거나 새 파일로 교체해야 합니다(즉, 수정 사항을 포함할 준비가 되었습니다).

답변4

바꾸다:

invoke-rc.d nginx reload >/dev/null 2>&1

그리고:

[ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`

최신 버전의 Nginx에서는 이것이 작동하는 것 같습니다. 버전 1.9를 실행 중입니다.

관련 정보