shell - 如何在 FreeBSD 中调试 rc.d 脚本?
问题描述
我有一个 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
...
下面是一个简单的例子,说明如何使用service命令启动my_app
shell> cat /scratch/my_app
#!/usr/local/bin/bash
case $1 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 "$1"
shell> grep my_app /etc/rc.conf
my_app_enable="YES"
shell> service my_app start
Start my_app
详细信息可在
还引用了文档
手册页 rc(8)、rc.subr(8) 和 rcorder(8) 详细记录了 rc.d 组件。如果不研究手册页并在编写自己的脚本时参考它们,就无法充分利用 rc.d 的力量。
推荐阅读
- python - 在 Airflow 上连接超时 (110) 期间的 net-Lib 错误
- c# - 查询/命令中的 Mediatr 库通用参数
- ethereum - 我的 Uniswap 分叉不会显示我的流动资金池
- vue-formulate - Vue制定FormateForm问题
- javascript - 从一个对象数组获取或复制值到另一个对象数组
- ios - iOS上的Swift:全局队列上的任务将第二个任务添加到主队列以显示UIImageView,它不显示
- java - checkstyle插件在maven包上抛出major.minor 52错误,开发环境问题
- css - 用 css 和 vue 形成图形
- javascript - 如何在 react Native fetch 中创建自定义警报?
- c# - 如何获得总 GPU RAM(超过 4gb 内存)?