在 Centos 6 上创建服务导致其在启动时显示阻塞

在 Centos 6 上创建服务导致其在启动时显示阻塞

我正在尝试在 Centos 6 上创建一个服务,但它是在启动控制台上执行的,而不是在后台执行的,这意味着它永远不会到达用户界面 - 它只是挂在启动显示屏上。

服务如下:

#!/bin/bash
#
# run red5 server 
#
# chkconfig: 5 70 30
# description: app server
# processname: red5  

# Source function library.
. /etc/init.d/functions

RETVAL=0
prog="red5"
LOCKFILE=/var/lock/subsys/$prog

# Declare variables for red5 Server
ANALYTICS_DIR=/home/engineering/SVP/app-server

start() {
        echo -n "Starting $prog: "
        cd $ANALYTICS_DIR
        daemon ./red5.sh
        RETVAL=$?
        [ $RETVAL -eq 0 ] && touch $LOCKFILE
        echo
        return $RETVAL
}

stop() {
        echo -n "Shutting down $prog: "
        cd $ANALYTICS_DIR
        nohup ./red5-stop.sh && success || failure
        RETVAL=$?
        [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
        echo
        return $RETVAL
}

status() {
        echo "stub"
}


case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status
        ;;

这是 red5.sh 脚本(运行另一个脚本)

#!/bin/bash

if [ -z "$RED5_HOME" ]; then
  export RED5_HOME=`pwd`;
fi
export JAVA_OPTS="${JAVA_OPTS} -Xms1g -Xmx1g -Xss256K"
LOG_OPTS="-DSERVER_LOGS=/var/opt/SVP/svp-server/log"
source ${RED5_HOME}/red5-start.sh

这是 red5-start.sh

#!/bin/bash

if [ -z "$RED5_HOME" ]; then
  export RED5_HOME=`pwd`;
fi

P=":" # The default classpath separator
OS=`uname`
case "$OS" in
  CYGWIN*|MINGW*) # Windows Cygwin or Windows MinGW
  P=";" # Since these are actually Windows, let Java know
  ;;
  Darwin*)

  ;;
  *)
  # Do nothing
  ;;
esac

echo "Running on " $OS
# JAVA options
# You can set JAVA_OPTS to add additional options if you want
JAVA_OPTS="$JAVA_OPTS -Xverify:none -XX:+TieredCompilation -XX:+UseBiasedLocking -XX:+UseParNewGC -XX:InitialCodeCacheSize=8m -XX:ReservedCodeCacheSize=32m -Dorg.terracotta.quartz.skipUpdateCheck=true"
# Set up logging options
LOGGING_OPTS="-Dlogback.ContextSelector=org.red5.logging.LoggingContextSelector -Dcatalina.useNaming=true"
# Set up security options
SECURITY_OPTS="-Djava.security.debug=failure"
# Set up MySQL encryption
export APP_ENC=encrypt
# Set up Java system property for location of the application server log files
export JAVA_OPTS="$LOGGING_OPTS $SECURITY_OPTS $JAVA_OPTS $LOG_OPTS"

if [ -z "$RED5_MAINCLASS" ]; then
  export RED5_MAINCLASS=org.red5.server.Bootstrap
fi

# Jython options
JYTHON="-Dpython.home=lib"
#for JAVA in "${JAVA_HOME}/bin/java" "${JAVA_HOME}/Home/bin/java" "/usr/bin/java" "/usr/local/bin/java"
for JAVA in "${JAVA_HOME}/bin/java" "${JAVA_HOME}/Home/bin/java" "/usr/bin/java" "/usr/local/bin/java"
do
  if 
[ -x "$JAVA" ]
  then
    break
  fi
done

export JAVA=/usr/bin/java

if [ ! -x "$JAVA" ]
                                                                                                                                           
  then
    break
  fi
done

export JAVA=/usr/bin/java

if [ ! -x "$JAVA" ]
then
  echo "Unable to locate Java. Please set JAVA_HOME environment variable."
  exit
fi

export RED5_CLASSPATH="${RED5_HOME}/red5-service.jar${P}${RED5_HOME}/lib/mail.jar${P}${RED5_HOME}/conf${P}${CLASSPATH}"

# start Red5
echo "Starting Red5"
echo "JAVA is: $JAVA"
exec "$JAVA" "$JYTHON" -Dred5.root="${RED5_HOME}" $JAVA_OPTS -cp "${RED5_CLASSPATH}" "$RED5_MAINCLASS" $RED5_OPTS

问题是否在于服务正在调用另一个脚本?

我是否需要将 red5-start.sh 作为 red5 的守护进程运行?我宁愿不这样做,而且我知道它以前作为服务运行过,无需这样做。只是我没有最初设置的服务的副本,所以我想弄清楚它是如何工作的。

答案1

您是否尝试过将最后一行更改为:

exec "$JAVA" "$JYTHON" -Dred5.root="${RED5_HOME}" $JAVA_OPTS -cp "${RED5_CLASSPATH}" "$RED5_MAINCLASS" $RED5_OPTS &

它应该在后台运行 Java。

相关内容