设为首页 收藏本站
查看: 805|回复: 0

[经验分享] Linux system startup script for Jenkins(Hudson)

[复制链接]

尚未签到

发表于 2018-9-4 11:58:56 | 显示全部楼层 |阅读模式
  http:///safeRestart
  There is a startup script for Linux, and provides start|stop|status|try-restart|restart|force-reload|reload|probe  functionality.
  Please set your own JENKINS_HOME, default is at /lib/var/jenkins
  /etc/init.d/Hudson
  #!/bin/sh
  #
  #     Linux system statup script for Hudson
  #     Copyright (C) 2007  Pascal Bleser
  #
  #     This library is free software; you can redistribute it and/or modify it
  #     under the terms of the GNU Lesser General Public License as published by
  #     the Free Software Foundation; either version 2.1 of the License, or (at
  #     your option) any later version.
  #
  #     This library is distributed in the hope that it will be useful, but
  #     WITHOUT ANY WARRANTY; without even the implied warranty of
  #     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  #     Lesser General Public License for more details.
  #
  #     You should have received a copy of the GNU Lesser General Public
  #     License along with this library; if not, write to the Free Software
  #     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
  #     USA.
  #
  ### BEGIN INIT INFO
  # Provides:          hudson
  # Required-Start:    $local_fs $remote_fs $network $time $named
  # Should-Start: $time sendmail
  # Required-Stop:     $local_fs $remote_fs $network $time $named
  # Should-Stop: $time sendmail
  # Default-Start:     3 5
  # Default-Stop:      0 1 2 6
  # Short-Description: Hudson continuous build server
  # Description:       Start the Hudson continuous build server
  ### END INIT INFO
  # Check for missing binaries (stale symlinks should not happen)
  HUDSON_WAR="/usr/lib/hudson/hudson.war"
  test -r "$HUDSON_WAR" || { echo "$HUDSON_WAR not installed";
  if [ "$1" = "stop" ]; then exit 0;
  else exit 5; fi; }
  # Check for existence of needed config file and read it
  HUDSON_CONFIG=/etc/sysconfig/hudson
  test -e "$HUDSON_CONFIG" || { echo "$HUDSON_CONFIG not existing";
  if [ "$1" = "stop" ]; then exit 0;
  else exit 6; fi; }
  test -r "$HUDSON_CONFIG" || { echo "$HUDSON_CONFIG not readable. Perhaps you forgot 'sudo'?";
  if [ "$1" = "stop" ]; then exit 0;
  else exit 6; fi; }
  HUDSON_PID_FILE="/var/run/hudson.pid"
  # Source function library.
  . /etc/init.d/functions
  # Read config
  [ -f "$HUDSON_CONFIG" ] && . "$HUDSON_CONFIG"
  # Set up environment accordingly to the configuration settings
  [ -n "$HUDSON_HOME" ] || { echo "HUDSON_HOME not configured in $HUDSON_CONFIG";
  if [ "$1" = "stop" ]; then exit 0;
  else exit 6; fi; }
  [ -d "$HUDSON_HOME" ] || { echo "HUDSON_HOME directory does not exist: $HUDSON_HOME";
  if [ "$1" = "stop" ]; then exit 0;
  else exit 1; fi; }
  export HUDSON_HOME
  # Search usable Java. We do this because various reports indicated
  # that /usr/bin/java may not always point to Java 1.5
  # see http://www.nabble.com/guinea-pigs-wanted-----Hudson-RPM-for-RedHat-Linux-td25673707.html
  for candidate in /usr/lib/jvm/java-1.6.0/bin/java /usr/lib/jvm/jre-1.6.0/bin/java /usr/lib/jvm/java-1.5.0/bin/java /usr/lib/jvm/jre-1.5.0/bin/java /usr/bin/java
  do
  [ -x "$HUDSON_JAVA_CMD" ] && break
  HUDSON_JAVA_CMD="$candidate"
  done
  JAVA_CMD="$HUDSON_JAVA_CMD $HUDSON_JAVA_OPTIONS -DHUDSON_HOME=$HUDSON_HOME -jar $HUDSON_WAR"
  PARAMS="--logfile=/var/log/hudson/hudson.log --daemon"
  [ -n "$HUDSON_PORT" ] && PARAMS="$PARAMS --httpPort=$HUDSON_PORT"
  [ -n "$HUDSON_DEBUG_LEVEL" ] && PARAMS="$PARAMS --debug=$HUDSON_DEBUG_LEVEL"
  [ -n "$HUDSON_HANDLER_STARTUP" ] && PARAMS="$PARAMS --handlerCountStartup=$HUDSON_HANDLER_STARTUP"
  [ -n "$HUDSON_HANDLER_MAX" ] && PARAMS="$PARAMS --handlerCountMax=$HUDSON_HANDLER_MAX"
  [ -n "$HUDSON_HANDLER_IDLE" ] && PARAMS="$PARAMS --handlerCountMaxIdle=$HUDSON_HANDLER_IDLE"
  [ -n "$HUDSON_ARGS" ] && PARAMS="$PARAMS $HUDSON_ARGS"
  if [ "$HUDSON_ENABLE_ACCESS_LOG" = "yes" ]; then
  PARAMS="$PARAMS --accessLoggerClassName=winstone.accesslog.SimpleAccessLogger --simpleAccessLogger.format=combined --simpleAccessLogger.file=/var/log/hudson/access_log"
  fi
  RETVAL=0
  case "$1" in
  start)
  echo -n "Starting Hudson "
  daemon --user "$HUDSON_USER" --pidfile "$HUDSON_PID_FILE" $JAVA_CMD $PARAMS > /dev/null
  RETVAL=$?
  if [ $RETVAL = 0 ]; then
  success
  echo > "$HUDSON_PID_FILE"  # just in case we fail to find it
  MY_SESSION_ID=`/bin/ps h -o sess -p $$`
  # get PID
  /bin/ps hww -u "$HUDSON_USER" -o sess,ppid,pid,cmd | \
  while read sess ppid pid cmd; do
  [ "$ppid" = 1 ] || continue

  # this test doesn't work because Hudson sets a new Session>  # [ "$sess" = "$MY_SESSION_ID" ] || continue
  echo "$cmd" | grep $HUDSON_WAR > /dev/null
  [ $? = 0 ] || continue
  # found a PID
  echo $pid > "$HUDSON_PID_FILE"
  done
  else
  failure
  fi
  echo
  ;;
  stop)
  echo -n "Shutting down Hudson "
  killproc hudson
  RETVAL=$?
  echo
  ;;
  try-restart|condrestart)
  if test "$1" = "condrestart"; then
  echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
  fi
  $0 status
  if test $? = 0; then
  $0 restart
  else
  : # Not running is not a failure.
  fi
  ;;
  restart)
  $0 stop
  $0 start
  ;;
  force-reload)
  echo -n "Reload service Hudson "
  $0 try-restart
  ;;

  >  $0 restart
  ;;
  status)
  status hudson
  RETVAL=$?
  ;;
  probe)

  ## Optional: Probe for the necessity of a>
  ## argument to this init script which is required for a>  ## Note: probe is not (yet) part of LSB (as of 1.9)

  test "$HUDSON_CONFIG" -nt "$HUDSON_PID_FILE" && echo>  ;;
  *)
  echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
  exit 1
  ;;
  esac
  exit $RETVAL


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-562469-1-1.html 上篇帖子: Jenkins Master/Slave架构 下篇帖子: JENKINS删除插件
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表