• 第一个脚本部署案例,比较简单,还有redis的部署脚本没有写完


    #!/bin/bash

    go_home="/work/go"
    go_root="/usr/local"
    go_bin="/work/go/bin"
    state="$1"
    app_name="medicalrecordservice"
    app_redis="redisservice"
    ipaddr=`ip a | grep ens | grep inet | grep -v 127.0.0.1 | grep -v inet6 | awk '{print $2}' | cut -d "/" -f1`
    echo $ipaddr
    echo $state

    function CreateCatalog(){
    if [ ! -x "$go_home" ];
    then
    mkdir -p "$go_home"
    echo "create catalog $go_home"
    else
    echo "$go_home catalog exists!"
    fi

    if [ ! -x "$go_root" ];
    then
    mkdir -p "$go_root"
    echo "create catalog $go_root"
    else
    echo "$go_root catalog exists!"
    fi

    if [ ! -x "$go_bin" ];
    then
    mkdir -p "$go_bin"
    echo "create catalog $go_bin"
    else
    echo "$go_bin exists!"
    fi
    }
    function Choose(){
    if [ $state = "install" ];then
    Install $1 $2
    fi
    if [ $state = "start" ];then
    Start
    fi
    if [ $state = "stop" ];then
    Stop
    fi
    if [ $state = "log" ];then
    Log
    fi
    }
    function Install(){
    medical_path="$2"
    go_path="$1"
    echo $go_path
    echo $medical_path
    if [ ! -f "$go_path" ];
    then
    echo "file $go_path is not exists"
    echo "please enter the correct file path"
    return
    fi
    tar -zxvf $go_path -C $go_root
    if [ $? -eq 0 ];
    then
    echo "tar $go_path success!"
    else
    echo "tar $go_path is error!"
    return
    fi
    echo "export GOROOT=$go_root/go" >> /etc/profile
    if [ $? -eq 0 ];
    then
    echo "add environment variable $GOROOT is success!"
    else
    echo "add environment variable $GOROOT is error!"
    return
    fi
    echo "export GOPATH=$go_home" >> /etc/profile
    if [ $? -eq 0 ];
    then
    echo "add environment variable $GOPATH is success!"
    else
    echo "add environment variable $GOPATH is error!"
    return
    fi
    echo "export GOBIN=$go_bin" >> /etc/profile
    if [ $? -eq 0 ];
    then
    echo "add environment variable $GOBIN is success!"
    else
    echo "add environment variable $GOBIN is error!"
    return
    fi
    sed -i '$a export PATH=$PATH:$GOROOT/bin:$GOBIN' /etc/profile
    if [ $? -eq 0 ];
    then
    echo "add environment variable $PATH is success!"
    else
    echo "add environment variable $PATH is error!"
    return
    fi
    source /etc/profile
    CreateCatalog
    if [ ! -f $medical_path ];
    then
    echo "file $medical_path is not exists"
    echo "please enter the correct file path"
    return
    fi
    echo $medical_path
    unzip $medical_path
    if [ $? -eq 0 ];
    then
    echo "unzip $medical_path is success!"
    else
    echo "unzip x $medical_path is error!"
    return
    fi
    /bin/cp -raf $PWD/$app_name/bin/* $go_bin
    if [ $? -eq 0 ];
    then
    echo "move $PWD/$app_name is success!"
    else
    echo "move $PWD/$app_name is error!"
    return
    fi
    echo $go_bin/$app_name
    if [ -f $go_bin/$app_name ];
    then
    chmod 766 $go_bin/$app_name
    if [ $? -eq 0 ];
    then
    echo "chmod x role $go_bin/$app_name is success!"
    else
    echo "chmod x role $go_bin/$app_name is error!"
    fi
    fi
    echo $go_bin/$app_redis
    if [ -f $go_bin/$app_redis ];
    then
    chmod 766 $go_bin/$app_redis
    if [ $? -eq 0 ];
    then
    echo "chmod x role $go_bin/$app_redis is success!"
    else
    echo "chmod x role $go_bin/$app_redis is error !"
    fi
    fi
    }
    function Start(){
    nohup $go_bin/$app_name >log.log 2>&1&
    if [ $? -eq 0 ];
    then
    echo "$go_bin/$app_name is start success!"
    else
    echo "$go_bin/$app_name is start error !"
    fi
    nohup $go_bin/$app_redis >redis.log 2>&1&
    if [ $? -eq 0 ];
    then
    echo "$go_bin/$app_redis is start success!"
    else
    echo "$go_bin/$app_redis is start error !"
    fi
    }
    function Stop(){
    pkill -f $app_name
    pkill -f $app_redis
    }
    Choose $2 $3

    分别支持,install ,start,stop,并修改项目配置文件ip地址,虽然比较简单,但还是比较好玩!

  • 相关阅读:
    yum安装nginx没有某一模块,该如何添加第三方模块?
    二进制部署K8S集群(二十四)k8s技术点整理
    opencv在python和c#中的对照应用-文字区域识别
    小区配置地图中心坐标
    Exception: No supported Visual Studio can be found. Supported versions are: 16.0 (2019), 15.0 (2017)
    文件包含
    kali linux 安装lanmp遇到的问题
    嵌入式实操----基于RT1170 首板硬件之SDRAM调试(十二)
    嵌入式实操----基于RT1170 DCD数据开发入门记录(十一)
    嵌入式实操----基于RT1170解决串口不支持float类型打印问题(十)
  • 原文地址:https://www.cnblogs.com/apolov-fabric/p/11535242.html
Copyright © 2020-2023  润新知