Re: Run something on first start of a service

From: Laurent Bercot <ska-skaware_at_skarnet.org>
Date: Mon, 01 Feb 2021 12:41:15 +0000

>I'm struggling to figure out how to start a particular initialization when a service first comes up (since service startup, system startup, or ever).
>I'm pretty sure it's well documented, but if the question is phrased incorrectly, you can search for a long time.

  Do you mean that the "start" script would only be run once, no matter
how many times the service can die and be restarted later on?
  If so, it's the job of a service manager. Conceptually, "start" is
not really part of the supervised service, it's something separate that
needs to run before your service is first brought up.

  In the s6 world, this would be handled by s6-rc (or anopa). You would
make a oneshot that contains your "start" script, and your longrun
(containing your "run" script, the thing you want supervised) would
depend on the "start" oneshot.

  But if it's not what you mean (and it appears it's not), read below.


>What daemontools-encore does with ./start seems pretty ok - and would be near perfect if it were to wait for ./start to finish before running ./run.

  After reading
  https://untroubled.org/daemontools-encore/supervise.8.html
I understand that ./start is run every time the service is started, not
only the first time, and ./run is only actually executed if ./start
exits 0. Which is a very different approach: "start" is not a
oneshot, but part of the service.
  And if it's part of the service and supposed to be run every time,
then you don't need a separate ./start: it can just as well be part
of the ./run script.

  To emulate this in execline: if -X { ./start } rest-of-run-script
and in shell: set -e ; ./start ; rest-of-run-script


>s6 has a concept for ./finish - so I think a ./start concept is there as well and I just can't find it. Can someone please nudge me on this?

  ./finish has to be separate because it's spawned when ./run dies.
But anything that needs to run *before* ./run can just be integrated
into ./run instead, there's no need for a separate script.

--
  Laurent
Received on Mon Feb 01 2021 - 12:41:15 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:38:49 UTC