0

I have a proprietary service inside a FreeBSD 14 jail that I launch as follows:

/opt/bin/rserver_tcp >> /var/log/rserver_tcp.log 2>&1

This is a blocking service which uses stdout and stderr. So it does not return to command line unless you press CONTROL+C or kill the process.

I am trying to write a custom rc script to launch this.

The script also requires /usr/local/bin in the PATH. So I use env in the /etc/rc.d script accordingly. This is what I have tried so far:

/etc/rc.d/rserver_tcp

#!/bin/sh
# PROVIDE: rserver_tcp
# REQUIRE: DAEMON
# KEYWORD: shutdown
. /etc/rc.subr
name="rserver_tcp"
rcvar="rserver_tcp_enable"
desc="rserver_tcp service"
pidfile="/var/run/rserver_tcp.pid"
start_cmd="rserver_tcp_start"
stop_cmd="rserver_tcp_stop"
rserver_tcp_start() {
 echo "Starting rserver_tcp..."
 # Start the daemon in the background and redirect output properly.
 daemon -p "${pidfile}" env PATH="$PATH:/usr/local/bin" /opt/bin/rserver_tcp >> /var/log/rserver_tcp.log 2>&1
}
rserver_tcp_stop() {
 echo "Stopping rserver_tcp..."
 if [ -f "${pidfile}" ]; then
 kill "$(cat ${pidfile})" && rm -f "${pidfile}"
 else
 echo "PID file not found; is rserver_tcp running?"
 fi
}
load_rc_config "${name}"
: ${rserver_tcp_enable:=no}
run_rc_command "1ドル"

It works perfectly when I start/stop manually:

# service rserver_tcp onestart
Starting rserver_tcp...
# service rserver_tcp onestop
Stopping rserver_tcp...

However, when I do this in /etc/rc.conf:

rserver_tcp_start="yes"

then when I try start the jail from the server that contains the jail it keeps forever starting and it never returns to shell.

It works normally if I remove that line from /etc/rc.conf.

lcheylus
2,6972 gold badges19 silver badges35 bronze badges
asked Mar 21, 2025 at 13:06
2
  • 1. First, SO is about programming, not OS features and settings, hence it seems somebody downvote your question 2. If you have to add a process from /usr/local/bin you have to use /usr/local/etc/rc.d instead of /etc/rc.d. which is reserved to systemland, not userland. 3. You speak about a jail but do not provide anything about this. 4. daemon if a utility that fork the process you provide and detach from terminal. 5. you have to run rcorder to see the order when you program starts and if it start with everything needed for its purpose (networking, ...). 6. Why not reading the handbook? Commented Mar 27, 2025 at 0:04
  • thanks for your comments. rc scripts (as in /etc/rc, /etc/rc.d/*, or /etc/rc.local) are shell scripts, so, writing an rc script is writing code, and thus it's a form of programming—even if it's usually more configuration-oriented than algorithmically interesting. Commented Mar 29, 2025 at 23:13

1 Answer 1

1

the service uses networking, hence the rc script must reflect this depedency.

Modifying the following line to the rc.d script fixed the issue:

# REQUIRE: networking

Manually launching the script was working fine since networking was already in place.

answered Mar 21, 2025 at 17:17
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.