如何在 FreeBSD 中调试 rc.d 脚本?

How to debug rc.d scripts in FreeBSD?

我的

中有一个 bash 脚本
/usr/local/etc/rc.d/

应该运行python脚本。我 运行 布什脚本

service script_name start

然后什么也没发生。我如何调试 rc.d 脚本?我怎么知道发生了什么?

FreeBSD rc.d 系统需要 /bin/sh 脚本。因此 sh 调试技术适用于此。例如,打印带有 'set -x''set -v'

的语句
shell> cat script.sh
#!/bin/sh
set -x
set -v
...

下面是如何使用服务命令

启动my_app的简单示例
shell> cat /scratch/my_app
#!/usr/local/bin/bash
case  in
     start)
        echo "Start my_app"
        exit
        ;;
     stop)
        echo "Stop my_app"
        exit
        ;;
esac
shell> cat /usr/local/etc/rc.d/my_app
#!/bin/sh
#set -x
#set -v
. /etc/rc.subr
name="my_app"
rcvar=my_app_enable
load_rc_config $name
start_cmd=${name}_start
stop_cmd=${name}_stop
my_app_start() {
    /scratch/my_app start
}
my_app_stop() {
    /scratch/my_app stop
}
run_rc_command ""
shell> grep my_app /etc/rc.conf
my_app_enable="YES"
shell> service my_app start
Start my_app

详情见

也引用自doc

The manual pages rc(8), rc.subr(8), and rcorder(8) document the rc.d components in great detail. You cannot fully use the rc.d power without studying the manual pages and referring to them while writing your own scripts.