> > 
> > I have a similar situation and have the same question. are 
> you running
> > the script as a daemon or just using 'while {..} sleep' 
> sort of thing?
> 
> Just the while(). How does one make it a daemon?

the easiest is way is to use Proc::Daemon. also perldoc -f fork is helpful.
take a look at drieux's example (from perl list) :
http://www.wetware.com/drieux/pbl/Sys/daemon1.txt

if you would rather roll your own here is a very simple example:
use POSIX qw(setsid);
umask 0;
open STDIN, '/dev/null' or die "blah... $!";
open STDOUT, '>/tmp/somelog_or_dev_null' or die "blah... $!";
open STDERR, '>&STDOUT' or die "Can't write to /dev/null: $!";
defined(my $pid = fork)  or die "Can't fork: $!";
exit if $pid;
setsid()  or die "Can't start a new session: $!";

while(1) {
   do stuff....;
   sleep $time;
}

-----

or you can just ad another daemon script to your /etc/rc.d... startup stuff
in *nix:
like :
#!/sbin/sh

case "$1" in
'start')
        if [ -x /bin/YOURSCRIPT.pl ]
        then
                /bin/YOURSCRIPT.pl -s # maybe your start tag
        fi
        ;;

'stop')
        if [ -x /bin/YOURSCRIPT.pl]
        then
                /bin/YOURSCRIPT.pl -k # stop tag
        fi
        ;;
*)
        echo "huh ??"
        ;;

esac



Reply via email to