From nobody Tue Feb 13 11:27:44 2024 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TYzb14dBhz5B4hy for ; Tue, 13 Feb 2024 11:27:57 +0000 (UTC) (envelope-from theraven@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TYzb13nm9z4257; Tue, 13 Feb 2024 11:27:57 +0000 (UTC) (envelope-from theraven@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707823677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gbfTKQR/achxYrMskodWLdXgmp+dG/o74lC8oTe77Y8=; b=vKv1rKVK46qNOIKvD2oCm8RPP1WEcrqlzF2OL5Q5GbEXOV+uTadkNFcNkQzatBmM92F776 J8Tjh46M4lO07DEBH7CS4Vq0eFjA6BVhE7cplzotq/A5521o1MPLCRYoslFfaQFpo4ybiQ jjMrJ0SN+n41zWDq+lyxielV7aAzsVyOWpXUxyTQ//BJYuNXEIjvJsmQ52lt2G8YPUaHuo sUd0s0EJgAc+CmW6nGne+StRDt/+L64C7EFQeTFBFXmePWV+YR6U0vomJSpL4oZ5F1OH8G RkA1UmUxSFZip43nLCsbt+Wqj8U5+CiuJ4US5YDd931LnseMYmQZLgF4Ycu9mA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1707823677; a=rsa-sha256; cv=none; b=ssdPGAE6TjedXgfmewfmM9vvs6DVhZnV0z+Ns+3rhAUjW3tqjnP9BJT0hrJkxmeZwXvGKl XkVMOTjC+6O0Rl+NTTo9NBP7I1d4L7R1O3vMNZenL/rVpnjwkNEW6fg6lGftNJSbBuOSTI OMcZLMGNxMOtMbkeGSADdEp/iRpBlAPcuoDWtYLRmrGsYjtYg0dwM7OQ5O4gZsJPCQlseT nqePjt3+aDSU3iABcpfEf3p6f0SvOL4jDfXmLc6gKwsW4ILCEWGXdV+5vmkWkY/rKG4Izf vooQ7DSPxdgO0SyTSSMMf27gslhMIDIMHpLNNWiQ46Tp4Xp2C3lVlED3M5GUZQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707823677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gbfTKQR/achxYrMskodWLdXgmp+dG/o74lC8oTe77Y8=; b=oQ6P4b8OR0OmLyTES3RXgb88BzIBEeUnfgzlglH5SvZqGLr/DxIBYr3iU4Ai87P/6xWLPF mrQ189b9059PPc5baB4gSJYLalXQ5W2dlnuiA/xZEnlVad2Krq8vx62HZB5gqkmj8uXzE1 87bQgxvp8MWIP1jBNszlZ09Qb+7GhW/g+8h6aWs+keMdD5T8W9+pCJlbihXcGseSgWZ0Mq z/6K37RzMK/I1WrCC8hsYIa56Ku6ExMKWMI0D8xn6zT4gzj/+EGGDYJGVwa3YZz8wiDOOu FwT694CX80USukCqXQU/gnVKSEatqAcVKhxT9ck20yFUUB+DIFKEUXmIqj0hxA== Received: from smtp.theravensnest.org (smtp.theravensnest.org [45.77.103.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: theraven) by smtp.freebsd.org (Postfix) with ESMTPSA id 4TYzb12Y7gz14Vp; Tue, 13 Feb 2024 11:27:57 +0000 (UTC) (envelope-from theraven@FreeBSD.org) Received: from smtpclient.apple (host86-131-178-116.range86-131.btcentralplus.com [86.131.178.116]) by smtp.theravensnest.org (Postfix) with ESMTPSA id 04268105BF; Tue, 13 Feb 2024 11:27:55 +0000 (GMT) From: David Chisnall Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_33E71CC9-4F79-4880-9D96-7E87BBEBCE07" List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.400.31\)) Subject: Re: rcorder question Date: Tue, 13 Feb 2024 11:27:44 +0000 In-Reply-To: <20240213121936.2c0fc4c0@zeta.dino.sk> Cc: freebsd-hackers@freebsd.org To: Milan Obuch References: <20240213121936.2c0fc4c0@zeta.dino.sk> X-Mailer: Apple Mail (2.3774.400.31) --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 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 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:



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).  

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=3D"YES"

and = /usr/local/etc/socat-instances.conf:

[moxa]
daemonuser=3Drootflags=3D"PTY,link=3D/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


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