zoukankan      html  css  js  c++  java
  • 第一个脚本部署案例,比较简单,还有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地址,虽然比较简单,但还是比较好玩!

  • 相关阅读:
    每日一题_191208
    每日一题_191207
    每日一题_191206
    每日一题_191205
    每日一题_191204
    每日一题_191203
    每日一题_191202
    每日一题_191201
    每日一题_191130
    2020届成都一诊理科16题
  • 原文地址:https://www.cnblogs.com/apolov-fabric/p/11535242.html
Copyright © 2011-2022 走看看