我是靠谱客的博主 负责钻石,这篇文章主要介绍Linux应用程序显示旋转,linux – 旋转愚蠢的非交互式应用程序的日志,现在分享给大家,希望可以做个参考。

伊格纳西奥的回答引起了我的兴趣,所以我做了一些研究,并提出了下面的Perl脚本.如果您的服务将写入命名管道,它应该工作并可用于logrotate.

要使它工作,您需要将日志文件设置为命名管道.然后重命名现有文件

mkfifo /var/log/something.log

并编辑3个文件名以满足您的要求.运行您的服务,然后运行此守护程序,该守护程序应读取命名管道并将其写入新的日志文件.

如果你重命名/var/log/somethingrotateable.log然后将一个HUP发送到守护进程,它将自己生成并创建一个新的somethingrotateable.log来写入.如果使用logrotate一个postrotate脚本kill -HUP’cat /var/run/yourpidfile.pid’

#!/usr/bin/perl -w

use POSIX ();

use FindBin ();

use File::Basename ();

use File::Spec::Functions;

#

$|=1;

#

# Change the 3 filenames and paths below to meet your requirements.

#

my $FiFoFile = '/var/log/something.log';

my $LogFile = '/var/log/somethingrotateable.log';

my $PidFile = '/var/run/yourpidfile.pid';

# # make the daemon cross-platform, so exec always calls the script

# # itself with the right path, no matter how the script was invoked.

my $script = File::Basename::basename($0);

my $SELF = catfile $FindBin::Bin, $script;

#

# # POSIX unmasks the sigprocmask properly

my $sigset = POSIX::SigSet->new();

my $action = POSIX::SigAction->new('sigHUP_handler',$sigset,&POSIX::SA_NODEFER);

POSIX::sigaction(&POSIX::SIGHUP, $action);

sub sigHUP_handler {

# print "Got SIGHUP";

exec($SELF, @ARGV) or die "Couldn't restart: $!n";

}

#open the logfile to write to

open(LOGFILE, ">>$LogFile") or die "Can't open $LogFile";

open(PIDFILE, ">$PidFile") or die "Can't open PID File $PidFile";

print PIDFILE "$$n";

close PIDFILE;

readLog();

sub readLog {

sysopen(FIFO, $FiFoFile,0) or die "Can't open $FiFoFile";

while ( my $LogLine = ) {

print LOGFILE $LogLine;

}

}

最后

以上就是负责钻石最近收集整理的关于Linux应用程序显示旋转,linux – 旋转愚蠢的非交互式应用程序的日志的全部内容,更多相关Linux应用程序显示旋转,linux内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(91)

评论列表共有 0 条评论

立即
投稿
返回
顶部