【问题标题】:How to debug rc.d scripts in FreeBSD?如何在 FreeBSD 中调试 rc.d 脚本?
【发布时间】:2019-01-20 20:02:44
【问题描述】:

我的

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

应该运行 python 脚本。我使用

运行布什脚本
service script_name start

然后什么都没有发生。我怎样才能调试那个 rc.d 脚本?我怎么知道发生了什么事?

【问题讨论】:

    标签: shell freebsd rc.d


    【解决方案1】:

    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
    

    详情可见

    同时引用doc

    手册页 rc(8)、rc.subr(8) 和 rcorder(8) 详细记录了 rc.d 组件。如果不研究手册页并在编写自己的脚本时参考它们,您将无法充分利用 rc.d 的力量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-15
      • 2021-01-02
      • 2012-08-13
      • 2014-09-23
      • 2012-02-26
      • 2010-09-15
      • 2015-07-23
      • 2021-04-05
      相关资源
      最近更新 更多