不能自动停止的启动脚本。
自由狼-台风
|
1#
自由狼-台风 发表于 2008-01-11 12:37
不能自动停止的启动脚本。
概况:
复制内容到剪贴板
问题:
代码:Linux=2.6.15-3Shell=GNU Bash 3.0.x 准备让自行安装的PostgreSQL随系统运行级别的变化而启停,未果。
复制内容到剪贴板
脚本“/etc/rc.d/init.d/tfw_pgsql”,修改自“/etc/rc.d/init.d/smb”:
代码:以下脚本都能手工start和stop。以下脚本都能用chkconfig添加进启动项,并在相应的/etc/rc.d/rcX.d目录中创建对应的SXXxxx和KXXxxx链接。 以下脚本在系统运行级别变化时只会start,不会stop。 有人能帮忙看看这些脚本有啥问题吗?或者给出一个可用的基本脚本?
复制内容到剪贴板
脚本“/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 "<<< [OK]" fi else RETVAL=1 if($_function)then echo -n "<<<" echo_failure echo "" else echo "<<< [Failed]" 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 "<<< [OK]" fi else RETVAL=1 if($_function)then echo -n "<<<" echo_failure echo "" else echo "<<< [Failed]" 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 "<<< [OK]" fi else RETVAL=1 if($_function)then echo -n "<<<" echo_failure echo "" else echo "<<< [Failed]" 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_2”,最终简化版本:
代码:#!/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 $?
复制内容到剪贴板
代码:#!/bin/sh# # chkconfig: - 91 35 # description: -_-||| case "$1" in start) # start echo "Starting AAAAA..." echo "[OK]" ;; stop) # stop echo "Stopping AAAAA..." echo "[OK]" ;; *) echo $"Usage: $0 {start|stop}" exit 1 esac exit $? |