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

Logrotate hourly will this restart my process

· 52CE 我爱测

I'm looking at switching my log rotate setup to rotate logs hourly instead of daily. I think I've got the config ready to go but wanted to check whether the config would trigger a reload/restart of the process with the postrotate…

问题原文

原帖链接 · John Fox · CC BY-SA 4.0

I'm looking at switching my log rotate setup to rotate logs hourly instead of daily. I think I've got the config ready to go but wanted to check whether the config would trigger a reload/restart of the process with the postrotate options?

I'm running this on ubuntu 16.04 and have copied my config from /etc/cron.daily to /etc/cron.hourly ready to go

Here's my config here from the logrotate.d/nginx file:

/var/log/nginx/*/*.log {
    hourly
    missingok
    rotate 720
    compress
    delaycompress
    notifempty
    create 640 nginx adm
    sharedscripts
    postrotate
            if [ -f /var/run/nginx.pid ]; then
                    kill -USR1 `cat /var/run/nginx.pid`
            fi
    endscript
}

If this does kill the process, is there a way around this step?

已采纳解答

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

The command you can see:

 kill -USR1 `cat /var/run/nginx.pid`

does not actually kill the process.

Instead, kill sends a specific signal "USR1" which for nginx has a specific meaning and tells the nginx master process to reopen it's log files.
This effectively means that nginx starts writing to the new log files.

With some other programs that aren't designed as proper daemons and don't understand this signal this might be a problem and you would have to kill and restart them. That doesn't apply to NGinx.

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

资料来源与适用范围

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

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

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