##############################################################
# 部署脚本
##############################################################
#!/bin/bash

set -e

app_name=$1
remote_host=$2
password=$3

if [[ -z ${app_name} ]] || [ -z ${remote_host} ] || [ -z ${password} ]; then
  echo 'error: sh deploy.sh build remote_host password'
  exit -1
fi

# 存放应用的根目录
#remote_jar_home="/opt/services/dmaster"
#remote_jar_home="/opt/services/dagent"
remote_jar_home="/opt/apps/dagent"
local_jar_home="/home/reghao/dev/tmp/apps"
cd ${local_jar_home}/${app_name}

# 拷贝 runner.sh 到远程主机
sshpass -p ${password} scp runner.sh root@${remote_host}:${remote_jar_home}
# 拷贝应用到远程主机
sshpass -p ${password} scp ${app_name}.jar root@${remote_host}:${remote_jar_home}
# 运行远程主机上的应用
#sshpass -p ${password} ssh root@${remote_host} "source /etc/profile && cd ${remote_jar_home} && sh runner.sh start"
