影院平台搭建 - (9)来谈谈service命令

自从换到flash media server,就有一个很古怪的问题。系统启动后,fms是启动起来了的,看netstat -ntpl也可以看到端口监听,从连接时也可以看到确实连接成功,但就始终无法播放之前能顺利播放的东西。一定要到它目录下执行一下./server restart才可以。
这个问题困扰了我很久,虽然其实这不算是个真正的问题,在/etc/rc中添加一句就可以了。但我这人不喜欢对配置文件做太多的hack。于是一直在琢磨是怎么回事。

今天花了一晚上来研究这个问题。仔细比较server restart方法和service fms restart方法有什么异同。从系统日志,到fms自己的日志,只发现后者restart出来后会提示406错误。但为什么会出406错误我就想不通了,尤其是只是启动方式不同这个原因。
于是我不断修改/etc/init.d/fms这个文件,看看是不是哪条语句出了问题。结果在偶尔一次我没用service方法来重启,而是直接执行的/etc/init.d/fms后,居然正常了。我便开始怀疑service方法的问题。

网上查了查,发现service命令貌似是Redhat系才有的东西,debian系默认不自带,要自己去装,而且也有人不推荐用service命令。
我就好奇的打开/sbin/service看看到底是怎么回事。


#!/bin/sh
#
# /sbin/service        Handle boot and runlevel services
#

#
# Only root should do
#
if test "$(id -u)" -ne 0; then
echo "${0##*/}: only root can use ${0##*/}" 1>&2
exit 1
fi

#
# Location of our service scripts
#
RCDIR="/etc/init.d"

#
# Clean environment
#
PATH=/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin
test -n "$TERM" || TERM=raw
LANG=POSIX
export PATH TERM LANG


exec_rc ()
{
    env -i LANG=$LANG PATH=$PATH TERM=$TERM ${1+"$@"}
}

usage ()
{
echo "Usage: ${0##*/} [--help | --status-all | <service> [<args>| --full-restart]]" 1>&2
exit 1
}

help ()
{
echo "Usage: ${0##*/} [<options> | <service> [<args> | --full-restart]]"
echo "Available <options>:"
echo "  -h,--help        This help."
echo "  -s,--status-all  List out status of all services."
echo "Usage for specific <service>:"
echo "  ${0##*/} service_name argument [option]"
echo "  ${0##*/} service_name --full-restart"
echo "  ${0##*/} --full-restart service_name"
exit 0
}

status_all=0
full_restart=0
args=""
while test $# -gt 0; do
opt=
if test "${1::1}" = "-"; then
if test ${#1} -gt 2 -a "${1::2}" = "--" ; then
opt="${1:2}"
else
opt="${1:1}"
fi
shift
else
args="${args:+$args }$1"
shift
continue
fi

case "$opt" in
status-all|s)   status_all=1 ;;
full-restart) full_restart=1 ;;
h*)                help ;;
*)               usage ;;
esac
done

#
# Determine the status of all services
#
if test $status_all -gt 0 ; then
if test -n "$args" ; then
usage 1>&2
exit 1
fi
for rc in ${RCDIR}/*; do
test ! -x "$rc" -o -d "$rc"    && continue
case "${rc##*/}" in
*.local|*.rpm*|*.ba*|*.old|*.new) continue ;;
*.dpkg|*.save|*.swp|*.core)      continue ;;
boot|rc|single|halt|reboot)      continue ;;
powerfail|rx|Makefile|README)      continue ;;
skeleton|*.d)              continue ;;
esac
exec_rc $rc status
done
exit 0
fi

#
# Do a full restart of a few services
#
if test $full_restart -gt 0 ; then
if test -z "$args" ; then
usage 1>&2
exit 1
fi
for rc in $args; do
if test ! -x ${RCDIR}/$rc ; then
echo "${0##*/}: no such service $rc" 1>&2
exit 1
fi
done
status=0
for rc in $args; do
rc=${RCDIR}/$rc
exec_rc $rc stop
exec_rc $rc start
test $? -gt 0 && status=1
done
exit $status
fi


#
# Execute single service with options
#
if test -z "${args}" ; then
usage 1>&2
exit 1
fi

set -- $args
if test ! -x ${RCDIR}/$1 ; then
echo "${0##*/}: no such service $1" 1>&2
exit 1
fi
rc=${RCDIR}/$1
shift

exec_rc $rc ${1+"$@"}
exit $?

有够复杂吧,比我之前网上看到的版本要复杂N倍,人家就一个/etc/init.d/$1 $2 $3……
另外大家有没有注意到我红色勾出来的地方?对,这个脚本居然很恶心的做了一个系统环境重置,不管外面配置动,用它启动起来的就是固定那几个配置。真是贱到家了。
我猜测这个就是问题的原因,于是去掉所有的系统配置语句。然后再service fms restart。这次就正常了。

很奇怪为什么这里需要系统环境重置,诡异的openSUSE开发人员。
类别:影院平台搭建 查看评论
posted @ 2009-08-17 00:08  ayanamist  阅读(290)  评论(0编辑  收藏  举报