NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: rc.local nightmare



On Sun, 29 Oct 2023, Ramiro Aceves wrote:

if [ -x /root/nettest ]; then
	/root/nettest &
fi


Redirect the output of your script somewhere and then it shoould be OK:

```
if [ -x /root/nettest ]; then
	/root/nettest >/root/nettest.log 2>&1 &
fi
```

(Or, use logger(1) on all output within the script.)

What's happening here can be understood if you look at the 2nd last
line of /etc/rc which is:

```
rc_real_work "$@" 2>&1 | rc_postprocess
```

The rc_real_work() function runs all the rc scripts in /etc/rc.d/
including /etc/rc.local (via /etc/rc.d/local), and _all_ output is,
as you can see, piped to rc_postprocess()

When all the scripts finish, /etc/rc exits, and so does the RHS of
that pipeline ie. whatever's running rc_postprocess(). So, anything
started by rc_real_work() will get a SIGPIPE as soon as it tries
to write stuff to its stdout/stderr.

The nohup command also didn't work for the same reason. The nohup
man-page says:

	If the standard output is a terminal, the standard output
	is appended to the file nohup.out in the current directory.
	If standard error is a terminal, it is directed to the same
	place as the standard output.

Well, here the output of _all_ the scripts is a pipe, so nohup
doesn't redirect the output of your command into a nohup.out file
and here too it gets a SIGPIPE.

HTH,

-RVP


Home | Main Index | Thread Index | Old Index