码迷,mamicode.com
首页 > 其他好文 > 详细

部署应用的小脚本

时间:2017-05-12 23:57:00      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:expected   color   span   fail   logs   init.d   div   nts   init   

 1 #!/bin/bash
 2 # Author        : standby
 3 # Date          : 2017-05-12
 4 # Description   : Deploy something.
 5 
 6 . /etc/init.d/functions
 7 
 8 # Usage...
 9 function Usage()
10 {
11     echo -e "Usage: /bin/sh $0 arg1 arg2\n \
12                   - arg1 like this : data1 | data2 ...\n 13                   - arg2 like this : tag"
14     exit 2
15 }
16 # The core deploy code block here...
17 function deploy()
18 {
19     # Prepare something...
20     # ...
21     # Deploy some crontab and script...
22     # ...
23 }
24 # Verificate the arguments.
25 function verificate()
26 {
27     result=0
28     available=`df -m |grep $1$ |awk {print $4}`
29     [[ $available -lt 1000000 ]] && result=1
30     [[ $2 == x* ]] || result=2
31     #[ $2 == x* ] || result=2
32     echo $result
33 }
34 # Start something processes.
35 function start_work()
36 {
37     if [ $1 -eq 1 ]
38     then
39         echo -e "\n"
40         action "Deploy something successful." /bin/true
41         echo -e "\nBegin to start something process...\n"
42         # start something cmd here ...
43         if [ $? -eq 0 ]
44         then
45             action "Start something successful." /bin/true
46         else
47             action "Start something failed." /bin/false
48         fi
49     elif [ $1 -eq 2 ]
50     then
51         action "Deploy something failed." /bin/false
52     exit -1
53     else
54         action "You are not expected to undestand this code block ->_->" /bin/true
55     fi
56 }
57 # Main code body.
58 function main()
59 {
60     [[ $1 == dat* ]] || Usage
61     result=`verificate $1 $2`
62     #echo $result
63     if [ $result -eq 0 ]
64     then
65         #echo "Hello world!"
66         deploy $1 $2
67         [ $? -eq 0 ] && start_work 1 || start_work 2
68     elif [ $result -eq 1 ]
69     then
70         echo "$1 have less than 1T space left"
71         exit 1
72     elif [ $result -eq 2 ]
73     then
74         echo "The arg2 must start with ‘x‘, not $2"
75         exit 2
76     fi
77 }
78 # Start here...
79 if [ $# -ne 2 ]
80 then
81     Usage
82 else
83     main $1 $2
84 fi

 

部署应用的小脚本

标签:expected   color   span   fail   logs   init.d   div   nts   init   

原文地址:http://www.cnblogs.com/standby/p/6847554.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!