Attempt to write an rc.d script not working

Rocky Hotas rockyhotas at post.com
Wed Jan 20 15:33:38 UTC 2021


Hello!
I'm following this thorough tutorial:

 <https://www.freebsd.org/doc/en_US.ISO8859-1/articles/rc-scripting/>

To make some tests, I tried to create a script to enable a very simple
service: an nc server listening on a custom port.

Attempt number 1, file /etc/rc.d/dummy:

#!/bin/sh

. /etc/rc.subr

name=dummy
rcvar=dummy_enable

command="/usr/bin/nc"
command_args="> /tmp/dummy_out 2>&1"

pidfile="/var/run/${name}.pid"

load_rc_config $name
run_rc_command "$1"

I also added in /etc/rc.conf these lines:

dummy_enable="YES"
dummy_flags="-l 59002"

Then, as root:

# service dummy start
Starting dummy.

The prompt does not return. The service seems to be started, but it only
writes /tmp/dummy_out file when a FreeBSD nc client is connected, not
for example with a Linux nc client (maybe this issue is not related to
rc.d).

Then, I made another attempt trying to embed the arguments `-l 59002'
inside the rc.d script itself.

Attempt number 2, file /etc/rc.d/dummy2:

#!/bin/sh

. /etc/rc.subr

name=dummy2
rcvar=dummy2_enable

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

load_rc_config $name
: ${dummy_enable:=no}

dummy2_start()
{
        nc -l 59002
}

run_rc_command "$1"

In /etc/rc.conf I added the line:

dummy2_enable="YES"

Trying again, as root, `service dummy2 start', it prints nothing this
time, and the prompt does not return.

What am I doing wrong?

Thank you anyway!

Rocky


More information about the freebsd-questions mailing list