build.xml
2.73 KB
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
<?xml version="1.0" encoding="UTF-8" ?>
<project name="main" default="build" basedir=".">
<taskdef resource="net/sf/antcontrib/antlib.xml" />
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
<property file="build.properties" />
<property name="servers" value="192.168.102.12;192.168.102.13" />
<property name="user" value="ginozhang" />
<property name="pwd" value="123456" />
<property name="war_name" value="yoho-kisjob-web" />
<property name="tomcat_location" value="/home/ginozhang/apache-tomcat-8.0.36" />
<target name="deployAndStart" description="初始化处理 停tomcat 删除环境上的war包">
<for list="${servers}" delimiter=";" param="server">
<sequential>
<antcall target="deployAndStartSingle">
<param name="server_ip" value="@{server}" />
</antcall>
</sequential>
</for>
</target>
<target name="deployAndStartSingle" description="初始化处理 停tomcat 删除环境上的war包">
<property name="server_ip" value="" />
<antcall target="deploySingle">
<param name="server_ip" value="${server_ip}" />
</antcall>
<echo message="start tomcat" />
<sshexec host="${server_ip}" username="${user}" password="${pwd}" trust="true" failonerror="false" command="cd ${tomcat_location}/bin; ./startup.sh" />
</target>
<target name="deploy" description="将包部署到远程服务器 但并不启动">
<for list="${servers}" delimiter=";" param="server">
<sequential>
<antcall target="deploySingle">
<param name="server_ip" value="@{server}" />
</antcall>
</sequential>
</for>
</target>
<target name="deploySingle" description="将包部署到单个远程服务器 ">
<property name="server_ip" value="" />
<antcall target="stopSingle">
<param name="server_ip" value="${server_ip}" />
</antcall>
<echo message="upload war package" />
<scp file="war/${war_name}.war" todir="${user}@${server_ip}:${tomcat_location}/webapps" password="${pwd}" trust="true" />
</target>
<target name="stop" description="停止远程机器上的tomcat">
<for list="${servers}" delimiter=";" param="server">
<sequential>
<antcall target="stopSingle">
<param name="server_ip" value="@{server}" />
</antcall>
</sequential>
</for>
</target>
<target name="stopSingle" description="停止远程机器的tomcat 并删除war包和日志">
<property name="server_ip" value="" />
<echo message="clear server ${server_ip}" />
<echo message="stop tomcat" />
<sshexec host="${server_ip}" username="${user}" password="${pwd}" trust="true" failonerror="false" command="cd ${tomcat_location};./bin/shutdown.sh;rm -rf ${tomcat_location}/webapps/${war_name}*;rm -rf ${tomcat_location}/logs/2016-*" />
</target>
<target name="build" depends="deployAndStart">
</target>
</project>