Re: rcorder question

From: Milan Obuch <freebsd-hackers_at_dino.sk>
Date: Wed, 14 Feb 2024 21:54:33 UTC
On Tue, 13 Feb 2024 11:27:44 +0000
David Chisnall <theraven@FreeBSD.org> wrote:

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

Thanks for pointer, I created simple script and it looks like it works
as expected:

--- 8< ---------------------------------

#!/bin/sh

# PROVIDE: scex
# REQUIRE: socat

. /etc/rc.subr

name=scex
rcvar=scex_enable 

start_cmd="${name}_start"
stop_cmd=":"

load_rc_config $name 
: ${scex_enable:=no} 

scex_start()
{
        /usr/local/bin/init_program
        /usr/local/bin/main_program /dev/cuaV0 &
}

run_rc_command "$1"

--- 8< ---------------------------------

For it to run, I added to /etc/rc.conf:

scex_enable="YES"

There is no stop instruction, but it is just enough for my purpose at
the moment. Is there anything which would be recommended to change?

Regards,
Milan