How to debug rc.d scripts in FreeBSD?

狂风中的少年 提交于 2019-12-02 10:39:58

问题


I have a bash script in my

/usr/local/etc/rc.d/

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

service script_name start

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


回答1:


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.

# cat script.sh

#!/bin/sh
set -x
set -v
...

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

# cat /scratch/my_app

#!/usr/local/bin/bash
case $1 in
     start)
         echo "Start my_app"
         exit
         ;;
     stop)
        echo "Stop my_app"
        exit
        ;;
esac

# 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"

# grep my_app /etc/rc.conf

my_app_enable="YES"

# service my_app start

Start my_app

Details are available in Practical rc.d scripting in BSD and The Design and Implementation of the NetBSD rc.d system.

Also quoting from the 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.



来源:https://stackoverflow.com/questions/51833364/how-to-debug-rc-d-scripts-in-freebsd

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!