in script ~ read.

linux部署脚本

因为有多台 linux服务器, 在一台机器上编译完成后, 总是需要拷贝执行文件到其他节点, 并且启动, 操作十分繁琐, 使用如下脚本作为部署工具, 将它拷贝并执行/停止

使用方式:
./deploy.sh -version=debug -copy
./deploy.sh -start
./deploy.sh -stop

#!/bin/bash


USER=zhanghaoyu
VERSION=debug
STOP=0
COPY=0
START=0

if [ $# -eq 0 ]; then
    STOP=1
    COPY=1
    START=1
else
    for ARG  in $*
    do
        case "$ARG" in
            -start)
                START=1
                ;;
            -stop)
                STOP=1
                ;;
            -copy)
                COPY=1
                ;;
            -version=*)
                VERSION=`echo $ARG | cut -d= -f2`
                ;;
            *)
                echo "UNKNOW ARG"
                exit 3
                ;;
        esac
    done
fi

# SRC_FILE=xpkg/conf/ds.xml
SRC_FILE=build/$VERSION/bin/xcloudd
DES_DIR=/data0/$USER/xpkgExec/dsink/xpkg/bin
HOME_DIR=/data0/$USER/xpkgExec/dsink/xpkg
NODES="xcloud39 xcloud40 xcloud41 xcloud42 xcloud43 xcloud44"

function stop_func() {
for NODE in $NODES
do
    echo $NODE
    ssh $USER@$NODE << eeooff
    cd $HOME_DIR
    ./stop-xcloud.sh
    exit
eeooff
done
}

# STOP
if [ $STOP -eq 1 ]; then
    stop_func
fi

# COPY
if [ $COPY -eq 1 ]; then
    for NODE in $NODES
    do
        scp $SRC_FILE $USER@$NODE:$DES_DIR
    done
fi

function start_func() {
for NODE in $NODES
do
    ssh $USER@$NODE << eeooff
    cd $HOME_DIR
    ./start-xcloud.sh
    exit
eeooff
done
}

# START
if [ $START -eq 1 ]; then
    start_func
fi