Hi morgon,

ikegami already said it, but in the module's source you can see that do_stop is the only place unlink is called on the PID file.

Taking a step back though: I understand that your process is something that just runs once briefly and then exits. Aside from the question as to whether you need a PID file in the first place (is your script called multiple times?) and whether you need to delete the PID file at all, I wouldn't really see the task you describe as a continually-running daemon - instead I might just set that up via cron.

Is this something like "dvbdate" (1, 2)? If so, that can be set up to run regularly in the crontab - which by the way also has a @reboot directive for running things once on startup (haven't used that myself but it sounds pretty simple).

If you really want to use an init script (which has the advantage that it can be run immediately on boot and you can control the prerequisites), you could use Daemon::Control's ability to generate an init script for you, and then adapt that to suit your needs. For example, if I use the get_init_file command on your script, I get something like this (edited for brevity):

#!/bin/sh ### BEGIN INIT INFO # Provides: Time from DVB # Required-Start: $syslog $remote_fs # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 ### END INIT INFO` if [ -x /tmp/timeset_daemon.pl ]; then /tmp/timeset_daemon.pl $1 else echo "Required program /tmp/timeset_daemon.pl not found!" exit 1; fi

Then, just replace /tmp/timeset_daemon.pl by whatever command sets the time from the DVB stick, and it'll be run once on boot (and on shutdown, but that shouldn't matter here). Another sample init script is shown in this article, it also shows the usage of the update-rc.d command. You could also teach that script to respect the start|stop|status commands, but since your script isn't really a continually-running daemon, Daemon::Control might not be the optimal way to do that. Or, you can slap a while (1) { my_code_here; sleep($interval) } around your code and you've basically got a daemon.

I just recently started working with chrony to replace ntpd and provide accurate time via a GPS receiver on a Raspberry Pi, and it really was much easier to set up than ntpd. If you're looking into giving your RPi accurate time, then somehow feeding the DVB stick's time into chrony might be something worth investigating.

Hope this helps,
-- Hauke D


In reply to Re: Daemon::Control pid-files by haukex
in thread Daemon::Control pid-files by morgon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.