Linux Jenkins启动、停止脚本

Jenkins的官网下载https://jenkins.io


点击Download Jenkins按钮会弹出两个版本选择:LTS Release(长期支持版本),Weekly Release(每周更新版本)。首先说一下这两个版本,个人觉得和MIUI的更新类似,一个开发版本一个稳定版,大家可以自行选择,功能上几乎没区别。


1.保存为jenkins目录下 jenkins.sh
JENKINS_ROOT为 jenkins目录

#! /bin/sh  
# chkconfig: 2345 10 90   
# description: jenkins ....  
# This script will be executed *after* all the other init scripts.    
# You can put your own initialization stuff in here if you don't    
# want to do the full Sys V style init stuff.    
#prefix=/home/lanmps/jenkins  
#nohup $prefix/start_jenkins.sh >> $prefix/jenkins.log 2>&1 &  
  
JENKINS_ROOT=/home/lanmps/jenkins  
JENKINSFILENAME=jenkins.war  
  
#停止方法  
stop(){  
    echo "Stoping $JENKINSFILENAME "  
    ps -ef|grep $JENKINSFILENAME |awk '{print $2}'|while read pid  
    do  
       kill -9 $pid  
       echo " $pid kill"  
    done  
}  
  
case "$1" in  
start)  
    echo "Starting $JENKINSFILENAME "  
    nohup $JENKINS_ROOT/start_jenkins.sh >> $JENKINS_ROOT/jenkins.log 2>&1 &  
  ;;  
stop)  
  stop  
  ;;  
restart)  
  stop  
  start  
  ;;  
status)  
  ps -ef|grep $JENKINSFILENAME  
  ;;  
*)  
  printf 'Usage: %s {start|stop|restart|status}\n' "$prog"  
  exit 1  
  ;;  
esac


2.保存为:start_jenkins.sh

其中JENKINS_ROOT是你自己空间的路径

注意:如果使用service jenkins start命令启动报错:java: command not found,那么java -jar命令就写绝对路径,比如:/usr/java/jdk1.8.0_25/bin/java -jar

#!/bin/bash  
JENKINS_ROOT=/home/lanmps/jenkins  
export JENKINS_HOME=$JENKINS_ROOT/home  
java -jar $JENKINS_ROOT/jenkins.war --httpPort=8080

3.centos

ln -s /home/lanmps/jenkins/jenkins.sh /etc/init.d/jenkins  
chkconfig --add jenkins  
chkconfig --level 345 jenkins on

4.启动方式1

/etc/init.d/jenkins start


5.启动方式2
service jenkins start

参考文章:http://blog.csdn.net/fenglailea/article/details/42557751


你可能感兴趣的:(后端)