admin管理员组文章数量:1402331
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
.
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
.
- 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? – Valery S. Commented Mar 27 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. – M.E. Commented Mar 29 at 23:13
1 Answer
Reset to default 1the 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.
本文标签: daemonImplementing a rc script to launch a custom serviceStack Overflow
版权声明:本文标题:daemon - Implementing a rc script to launch a custom service - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744351339a2602068.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论