我遇到了以下脚本,有些东西我无法完全理解
#!/bin/sh /etc/rc.common
# Copyright (C) 2006-2011 OpenWrt.org
START=50
start() {
mkdir -m 0755 -p /var/run/vsftpd
service_start /usr/sbin/vsftpd
}
stop() {
service_stop /usr/sbin/vsftpd
}
'/etc/rc.common' 在这里如何使用?
这是 rc.common 的内容
#!/bin/sh
# Copyright (C) 2006-2011 OpenWrt.org
. $IPKG_INSTROOT/lib/functions.sh
. $IPKG_INSTROOT/lib/functions/service.sh
initscript=$1
action=${2:-help}
shift 2
start() {
return 0
}
stop() {
return 0
}
reload() {
return 1
}
restart() {
trap '' TERM
stop "$@"
start "$@"
}
boot() {
start "$@"
}
shutdown() {
stop
}
disable() {
name="$(basename "${initscript}")"
rm -f "$IPKG_INSTROOT"/etc/rc.d/S??$name
rm -f "$IPKG_INSTROOT"/etc/rc.d/K??$name
}
enable() {
name="$(basename "${initscript}")"
disable
[ -n "$START" -o -n "$STOP" ] || {
echo "/etc/init.d/$name does not have a START or STOP value"
return 1
}
[ "$START" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}"
[ "$STOP" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/K${STOP}${name##K[0-9][0-9]}"
}
enabled() {
name="$(basename "${initscript}")"
[ -x "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" ]
}
depends() {
return 0
}
help() {
cat <<EOF
Syntax: $initscript [command]
Available commands:
start Start the service
stop Stop the service
restart Restart the service
reload Reload configuration files (or restart if that fails)
enable Enable service autostart
disable Disable service autostart
$EXTRA_HELP
EOF
}
. "$initscript"
ALL_COMMANDS="start stop reload restart boot shutdown enable disable enabled depends ${EXTRA_COMMANDS}"
list_contains ALL_COMMANDS "$action" || action=help
[ "$action" = "reload" ] && action='eval reload "$@" || restart "$@" && :'
$action "$@"
希望你们中的一些人能对此有所了解。谢谢!
PS:我不太明白的另一件事是如何通过简单地将函数名称附加到启动脚本的完整路径来调用脚本中的函数。例如,'/etc/init.d/vsftpd test' 将在 /etc/init.d/vsftpd 或 /etc/rc.common 中执行一个名为 'test' 的函数。但如果 'test' 函数在启动脚本和/etc/rc.common,前者中的函数会运行,而rc.common中的函数不会。
还有,为什么不
'[ "$action" = "reload" ] && action='eval reload "$@" || restart "$@" && :'
简单地写成
'[ "$action" = "reload" ] && action='eval reload "$@" || restart "$@"'
谢谢!