我正在使用一个非常普通的openrc服务来运行一个Go应用程序,我编写了一个将日志数据输出到stdout的应用程序,在我对应用程序的日志文件启用logrorate之前,它运行得非常好。它似乎旋转了日志,但是在日志文件被截断后的某个点之后,我的Go应用程序就完全停止了对该文件的日志记录。当我重新启动服务时,它似乎又起作用了。
我的openrc服务文件:
#!/sbin/openrc-run
name="My Server"
description="My Server Written in Go"
command="/usr/bin/server"
command_args="/etc/${RC_SVCNAME}/${RC_SVCNAME}.conf"
pidfile="/var/run/${RC_SVCNAME}.pid"
command_background="yes"
output_log="/var/log/${RC_SVCNAME}/${RC_SVCNAME}.log"
error_log="/var/log/${RC_SVCNAME}/${RC_SVCNAME}.log"
depend() {
use net localmount logger dns
need net
after keepalived firewall
}
start_pre() {
checkpath --directory /etc/${RC_SVCNAME}
}我的logrotate配置。
/var/log/server/*.log {
daily
missingok
notifempty
}我是否需要对我的应用程序做任何事情才能知道日志的旋转?
发布于 2021-01-20 00:12:12
我不是日志旋转的主程序,但是您可以通过以下方式重新启动该服务:
/var/log/server/*.log {
daily
missingok
notifempty
postrotate
/etc/init.d/server --quiet --ifstarted restart || true
endscript
}https://unix.stackexchange.com/questions/620415
复制相似问题