-
Notifications
You must be signed in to change notification settings - Fork 48
/
install-jenkins-war.sh
89 lines (76 loc) · 2 KB
/
install-jenkins-war.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
#
# war install jenkins
# 解决相对路径问题
cd `dirname $0`
# 检查是否为root用户,脚本必须在root权限下运行
source ../common/util.sh
util::check_root
# 下载war包
# 在此地址下载war包http://mirrors.jenkins.io/war-stable/
wget http://mirrors.jenkins.io/war-stable/latest/jenkins.war -O jenkins.war
# 创建用户
# 先清理旧用户
userdel jenkins
groupdel jenkins
useradd jenkins
usermod -aG www-data jenkins
# 创建文件夹,移动目录
mkdir -p /data/service/jenkins
mkdir -p /data/service/jenkins/.jenkins
mv jenkins.war /data/service/jenkins/
# 修改目录权限
chown -R www-data:www-data /data/service/jenkins
chown -R jenkins:jenkins /data/service/jenkins/.jenkins
# 安装start-stop-daemon
wget http://ftp.de.debian.org/debian/pool/main/d/dpkg/dpkg_1.16.18.tar.xz -O dpkg_1.16.18.tar.xz
tar -xf dpkg_1.16.18.tar.xz && cd dpkg-1.16.18
yum install ncurses-devel -y
./configure && make && make install
# 创建开机启动服务
cat <<"EOF" > /etc/init.d/jenkins
#!/bin/sh
# chkconfig: - 85 15
# description: Jenkins CI Server
DESC="Jenkins CI Server"
NAME=jenkins
PIDFILE=/var/run/$NAME.pid
RUN_AS=jenkins
COMMAND="/usr/bin/java -- -DJENKINS_HOME=/data/service/jenkins/.jenkins -jar /data/service/jenkins/jenkins.war"
START_STOP_DAEMON=/usr/local/sbin/start-stop-daemon
d_start() {
$START_STOP_DAEMON --start --quiet --background -C --make-pidfile --pidfile $PIDFILE --chuid $RUN_AS --exec $COMMAND > /var/log/jenkins.log 2>&1
}
d_stop() {
$START_STOP_DAEMON --stop --quiet --pidfile $PIDFILE
if [ -e $PIDFILE ]
then rm $PIDFILE
fi
}
case $1 in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 1
d_start
echo "."
;;
*)
echo "usage: $NAME {start|stop|restart}"
exit 1
;;
esac
exit 0
EOF
chmod +x /etc/init.d/jenkins
chkconfig --add jenkins