Re: Creating a Daemon

2003-08-24 Thread Sam Vilain
On Sun, 24 Aug 2003 00:10, sungo wrote;

  su> fork and exit unless DEBUG; # provided of course you have a
  su> DEBUG constant very early in your program. that way, in debug
  su> mode, the program will stay attached and spew its debug
  su> content. otherwise, it will daemonize.

If you're going to ignore the appropriate module, you should at least
also disassociate from the terminal and set a new process session ID:

  use POSIX qw(setsid);
  open STDIN, "/dev/null" or die $!;
  open STDERR, ">&STDOUT" or die $!;
  fork and exit;
  setsid();
  
-- 
Sam Vilain, [EMAIL PROTECTED]

  The flush toilet is the basis of Western civilization.
ALAN COULT



Re: Creating a Daemon

2003-08-24 Thread sungo
Sam Vilain wrote:

If you're going to ignore the appropriate module, you should at least
also disassociate from the terminal and set a new process session ID:
i developed that methodology BEFORE the module even existed so NYEH :)

--
Matt Cashner
http://eekeek.org


Re: Creating a Daemon

2003-08-24 Thread Jake
Thanks, I didn't know about Net::Server::Daemonize.

I've got it working now,

Thanks
Jay
"Rocco Caputo" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Sat, Aug 23, 2003 at 01:05:15PM -0500, Jake wrote:
> > Hi,
> >
> > I want to create a POE server that doesn't block my terminal when I
start
> > it.  I did it with a fork but I haven't seen anyone do it this way so I
> > figure I'm missing something in POE to do it.
> >
> > How am I supposed to build a server that when I start it, I get my
prompt
> > back?
>
> [...]
>
> It's rather easy to daemonize a program, and it's covered in an existing
> CPAN module (Net::Server::Daemonize), so it hasn't been included in POE
> itself.
>
> --
> Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org/




Re: Creating a Daemon

2003-08-23 Thread sungo
Rocco Caputo wrote:
On Sat, Aug 23, 2003 at 01:05:15PM -0500, Jake wrote:

Hi,

I want to create a POE server that doesn't block my terminal when I start
it.  I did it with a fork but I haven't seen anyone do it this way so I
figure I'm missing something in POE to do it.
How am I supposed to build a server that when I start it, I get my prompt
back?


[...]

It's rather easy to daemonize a program, and it's covered in an existing
CPAN module (Net::Server::Daemonize), so it hasn't been included in POE
itself.
a very simple formula is:

fork and exit unless DEBUG; # provided of course you have a DEBUG constant

very early in your program. that way, in debug mode, the program will 
stay attached and spew its debug content. otherwise, it will daemonize.

--
Matt Cashner
http://eekeek.org


Re: Creating a Daemon

2003-08-23 Thread Rocco Caputo
On Sat, Aug 23, 2003 at 01:05:15PM -0500, Jake wrote:
> Hi,
> 
> I want to create a POE server that doesn't block my terminal when I start
> it.  I did it with a fork but I haven't seen anyone do it this way so I
> figure I'm missing something in POE to do it.
> 
> How am I supposed to build a server that when I start it, I get my prompt
> back?

[...]

It's rather easy to daemonize a program, and it's covered in an existing
CPAN module (Net::Server::Daemonize), so it hasn't been included in POE
itself.

-- 
Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org/


Creating a Daemon

2003-08-23 Thread Jake
Hi,

I want to create a POE server that doesn't block my terminal when I start
it.  I did it with a fork but I haven't seen anyone do it this way so I
figure I'm missing something in POE to do it.

How am I supposed to build a server that when I start it, I get my prompt
back?

Thanks
Jay

So far I have:

#!/usr/bin/perl -w

use warnings;
use strict;
$|++;

use POE qw(Component::Server::TCP);

if (!defined(my $child_pid = fork())) {
die "cannot fork $!\n";
}
elsif ($child_pid) {
print "parent $child_pid\n";
}
else {
print "starting server\n";

POE::Component::Server::TCP->new(
Port=> 12345,
ClientInput => \&client_input,
Alias => "quoted",
);

POE::Kernel->run();
exit;
}

sub client_input {
my ($heap, $input) = @_[HEAP, ARG0];
print $input,"\n";
$heap->{client}->put($input);
}