Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 Feb 2024 11:27:44 +0000
From:      David Chisnall <theraven@FreeBSD.org>
To:        Milan Obuch <freebsd-hackers@dino.sk>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: rcorder question
Message-ID:  <B9DB6A7C-8412-40EC-B8C4-98A8C731D597@FreeBSD.org>
In-Reply-To: <20240213121936.2c0fc4c0@zeta.dino.sk>
References:  <20240213121936.2c0fc4c0@zeta.dino.sk>

next in thread | previous in thread | raw e-mail | index | archive | help

--Apple-Mail=_33E71CC9-4F79-4880-9D96-7E87BBEBCE07
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=utf-8

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=3Drc

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

In general, I wouldn=E2=80=99t 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). =20

David

> On 13 Feb 2024, at 11:19, Milan Obuch <freebsd-hackers@dino.sk> wrote:
>=20
> Hi,
>=20
> 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).
>=20
> I configured socat instance in /etc/rc.conf:
>=20
> socat_enable=3D"YES"
>=20
> and /usr/local/etc/socat-instances.conf:
>=20
> [moxa]
> daemonuser=3Droot
> flags=3D"PTY,link=3D/dev/cuaV0,rawer,wait-slave TCP4:192.168.x.y:5000"
>=20
> It works - on boot, designated device is contacted and virtual serial
> port is created.
>=20
> For starting program consuming data, I put following in /etc/rc.local:
>=20
> /usr/local/xxx/yyy/zzz /dev/cuaV0 &
>=20
> If started manually after boot up, it works as intended, but here is
> the problem, it is started before socat, because
>=20
> # 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
>=20
> (some more entries edited out, not relevant to the issue).
>=20
> 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)
>=20
> # REQUIRE: DAEMON
>=20
> to
>=20
> # REQUIRE: DAEMON socat
>=20
> but this does not work, because then rcorder reports
>=20
> 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.
>=20
> I did some more, but no success yet... Anybody to offer some hint I =
can
> try?
>=20
> Regards,
> Milan
>=20


--Apple-Mail=_33E71CC9-4F79-4880-9D96-7E87BBEBCE07
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=utf-8

<html><head><meta http-equiv=3D"content-type" content=3D"text/html; =
charset=3Dutf-8"></head><body style=3D"overflow-wrap: break-word; =
-webkit-nbsp-mode: space; line-break: after-white-space;">A quick look =
at teh socat RC script suggests that it contains this =
line:<div><br></div><div><div># PROVIDE: =
socat</div><div><br></div><div>You should be able to simply =
add:</div><div><br></div><div>#&nbsp;<span style=3D"font-size: =
1.1em;">REQUIRE: socat</span></div><div><span style=3D"font-size: =
1.1em;"><br></span></div><div><span style=3D"font-size: 1.1em;">And your =
service will start after socat. &nbsp;But to do that you need to not use =
`rc.local` and instead provide a separate RC script. &nbsp;There are =
some examples in the man page and the web site:</span></div><div><span =
style=3D"font-size: 1.1em;"><br></span></div><div><a =
href=3D"https://man.freebsd.org/cgi/man.cgi?query=3Drc">https://man.freebs=
d.org/cgi/man.cgi?query=3Drc</a></div><div><br></div><div><a =
href=3D"https://docs.freebsd.org/en/articles/rc-scripting/">https://docs.f=
reebsd.org/en/articles/rc-scripting/</a></div><div><br></div><div>In =
general, I wouldn=E2=80=99t use rc.local for anything that has =
dependencies outside of rc.local (or, in fact, for anything). &nbsp;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). &nbsp;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). &nbsp;</div><div><span style=3D"font-size: =
1.1em;"><br></span></div><div><span style=3D"font-size: =
1.1em;">David</span></div><div><br><blockquote type=3D"cite"><div>On 13 =
Feb 2024, at 11:19, Milan Obuch &lt;freebsd-hackers@dino.sk&gt; =
wrote:</div><br class=3D"Apple-interchange-newline"><div><div>Hi,<br><br>I=
 am trying to solve an issue how to start local scripts in =
proper<br>order (for my application). Basically, I use net/socat port to =
create<br>virtual serial port used to read data from some device (just =
simple<br>character stream, with CR LF terminating the record with fixed =
position<br>items).<br><br>I configured socat instance in =
/etc/rc.conf:<br><br>socat_enable=3D"YES"<br><br>and =
/usr/local/etc/socat-instances.conf:<br><br>[moxa]<br>daemonuser=3Droot<br=
>flags=3D"PTY,link=3D/dev/cuaV0,rawer,wait-slave =
TCP4:192.168.x.y:5000"<br><br>It works - on boot, designated device is =
contacted and virtual serial<br>port is created.<br><br>For starting =
program consuming data, I put following in =
/etc/rc.local:<br><br>/usr/local/xxx/yyy/zzz /dev/cuaV0 &amp;<br><br>If =
started manually after boot up, it works as intended, but here is<br>the =
problem, it is started before socat, because<br><br># rcorder =
/etc/rc.d/* /usr/local/etc/rc.d/* | grep =
local<br>/etc/rc.d/mountcritlocal<br>/usr/local/etc/rc.d/dbus<br>/etc/rc.d=
/local<br>/usr/local/etc/rc.d/socat<br><br>(some more entries edited =
out, not relevant to the issue).<br><br>So the question is how could I =
alter boot order to start /etc/rc.local<br>*after* socat instance. I =
tried, altering /etc/rc.d/local line (naively)<br><br># REQUIRE: =
DAEMON<br><br>to<br><br># REQUIRE: DAEMON socat<br><br>but this does not =
work, because then rcorder reports<br><br>rcorder: Circular dependency =
on file `/usr/local/etc/rc.d/socat'.<br>rcorder: Circular dependency on =
provision `LOGIN': /etc/rc.d/LOGIN -&gt; /etc/rc.d/local -&gt; =
/usr/local/etc/rc.d/socat -&gt; /etc/rc.d/LOGIN.<br>rcorder: =
`/usr/local/etc/rc.d/socat' was seen in circular dependencies for 1 =
times.<br>rcorder: `/etc/rc.d/local' was seen in circular dependencies =
for 1 times.<br>rcorder: `/etc/rc.d/LOGIN' was seen in circular =
dependencies for 1 times.<br>rcorder: `/usr/local/etc/rc.d/socat' was =
seen in circular dependencies for 1 times.<br><br>I did some more, but =
no success yet... Anybody to offer some hint I =
can<br>try?<br><br>Regards,<br>Milan<br><br></div></div></blockquote></div=
><br></div></body></html>=

--Apple-Mail=_33E71CC9-4F79-4880-9D96-7E87BBEBCE07--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?B9DB6A7C-8412-40EC-B8C4-98A8C731D597>