查询状态时,jenkins ci init.d脚本返回错误

时间:2014-07-07 11:53:54

标签: tomcat jenkins centos init.d

我使用以下init.d脚本由jenkins ci网站提供https://wiki.jenkins-ci.org/display/JENKINS/JenkinsLinuxStartupScript

当我开始和停止jenkins时它工作正常,但当我要求状态时它会出错。如何正确报告状态?

[root@jenkins01 init.d]# service jenkins start
Starting Tomcat: Using CATALINA_BASE:   /apps/tomcat/apache-tomcat-7.0.54
Using CATALINA_HOME:   /apps/tomcat/apache-tomcat-7.0.54
Using CATALINA_TMPDIR: /apps/tomcat/apache-tomcat-7.0.54/temp
Using JRE_HOME:        /usr/java/jdk1.7.0_13
Using CLASSPATH:       /apps/tomcat/apache-tomcat- \ 
7.0.54/bin/bootstrap.jar:/apps/tomcat/apache-tomcat-7.0.54/bin/tomcat-juli.jar
Using CATALINA_PID:    /apps/tomcat/jenkins-tomcat.pid
Tomcat started.

[root@jenkins01 init.d]# service jenkins status
status: Unknown job: tomcat

[root@jenkins01 init.d]# cat /apps/tomcat/jenkins-tomcat.pid
8919

这里的脚本完整,略微适合我的设置:

#!/bin/sh
#
# Startup script for the Jenkins Continuous Integration server
# (via Jakarta Tomcat Java Servlets and JSP server)
#
# chkconfig: - 85 15
# description: Jakarta Tomcat Java Servlets and JSP server
# processname: tomcat
# pidfile: /var/run/tomcat.pid

# Set Tomcat environment.
JENKINS_USER=tomcat
LOCKFILE=/var/lock/jenkins
export PATH=/usr/local/bin:$PATH
export HOME=/apps/tomcat
export JAVA_HOME=/usr/java/jdk1.7.0_13
export JENKINS_BASEDIR=/apps/tomcat
export TOMCAT_HOME=/apps/tomcat/apache-tomcat-7.0.54
export CATALINA_PID=$JENKINS_BASEDIR/jenkins-tomcat.pid
export CATALINA_OPTS="-DJENKINS_HOME=$JENKINS_BASEDIR/jenkins-home -Xmx512m -Djava.awt.headless=true"

[ -f $TOMCAT_HOME/bin/catalina.sh ] || exit 0

export PATH=$PATH:/usr/bin:/usr/local/bin

# See how we were called.
case "$1" in
  start)
        # Start daemon.
        echo -n "Starting Tomcat: "
        su -p -s /bin/sh $JENKINS_USER -c "$TOMCAT_HOME/bin/catalina.sh start"
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch $LOCKFILE
        ;;
  stop)
        # Stop daemons.
        echo -n "Shutting down Tomcat: "
        su -p -s /bin/sh $JENKINS_USER -c "$TOMCAT_HOME/bin/catalina.sh stop"
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f $LOCKFILE
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  condrestart)
       [ -e $LOCKFILE ] && $0 restart
       ;;
  status)
        status tomcat
        ;;
  *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
esac

exit 0

1 个答案:

答案 0 :(得分:0)

我遇到了和你一样的问题,网站上的脚本是完全错误的,我已经更新了(我在Red Hat上测试过)。

错误是:

  • 缺少函数库的源代码(没有使用status命令而不是库中定义的状态函数)

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

  • 描述中的错误进程名称(tomcat而不是jenkins)

  • 描述中的错误pid文件

  • 状态语法错误,正确: status -p $CATALINA_PID -l $(basename $LOCKFILE) jenkins