脚本无法在启动时使用init启动

时间:2015-05-15 13:12:43

标签: linux bash shell init

我有以下脚本

#!/bin/sh
# chkconfig: 345 99 01
# description: some startup script
### BEGIN INIT INFO
    # Provides: weblogic
    # Required-Start: $local_fs $network $remote_fs
    # Required-Stop: $local_fs $network $remote_fs
    # Default-Start:  2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: start and stop OurDB
    # Description: OurDB is a very fast and reliable database
    #        engine used for illustrating init scripts
    ### END INIT INFO
. /etc/rc.d/init.d/function
service=startWebLogic.sh
user=*******
password=******
dbschemaname=******
hostname=*******
port=********
weblogic_start()
{
pgrep -f startWebLogic.sh > /dev/null
                if ! [ $? -eq 0 ]; then
                echo "exit" |  sqlplus -L "$user/$password@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=$hostname)(Port=$port))(CONNECT_DATA=(SID=$dbschemaname)))" |  grep "Connected to" > /dev/null
                        if [ $? -eq 0 ]; then
                        /home/usr/Oracle/Middleware/Oracle_Home/user_projects/domains/bin/startWebLogic.sh &

                        else

                        echo "WARNING! No connection to the Oracle Server" | mail -s OracleServerDown monitoring@accedia.com

                        fi
                else

                echo "WARNING! Running WebLogic service was found!" | mail -s "Service Already Running" monitoring@example.com
                fi
}
weblogic_stop()
{
               pgrep -f startWebLogic.sh > /dev/null
                if [ $? -eq 0 ]; then 
                        /home/usr/Oracle/Middleware/Oracle_Home/user_projects/domains/Econt/bin/stopWebLogic.sh &  pid=$! ; sleep 5m; pkill -TERM -P $pid
                        ps -ef| grep $pid
                        if [ $? -ne 0 ];then
                        pkill -TERM -P $pid
                        fi

                        pid=`ps -ejH|grep "startWebLogic" | grep -iv "grep" | awk '{print $1}'`
                        pkill -TERM -P $pid


                else
                        echo "WARNING! No running WebLogic service was found" | mail -s "WebLogic Not Found" monitoring@accedia.com

                fi
}
case $1 in
    start)
            weblogic_start
        ;;
    stop)
            weblogic_stop
        ;;
    *) echo "Invalid input"

        ;;
esac

我已经把它正确地放在了init.d和东西中,正确地修改它,把它放在rc.local中然后又不想在启动时启动,不过如果我手动运行它,传递一个对它的论证,例如“service weblogic start”它运行良好,既可以是root,也可以不是。任何人都有任何建议,为什么它是这样的,有什么解决方案吗?

2 个答案:

答案 0 :(得分:0)

您不需要将它放在init.drc.local这两个地方。一个就够了。

您可以在将其放入init.d后尝试此操作:

对于基于Debian的操作系统:

 sudo update-rc.d script_name defaults

对于CentOS:

chkconfig --add myscript 

答案 1 :(得分:0)

找到一个解决方案,问题出在上面,我已经将chkconfig选项从345 99 01改为345 98 10.