Writing a daemon to start/stop at boot and shutdown.

J

Justin C

I've yet to write the file for /etc/init.d to start and stop my
program, but I don't think I should really go that far before I can
make my program detach itself and be able to stop when called with
'/usr/local/bin/progname stop'.

I've been reading the docs of Daemon::Control, Daemon::Generic and
Proc::Daemon, but I can't get my program to detach - the problem
appears that it never returns from one of the subs. Here's what
doesn't return:

start_program();

sub start_program {
my $server = RPC::Serialized::Server::NetServer->new({
net_server => {port => $port},
rpc_serialized => {
handlers => {
echo => 'My::Echo',
address_lookup => 'My::AddressLookup',
}
},
});
$server->run;
}

The program works in that there is a server listening, and responding
to requests from other servers on the network.

All suggestions gratefully received.


Justin.
 
D

Dave Saville

I've yet to write the file for /etc/init.d to start and stop my
program, but I don't think I should really go that far before I can
make my program detach itself and be able to stop when called with
'/usr/local/bin/progname stop'.

Well the classic C method is to fork yourself having reassigned
STDin/out/err to disconnect from the starting terminal. Why bother
when the start script can just & the program?
 
J

Justin C

Am 20.11.2013 16:44, schrieb Justin C:

It's documented in RPC::Serializd::Server::NetServer, section
"Things you might want to configure", where points (albeit in
slightly roundabout way) to the "background" option of Net::Server.
So somthing along the lines of this should work (untested):

...
my $server = RPC::Serialized::Server::NetServer->new({
net_server => {
port => $port,
background = 1
},


Thank you, Chris, that's spot on. I don't know how I missed that in
the docs, especially seeing as they're so short. Reading, as that
part of the docs suggested, Net::Server docs I've also found how to
set GID and UID for the process - which I thought I was going to
have to do with a separate program to start and stop my daemon. Now
it's all rolled into one, now I've just got to set up the
start|stop|restart process.

Thanks again.


Justin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top