自由狼-台风 发表于 2008-1-11 12:37:48

不能自动停止的启动脚本。

概况:

Linux=2.6.15-3
Shell=GNU Bash 3.0.x
准备让自行安装的PostgreSQL随系统运行级别的变化而启停,未果。


问题:

以下脚本都能手工start和stop。
以下脚本都能用chkconfig添加进启动项,并在相应的/etc/rc.d/rcX.d目录中创建对应的SXXxxx和KXXxxx链接。
以下脚本在系统运行级别变化时只会start,不会stop。
有人能帮忙看看这些脚本有啥问题吗?或者给出一个可用的基本脚本?


脚本“/etc/rc.d/init.d/tfw_pgsql”,修改自“/etc/rc.d/init.d/smb”:

#!/bin/sh
#
# chkconfig: - 90 6
# description: PostgreSQL control script.
# !!! DO NOT MODIFY THE CONTENTS ABOVE BEFORE CAREFULLY THINKING! !!!

echo "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
echo "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
echo "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
echo "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"

# Source function library.
if [ -f /etc/init.d/functions ] ; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
. /etc/rc.d/init.d/functions
else
exit 0
fi

NAME=PostgreSQL
USER=typhoon
PG_HOME=/opt/prog/m/PostgreSQL.MagicLinux-2.0
PGDATA=/opt/prog/m/PostgreSQL-Database
PG_CTL=$PG_HOME/bin/pg_ctl
DEAMON=$PG_HOME/bin/postmaster
LOGFILE=$PGDATA/pg.log

RETVAL=0

start() {
        echo ">>>        Starting $NAME..."
        echo "        Version:        2008-01-10 14:45"
        if(su - $USER -c "$PG_CTL -w -l $LOGFILE start -D $PGDATA")then
                RETVAL=0
                if($_function)then
                        echo -n "<<<"
                        echo_success
                        echo ""
                else
                        echo "<<<        "
                fi
        else
                RETVAL=1
                if($_function)then
                        echo -n "<<<"
                        echo_failure
                        echo ""
                else
                        echo "<<<        "
                fi
        fi
        echo $RETVAL
        return $RETVAL
}       

stop() {
        echo ">>>        Stopping $NAME..."
        echo "        Version:        2008-01-10 14:45"
        if(su - $USER -c "$PG_CTL stop -m fast")then
                RETVAL=0
                if($_function)then
                        echo -n "<<<"
                        echo_success
                        echo ""
                else
                        echo "<<<        "
                fi
        else
                RETVAL=1
                if($_function)then
                        echo -n "<<<"
                        echo_failure
                        echo ""
                else
                        echo "<<<        "
                fi
        fi
        echo $RETVAL
        return $RETVAL
}       

restart() {
        stop
        start
}       

reload() {
        echo ">>>        Reloading $NAME..."
        echo "        Version:        2008-01-10 14:45"
        if(su - $USER -c "$PG_CTL reload")then
                RETVAL=0
                if($_function)then
                        echo -n "<<<"
                        echo_success
                        echo ""
                else
                        echo "<<<        "
                fi
        else
                RETVAL=1
                if($_function)then
                        echo -n "<<<"
                        echo_failure
                        echo ""
                else
                        echo "<<<        "
                fi
        fi
        echo $RETVAL
        return $RETVAL
}       

status() {
        start
        stop
}       

case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
restart)
        restart
        ;;
reload)
        reload
        ;;
status)
        status
        ;;
*)
        echo $"Usage: $0 {start|stop|restart|reload|status}"
        exit 1
esac

exit $?


脚本“/etc/rc.d/init.d/smb_”,在上一脚本的基础上完全去除了数据库启停操作:

#!/bin/sh
#
# chkconfig: - 91 35
# description: Starts and stops the Samba smbd and nmbd daemons \
#             used to provide SMB network services.
#
# pidfile: /var/run/samba/smbd.pid
# pidfile: /var/run/samba/nmbd.pid
# config:/etc/samba/smb.conf


# Source function library.
if [ -f /etc/init.d/functions ] ; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
. /etc/rc.d/init.d/functions
else
exit 0
fi

# Avoid using root's TMPDIR
unset TMPDIR

# Source networking configuration.
. /etc/sysconfig/network

if [ -f /etc/sysconfig/samba ]; then
   . /etc/sysconfig/samba
fi

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

# Check that smb.conf exists.
[ -f /etc/samba/smb.conf ] || exit 0

RETVAL=0


start() {
        echo -n "Starting..."
        /myops/exec/pause
        echo_success
        echo ""
        return $RETVAL
}       

stop() {
        echo -n "Stopping..."
        /myops/exec/pause
        echo_success
        echo ""
        return $RETVAL
}       

restart() {
        stop
        start
}       

reload() {
        echo -n "Reloading..."
        /myops/exec/pause
        echo_success
        echo ""
        return $RETVAL
}       

status() {
        echo -n "Checking..."
        /myops/exec/pause
        echo_success
        echo ""
        return $RETVAL
}       

case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
restart)
        restart
        ;;
reload)
        reload
        ;;
status)
        status
        ;;
*)
        echo $"Usage: $0 {start|stop|restart|reload|status}"
        exit 1
esac

exit $?


脚本“/etc/rc.d/init.d/smb_2”,最终简化版本:

#!/bin/sh
#
# chkconfig: - 91 35
# description: -_-|||

case "$1" in
start)
#        start
        echo "Starting AAAAA..."
        echo ""
        ;;
stop)
#        stop
        echo "Stopping AAAAA..."
        echo ""
        ;;
*)
        echo $"Usage: $0 {start|stop}"
        exit 1
esac

exit $?


[ 本帖最后由 自由狼-台风 于 2008-1-11 12:39 编辑 ]

自由狼-台风 发表于 2008-1-11 20:10:46

终于找到一个解决方案,但很龌龊,很不地道,很邪恶,很弱小……
页: [1]
查看完整版本: 不能自动停止的启动脚本。