Re: rcorder question

From: David Chisnall <theraven_at_FreeBSD.org>
Date: Tue, 13 Feb 2024 11:27:44 UTC
A quick look at teh socat RC script suggests that it contains this line:

# PROVIDE: socat

You should be able to simply add:

# REQUIRE: socat

And your service will start after socat.  But to do that you need to not use `rc.local` and instead provide a separate RC script.  There are some examples in the man page and the web site:

https://man.freebsd.org/cgi/man.cgi?query=rc

https://docs.freebsd.org/en/articles/rc-scripting/

In general, I wouldn’t use rc.local for anything that has dependencies outside of rc.local (or, in fact, for anything).  If you have a service that needs to be started after something else, then put it in etc/rc.d and enable it via rc.conf (or, ideally, something in rc.conf.d).  If you want to move it to a different machine, you now just need to copy the files across rather than extract bits of config files (this also makes it easier to create packages for it, if you wish to automate installation).  

David

> On 13 Feb 2024, at 11:19, Milan Obuch <freebsd-hackers@dino.sk> wrote:
> 
> Hi,
> 
> I am trying to solve an issue how to start local scripts in proper
> order (for my application). Basically, I use net/socat port to create
> virtual serial port used to read data from some device (just simple
> character stream, with CR LF terminating the record with fixed position
> items).
> 
> I configured socat instance in /etc/rc.conf:
> 
> socat_enable="YES"
> 
> and /usr/local/etc/socat-instances.conf:
> 
> [moxa]
> daemonuser=root
> flags="PTY,link=/dev/cuaV0,rawer,wait-slave TCP4:192.168.x.y:5000"
> 
> It works - on boot, designated device is contacted and virtual serial
> port is created.
> 
> For starting program consuming data, I put following in /etc/rc.local:
> 
> /usr/local/xxx/yyy/zzz /dev/cuaV0 &
> 
> If started manually after boot up, it works as intended, but here is
> the problem, it is started before socat, because
> 
> # rcorder /etc/rc.d/* /usr/local/etc/rc.d/* | grep local
> /etc/rc.d/mountcritlocal
> /usr/local/etc/rc.d/dbus
> /etc/rc.d/local
> /usr/local/etc/rc.d/socat
> 
> (some more entries edited out, not relevant to the issue).
> 
> So the question is how could I alter boot order to start /etc/rc.local
> *after* socat instance. I tried, altering /etc/rc.d/local line (naively)
> 
> # REQUIRE: DAEMON
> 
> to
> 
> # REQUIRE: DAEMON socat
> 
> but this does not work, because then rcorder reports
> 
> rcorder: Circular dependency on file `/usr/local/etc/rc.d/socat'.
> rcorder: Circular dependency on provision `LOGIN': /etc/rc.d/LOGIN -> /etc/rc.d/local -> /usr/local/etc/rc.d/socat -> /etc/rc.d/LOGIN.
> rcorder: `/usr/local/etc/rc.d/socat' was seen in circular dependencies for 1 times.
> rcorder: `/etc/rc.d/local' was seen in circular dependencies for 1 times.
> rcorder: `/etc/rc.d/LOGIN' was seen in circular dependencies for 1 times.
> rcorder: `/usr/local/etc/rc.d/socat' was seen in circular dependencies for 1 times.
> 
> I did some more, but no success yet... Anybody to offer some hint I can
> try?
> 
> Regards,
> Milan
>