linux - 脚本不会在使用 init 启动时启动

标签 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@example.com
                fi
}
case $1 in
    start)
            weblogic_start
        ;;
    stop)
            weblogic_stop
        ;;
    *) echo "Invalid input"

        ;;
esac

我已经把它正确地放在 init.d 和其他东西中,正确地 chmod-ed 它,把它放在 rc.local 中,但它又不想在启动时启动,尽管如果我手动运行它,传递一个对它的争论,例如“service weblogic start”它工作正常,无论是作为 root 还是不是。任何人有任何建议,为什么它会这样,是否有任何解决方案?

最佳答案

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

你可以把它放到init.d中试试:

对于基于 Debian 的操作系统:

 sudo update-rc.d script_name defaults

对于 CentOS:

chkconfig --add myscript 

关于linux - 脚本不会在使用 init 启动时启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30260464/

相关文章:

linux - 为 libwebsocket Warmcat 安装新版本的 libtool

linux - echo、grep 和设置变量问题

bash - 从 stdout 中随机选择一行

linux - 如何在 Linux 中创建一个 bash 脚本来检查用户是否是本地用户

Java 库通过 ssh 在远程服务器上运行多个不相关的命令

c++ - 进程正在等待另一个进程终止时的信号处理

linux - 将 cat 输出作为变量进行比较

bash - gitlab-ci 脚本中的用户输入会发生什么

shell - &! 和有什么区别?和&|在 zsh 中?

Linux 重命名带有时间戳的文件