"epilogue" script?
Ian Smith
smithi at nimnet.asn.au
Sat Jan 30 14:19:34 UTC 2016
In freebsd-questions Digest, Vol 608, Issue 6, Message: 20
On Sat, 30 Jan 2016 11:59:55 +0100 Polytropon <freebsd at edvax.de> wrote:
> On Fri, 29 Jan 2016 16:35:07 -0600 (CST), Valeri Galtsev wrote:
> > Dear Experts,
> >
> > How does one create "epoligue" script in FreeBSD. By "epoligue" script
> > script I mean here the script that is executed after everything described
> > in /etc/rc.conf is done (services started, interfaces initialized etc.). I
[..]
> a) RC framework: rc.d
[..]
> See "man rc" and "man rcorder" for details.
Sure, if installing new daemon processes, this is the way to go.
OTOH, for scripts needing running just once at startup, and/or possibly
once at shutdown:
> b) rc.local and rc.shutdown.local
>
> Those files, located in /etc, are "real" shell scripts that will be
> executed "quite late", but not at the lastest possible point. Here
> is an example:
>
> Creating and/or trimming log files.
> Starting syslogd.
> No core dumps found.
> Additional ABI support: linux.
> Starting named.
> Clearing /tmp (X related).
> Starting local daemons: activity. <--- /etc/rc.local runnung now!
> Starting ntpd.
> Starting dhcpd.
> Starting cupsd.
> Configuring syscons: keymap keyrate font8x16 font8x14 font8x8.
> Starting sshd.
> Starting cron.
> Starting inetd.
>
> As you can see, there are other services started _after_ rc.local has
> been run. This might cause a problem for you when you need those services
> running.
Yes. I was preparing to post a very similar segment, which also wrote
something to stdout when /etc/rc.local was sourced - so thanks!
> See from "man rc":
>
> The rc.local script contains commands which are pertinent only
> to a specific site. Typically, the /usr/local/etc/rc.d/ mechanism
> is used instead of rc.local these days but if you want to use rc.local,
> it is still supported. In this case, it should source /etc/rc.conf
> and contain additional custom startup code for your system. The best
> way to handle rc.local, however, is to separate it out into rc.d/
> style scripts and place them under /usr/local/etc/rc.d/. The rc.conf
> file contains the global system configuration information referenced
> by the startup scripts, while rc.conf.local contains the local system
> configuration. See rc.conf(5) for more information.
>
> So this might not be "stable".
It's stable; been there since the dawn of time and isn't going away :)
Valeri, picking up on the above, if you run, say:
% rcorder /etc/rc.d/* /usr/local/etc/rc.d/* | less
and find 'local', you'll see where /etc/rc.d/rc/local runs, and that's
what runs (sources inline) /etc/rc.local on startup (or in reverse order
on shutdown, /etc/rc.shutdown.local)
You only need source /etc/rc.conf if using rc.conf variables of course.
> c) /etc/rc hook
Totally agree; don't go anywhere near there :)
> > I'm left clueless. As Linux refugee I have a feeling that this is doable
> > without a hack, like making init script, and having "sleep ..." in it
> > before payload. In Linux this is done using /etc/rc.d/rc.local which is
> > executed _after_ everything else is done.
>
> As you can see, an rc.d style mechanism will probably be the best
> solution here, except you are fully sure that the time when rc.local
> is run you will be provided with everything you need.
We don't really know what Valeri wants to run, and whether it's one or
more daemons, maybe including long-running background scripts, that may
need start|stop|status control via service(8), or whether it's more
simply one or more one-off tasks to be run sometime after startup?
If the latter, there's nothing at all wrong with starting a script that
runs in the background including sleep(1), so long as you don't have an
inline sleep that would just pause the whole startup. Something like ..
/etc/rc.local: (do not use exit or return, this runs within /etc/rc)
wait=20
( sleep $wait # sleep 5 should usually be more than enough
# perhaps wait for something or other to be running or exist?
# do stuff, maybe including starting further bg jobs, whatever ..
) &
echo "my rc.local stuff starts in $wait seconds"
cheers, Ian
More information about the freebsd-questions
mailing list