I am trying to daemonize a perl process example test to syslog.
1) in the perl script开发者_运维问答 it already log into rotate log file but I would like to log the daemonize for case of when things goes wrong before log get create 2) currently I am doing sudo /usr/sbin/daemonize -u User -a -e /home/users/me/log/log.log /home/users/me/test
It already working but the issue is that the log file will get big and the only way to handle the log file is if daemonize is stop.
So I am trying to log into syslog so I am doing
sudo /usr/sbin/daemonize -u User -a -e /dev/stderr /home/users/me/test | logger
this will have permission error when write to stderr. If I don't run as User it get log fine but for security reason I have to run my daemonize as User.
I am stuck any help is appreciate
my test sub main{ my $i = 0; for($i=0; $i < 10 ; $i++){ print "this is a test " . $i . " \n"; } }
main(@ARG);
Note I also tried the 2>&1 but does not work
You might do better to use Daemon::Daemonize from CPAN or something like it. It allows you to automatically redirect STDOUT and STDERR. It claims to handle all the setpgrp stuff you need.
I think if you combine this with using Sys::Syslog (also from CPAN) you can do all of what you need to do without out relying on /usr/sbin/daemonize and with a little more control over what is actually happening with your program.
You seem to have two distinct problems:
1) Daemonizing your program. 2) Logging to syslog.
Both are problems which are better solved directly in your Perl code. As well as Daemon::Daemonize there is Proc::Daemonize. I don't have an opinion on their relative merits, I've just used Daemon::Daemonize in the past. Either one would get your program running as a daemon.
For writing to syslog, using Sys::Sylog will do the heavy lifting for you. It's not a simple redirect, but it will allow you to send log messages and not worry about log rotation.
精彩评论