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

Discussion in 'Perl Misc' started by Justin C, Nov 20, 2013.

  1. Justin C

    Justin C Guest

    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.

    --
    Justin C, by the sea.
    Justin C, Nov 20, 2013
    #1
    1. Advertising

  2. Justin C

    Dave Saville Guest

    On Wed, 20 Nov 2013 15:44:54 UTC, Justin C
    <> 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
    Dave Saville, Nov 20, 2013
    #2
    1. Advertising

  3. Justin C

    Justin C Guest

    On 2013-11-20, Christian Winter <> 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::Daemon, 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.
    Justin C, Nov 22, 2013
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. calvin01
    Replies:
    5
    Views:
    16,397
  2. Jean-Paul Calderone
    Replies:
    0
    Views:
    455
    Jean-Paul Calderone
    Mar 20, 2009
  3. Floris Bruynooghe
    Replies:
    1
    Views:
    451
    Floris Bruynooghe
    Mar 24, 2009
  4. Thomas Uehlinger
    Replies:
    0
    Views:
    153
    Thomas Uehlinger
    Feb 8, 2005
  5. Grischa Schuering
    Replies:
    1
    Views:
    512
    David Efflandt
    Sep 30, 2003
Loading...

Share This Page