作者 yangfu

deploy.sh

1 #!/usr/bin/env bash 1 #!/usr/bin/env bash
2 2
3 ##部署脚本/文件路径 3 ##部署脚本/文件路径
4 -deploy_shell_path="/home/tiptok/test/ability.tar" 4 +#deploy_shell_path="/home/tiptok/test/ability.tar"
  5 +deploy_shell_path="/home/tiptok/test/ability.zip"
5 6
6 go build -o ability main.go 7 go build -o ability main.go
7 chmod +x ability 8 chmod +x ability
8 -tar -zcvf ${deploy_shell_path} ability conf deploy.sh run.sh start.sh stop.sh 9 +#tar -zcvf ${deploy_shell_path} ability conf deploy.sh run.sh start.sh stop.sh
  10 +zip -r ${deploy_shell_path} ability conf deploy.sh run.sh start.sh stop.sh
@@ -11,13 +11,20 @@ project_path="${project_root_path}/${project_name}" @@ -11,13 +11,20 @@ project_path="${project_root_path}/${project_name}"
11 project_bak_path="/home/tiptok/www/bin_bak" 11 project_bak_path="/home/tiptok/www/bin_bak"
12 12
13 projcet_bak_file="${project_bak_path}/${time}_${project_name}.tar" 13 projcet_bak_file="${project_bak_path}/${time}_${project_name}.tar"
14 -project_gzip_file="${deploy_shell_path}/${project_name}.tar" 14 +
  15 +## 看压缩文件的格式 tar / zip
  16 +#project_gzip_file="${deploy_shell_path}/${project_name}.tar"
  17 +project_gzip_file="${deploy_shell_path}/${project_name}.zip"
  18 +
  19 +conpress_type="${project_gzip_file##*.}"
15 20
16 echo "------begin deploy-------" 21 echo "------begin deploy-------"
17 echo "ProjectName: ${project_name}" 22 echo "ProjectName: ${project_name}"
18 echo "ProjectPath: ${project_path}" 23 echo "ProjectPath: ${project_path}"
19 echo "ProjectBakFile : ${projcet_bak_file}" 24 echo "ProjectBakFile : ${projcet_bak_file}"
20 echo "ProjectGzipFile : ${project_gzip_file}" 25 echo "ProjectGzipFile : ${project_gzip_file}"
  26 +echo "ConpressType : ${conpress_type}"
  27 +
21 28
22 if [ ! -d ${project_bak_path} ];then 29 if [ ! -d ${project_bak_path} ];then
23 mkdir -p ${project_bak_path} 30 mkdir -p ${project_bak_path}
@@ -38,8 +45,13 @@ if [ ! -e ${project_path} ];then @@ -38,8 +45,13 @@ if [ ! -e ${project_path} ];then
38 mkdir -p ${project_path} 45 mkdir -p ${project_path}
39 echo "mkdir ${project_path}" 46 echo "mkdir ${project_path}"
40 fi 47 fi
  48 +
41 if [ -f ${project_gzip_file} ];then 49 if [ -f ${project_gzip_file} ];then
  50 + if [ ${conpress_type} == "tar" ];then
42 tar -xzf ${project_gzip_file} -C "${project_root_path}/${project_name}"||(echo "tar -x failed"; exit 1) 51 tar -xzf ${project_gzip_file} -C "${project_root_path}/${project_name}"||(echo "tar -x failed"; exit 1)
  52 + elif [ ${conpress_type} == "zip" ];then
  53 + unzip -o ${project_gzip_file} -d "${project_root_path}/${project_name}"||(echo "tar -x failed"; exit 1)
  54 + fi
43 rm -fr ${project_gzip_file} 55 rm -fr ${project_gzip_file}
44 else 56 else
45 echo "project_gzip_file not exists! please upload zip file ..." 57 echo "project_gzip_file not exists! please upload zip file ..."