如何在FreeBSD中调试rc.d脚本? [英] How to debug rc.d scripts in FreeBSD?

查看:199
本文介绍了如何在FreeBSD中调试rc.d脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的bash脚本中有

/usr/local/etc/rc.d/

应运行python脚本.我用

that should run python script. I run the bush script with

service script_name start

,什么都没有发生.我该如何调试rc.d脚本?我怎么知道发生了什么事?

and nothing happens at all. How could i debug that rc.d script? How could i know what is going on?

推荐答案

FreeBSD rc.d 系统要求使用/bin/sh 脚本.因此, sh 调试技术在这里适用.例如,使用'set -x''set -v'

FreeBSD rc.d system expects /bin/sh scripts. Hence sh debugging techniques apply here. For example, printing the statements with 'set -x' and 'set -v'

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

下面是一个简单的示例,说明如何使用 service 命令启动 my_app

Below is a simple example of how to start my_app with the service command

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

详细信息位于

  • Practical rc.d scripting in BSD
  • The Design and Implementation of the NetBSD rc.d system.

还引用了 doc

手册页rc(8),rc.subr(8)和rcorder(8)详细介绍了rc.d组件.如果不学习手册页并在编写自己的脚本时对其进行引用,则无法完全使用rc.d功能.

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.

这篇关于如何在FreeBSD中调试rc.d脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆