| 1 | <?xml version="1.0" encoding="UTF-8"?> |
|---|
| 2 | <project name="xindex updator" default="all" basedir="."> |
|---|
| 3 | <property name="index" location="index"/> |
|---|
| 4 | <property name="work" location="work"/> |
|---|
| 5 | <property name="indexbackup" location="indexbackup"/> |
|---|
| 6 | <property name="mail-server" value="192.168.11.232"/> |
|---|
| 7 | <property name="mail-port" value="25"/> |
|---|
| 8 | <property name="mail-user" value="abc@pconline.com.cn"/> |
|---|
| 9 | <property name="mail-passwd" value="abc"/> |
|---|
| 10 | <property name="mail-list" value="chenchongqi@pconline.com.cn"/> |
|---|
| 11 | <tstamp> |
|---|
| 12 | <format property="TODAY" pattern="yyyy-MMMM-dd-HH-mm" locale="en"/> |
|---|
| 13 | </tstamp> |
|---|
| 14 | <fileset id="updateFiles" dir="${work}" > |
|---|
| 15 | <include name="*.txt"/> |
|---|
| 16 | </fileset> |
|---|
| 17 | <echo>Target time: ${TODAY}</echo> |
|---|
| 18 | |
|---|
| 19 | <target name="check-update"> |
|---|
| 20 | <condition property="update.files"> |
|---|
| 21 | <resourcecount refid="updateFiles" when="greater" count="0" /> |
|---|
| 22 | </condition> |
|---|
| 23 | </target> |
|---|
| 24 | |
|---|
| 25 | <target name="backup" depends="check-update" if="update.files"> |
|---|
| 26 | <echo>Backup index files ....</echo> |
|---|
| 27 | <zip destfile="${indexbackup}/bak${TODAY}.zip" |
|---|
| 28 | basedir="${index}" |
|---|
| 29 | includes="*.txt" |
|---|
| 30 | /> |
|---|
| 31 | </target> |
|---|
| 32 | |
|---|
| 33 | <target name="flush-cmd" depends="backup" if="update.files"> |
|---|
| 34 | <exec executable="bash" outputproperty="blah" > |
|---|
| 35 | <arg value="-c"/> |
|---|
| 36 | <arg value="echo flush_all | nc localhost 11311"/> |
|---|
| 37 | </exec> |
|---|
| 38 | <condition property="flush.fail"> |
|---|
| 39 | <and> |
|---|
| 40 | <not> |
|---|
| 41 | <equals arg1="OK" arg2="${blah}" forcestring="true"/> |
|---|
| 42 | </not> |
|---|
| 43 | <istrue value="${update.files}"/> |
|---|
| 44 | </and> |
|---|
| 45 | </condition> |
|---|
| 46 | <echo>Flush command return:${blah}</echo> |
|---|
| 47 | </target> |
|---|
| 48 | |
|---|
| 49 | <target name="send-mail"> |
|---|
| 50 | <echo>send alert mail</echo> |
|---|
| 51 | <mail mailhost="${mail-server}" mailport="${mail-port}" subject="${title}" |
|---|
| 52 | user="${mail-user}" password="${mail-passwd}" failonerror="false"> |
|---|
| 53 | <from address="${mail-user}"/> |
|---|
| 54 | <to address="${mail-list}"/> |
|---|
| 55 | <message>${message}</message> |
|---|
| 56 | </mail> |
|---|
| 57 | </target> |
|---|
| 58 | |
|---|
| 59 | <target name="flush" depends="flush-cmd" if="flush.fail"> |
|---|
| 60 | <antcall target="send-mail"> |
|---|
| 61 | <param name="title" value="Flush command failed"/> |
|---|
| 62 | <param name="message" value="Flush command return: ${blah}"/> |
|---|
| 63 | </antcall> |
|---|
| 64 | </target> |
|---|
| 65 | |
|---|
| 66 | <target name="get-cmd" > |
|---|
| 67 | <exec executable="bash" outputproperty="query-result" > |
|---|
| 68 | <arg value="-c"/> |
|---|
| 69 | <arg value="echo get index=20937 | nc localhost 11311"/> |
|---|
| 70 | </exec> |
|---|
| 71 | <condition property="get.fail"> |
|---|
| 72 | <and> |
|---|
| 73 | <not> |
|---|
| 74 | <contains string="${query-result}" substring="recordIds"/> |
|---|
| 75 | </not> |
|---|
| 76 | </and> |
|---|
| 77 | </condition> |
|---|
| 78 | <echo>Get command return:${query-result}</echo> |
|---|
| 79 | </target> |
|---|
| 80 | <target name="check-index" depends="get-cmd" if="get.fail"> |
|---|
| 81 | <antcall target="send-mail"> |
|---|
| 82 | <param name="title" value="Get command failed"/> |
|---|
| 83 | <param name="message" value="Get command return: ${query-result}"/> |
|---|
| 84 | </antcall> |
|---|
| 85 | </target> |
|---|
| 86 | </project> |
|---|