Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Writing a daemon to start/stop at boot and shutdown.

Reply
Thread Tools

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

 
 
Justin C
Guest
Posts: n/a
 
      11-20-2013

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:aemon, 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.

--
Justin C, by the sea.
 
Reply With Quote
 
 
 
 
Dave Saville
Guest
Posts: n/a
 
      11-20-2013
On Wed, 20 Nov 2013 15:44:54 UTC, Justin C
<(E-Mail Removed)> wrote:

> 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?

--
Regards
Dave Saville
 
Reply With Quote
 
 
 
 
Justin C
Guest
Posts: n/a
 
      11-22-2013
On 2013-11-20, Christian Winter <(E-Mail Removed)> wrote:
> Am 20.11.2013 16:44, schrieb 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:aemon, but I can't get my program to detach - the problem
>> appears that it never returns from one of the subs.

>
> 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.

--
Justin C, by the sea.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
writing java daemon server: start and stop calvin01 Java 5 05-30-2009 05:39 PM
Re: PEP 3143: Standard daemon process library (was: Writing awell-behaved daemon) Floris Bruynooghe Python 1 03-24-2009 02:58 PM
Re: PEP 3143: Standard daemon process library (was: Writing awell-behaved daemon) Jean-Paul Calderone Python 0 03-20-2009 01:02 PM
[ANN] Daemons 0.0.1: control your daemon scripts with start/stop commands Thomas Uehlinger Ruby 0 02-08-2005 12:35 PM
get messages from background task to log file (start-stop-daemon with perl script stderr) Grischa Schuering Perl Misc 1 09-29-2003 11:53 PM



Advertisments