Skip to content

Commit

Permalink
feat: add deploy scripts of vm (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsy1001de authored Jul 2, 2024
1 parent 8524f55 commit 5c7ffcf
Show file tree
Hide file tree
Showing 15 changed files with 556 additions and 3 deletions.
1 change: 0 additions & 1 deletion pkg/server/gateway/pb/gateway-for-agent.proto
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ service GatewayService {
// 查询控制参数
rpc get_control_configs(GetControlConfigsRequest) returns(GetControlConfigsResponse) {}

// deprecated
rpc write_metrics_v1 (WriteMetricsRequestV1) returns (WriteMetricsResponse) {}

// deprecated
Expand Down
3 changes: 1 addition & 2 deletions pkg/server/gateway/pb/gateway-for-agent_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions scripts/vm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 介绍
VM模式下的相关脚本.
该脚本可以在 Mac m1 或 Linux 上执行, 要求机器上装有 docker. Mac m1 特别慢, 建议在 Linux 上执行, 可以通过 rsync 将代码复制到 Linux 上再构建.

# 使用
```bash
./scripts/vm/build.sh 1.0.0
```

构建的结果在 `/root/workspace/remote/cloudmonitor-agent/scripts/vm/holoinsight-agent_linux-amd64_1.0.0.tar.gz`

之后我们把它上传到 OSS, 给用户下载安装即可.
```bash
./scripts/vm/upload.sh 1.0.0
```
22 changes: 22 additions & 0 deletions scripts/vm/agent.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[program:agent]
command=/usr/local/holoinsight/agent/bin/agent.sh
process_name=%(program_name)s
autostart=true
# 启动后持续3秒处于RUNNING状态则认为启动成功
#startsecs=3
# 重试
startretries=3
autorestart=unexpected
exitcodes=0,7
stopsignal=TERM
stopwaitsecs=3
stopasgroup=true
killasgroup=true
redirect_stderr=true
stdout_logfile=/usr/local/holoinsight/agent/logs/stdout.log
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=10
stdout_capture_maxbytes=0
stdout_events_enabled=true
#environment=KEY="val",KEY2="val2"
directory=/usr/local/holoinsight/agent
14 changes: 14 additions & 0 deletions scripts/vm/agent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

export GOTRACEBACK=all
export GODEBUG=gctrace=1,madvdontneed=1

script_dir=`dirname $0`

# 如果文件存在就从它加载一些环境变量
if [ -e "$script_dir/env.sh" ]; then
source $script_dir/env.sh
fi

exec $script_dir/agent

42 changes: 42 additions & 0 deletions scripts/vm/build-lite.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
set -e

# VM 模式下的打包: 打成 tar 包, 用户下载之后解压启动即可

script_dir=`dirname $0 | xargs realpath`
project_root=`realpath $script_dir/../..`

version=` cat $project_root/VERSION `

echo '[build vm lite agent package]'

# tar 包目录结构:
# /bin
# /agent agent 本体
# /data
# /agent.yaml 配置文件, install 时生成

echo script dir is $script_dir
echo project root is $project_root

tmpdir=`mktemp -d`
agent_home=$tmpdir/agent

mkdir -p $agent_home/{bin,data,conf,logs}

echo temp agent home $agent_home

$script_dir/../build/build-using-docker.sh

cp $script_dir/../../build/linux-amd64/bin/agent $agent_home/bin/agent

echo
echo ls -lh $agent_home
ls -lh $agent_home
echo

build_target=$project_root/build/linux-amd64/holoinsight-agent-lite_linux-amd64_${version}.tar.gz
echo "build to $build_target"
cd $tmpdir/agent && tar -zcf $build_target *

echo you should upload $build_target to your OSS
46 changes: 46 additions & 0 deletions scripts/vm/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash
set -e

# VM 模式下的打包: 打成 tar 包, 用户下载之后解压启动即可

script_dir=`dirname $0 | xargs realpath`
project_root=`realpath $script_dir/../..`

version=` cat $project_root/VERSION `

echo '[build vm agent package]'

# tar 包目录结构:
# /bin
# /agent agent 本体
# /data
# /agent.yaml 配置文件, install 时生成

echo script dir is $script_dir
echo project root is $project_root

tmpdir=`mktemp -d`
agent_home=$tmpdir/agent

mkdir -p $agent_home/{bin,data,conf,logs}

echo temp agent home $agent_home

cp $script_dir/{supervisord,supervisord.conf,ctl.sh,agent.ini,agent.sh,uninstall.sh} $agent_home/bin/

cp $script_dir/initd_holoinsight-agent.sh $agent_home/bin/initd_holoinsight-agent.sh

$script_dir/../build/build-using-docker.sh

cp $script_dir/../../build/linux-amd64/bin/agent $agent_home/bin/agent

echo
echo ls -lh $agent_home
ls -lh $agent_home
echo

build_target=$project_root/build/linux-amd64/holoinsight-agent_linux-amd64_${version}.tar.gz
echo "build to $build_target"
cd $tmpdir/agent && tar -zcf $build_target *

echo you should upload $build_target to your OSS
81 changes: 81 additions & 0 deletions scripts/vm/ctl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env bash
set -e

bin_dir=`dirname $0`
bin_dir=`cd $bin_dir && echo $PWD`
echo bin_dir is $bin_dir

SUPERVISORD_BIN=$bin_dir/supervisord
SUPERVISORD_CONF=${SUPERVISORD_BIN}.conf
SUPERVISORD_PID_FILE=$bin_dir/../run/supervisord.pid


function start() {
# TODO 防止重复启动
if [ -e "$SUPERVISORD_PID_FILE" ]; then
pid=`cat $SUPERVISORD_PID_FILE`
if ps -p $pid >/dev/null; then
# PID 存在
return
else
rm -f $SUPERVISORD_PID_FILE
# 文件存在但pid不存在, 启动
$SUPERVISORD_BIN -c $SUPERVISORD_CONF -d
fi
else
# pid文件不存在, 启动
$SUPERVISORD_BIN -c $SUPERVISORD_CONF -d
fi

$SUPERVISORD_BIN -c $SUPERVISORD_CONF ctl start agent
}

function stop() {
$SUPERVISORD_BIN -c $SUPERVISORD_CONF ctl stop agent

out=`$SUPERVISORD_BIN -c $SUPERVISORD_CONF ctl shutdown`
if [ "Shut Down" != "$out" ] && [ "Hmmm! Something gone wrong?!" != "$out" ]; then
echo "stop supervisord: $out"
fi

if [ -e "$SUPERVISORD_PID_FILE" ]; then
pid=`cat $SUPERVISORD_PID_FILE`
if ps -p $pid >/dev/null 2>&1; then
kill $pid || true
fi
rm $SUPERVISORD_PID_FILE
fi

pid=`ps aux | grep $SUPERVISORD_BIN | grep -v grep | awk '{ print $2 }'`
if [ -n "$pid" ]; then
kill $pid || true
fi
}

function restart() {
$SUPERVISORD_BIN -c $SUPERVISORD_CONF ctl restart agent
}

function status() {
$SUPERVISORD_BIN -c $SUPERVISORD_CONF ctl status agent
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo 'usage: ctl.sh <start|stop|restart|status>'
exit 1
;;
esac

5 changes: 5 additions & 0 deletions scripts/vm/initd_holoinsight-agent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -e

# 开机自启动时会调用这个脚本
exec /usr/local/holoinsight/agent/bin/ctl.sh "$@"
Loading

0 comments on commit 5c7ffcf

Please sign in to comment.