Android Source:优雅的repo sync自动重试
来源:互联网 发布:freebsd linux 编辑:程序博客网 时间:2024/05/16 17:28
问题
下载代码被墙
修改 hosts 文件
repo sync
时候卡住repo sync
时候中断
代码
要保证同时只有一个
repo
在运行
#!/bin/bash# 当前 repo sync 进程的 pidPID=kill_all_prog() { # 用ps找出所有的repo, 然后kill掉 echo "kill all prog(s)" PIDS=`ps aux |grep python|grep [r]epo |awk '{print $2}'` [[ -n $PIDS ]] && kill $PIDS}kill_prog() { # kill 当前repo sync子进程 if [[ -n $PID ]]; then echo "kill : $PID" kill $PID fi}start_sync() { # 启动子进程(使用coproc) coproc syncproc { repo sync; } PID=$syncproc_PID}restart_sync() { kill_prog kill_all_prog start_sync}# 如果网络流量在retry_delay时间内小于min_speed, 则认为repo sync已经卡住了min_speed="50"retry_delay=300((counter=0))((n_retries=0))kill_all_progrestart_syncwhile [[ 1 ]]; do # 用ifstat检测网速 speed=`ifstat 1 1 | tail -n 1 | awk '{print $1}'` result=$(echo "$speed < $min_speed" | bc) if [[ $result == "1" ]]; then ((counter++)) else ((counter=0)) fi if [[ `ps -p $PID| wc -l` == "1" ]]; then # 检测到子进程已经退出(ps已经查不到它了) # 用wait取得子进程返回值 wait $PID if [[ $? -eq 0 ]]; then echo "sync successful" break else echo "sync failed" ((counter=0)) ((n_retries++)) restart_sync continue fi fi if ((counter > retry_delay)); then ((counter=0)) echo "netspeed low. restart!" ((n_retries++)) restart_sync elif [[ counter -gt 20 ]]; then echo -e "\n" "netspeed low counter is " $counter "\n"; fidoneecho "completed with $n_retries retries"
废弃的代码
下面代码也是要保证只能有一个 repo
命令执行,且执行成功后还会执行
#!/bin/bash# FIXME: 只允许同时一个repo运行kill_prog() { # 用ps找出所有的repo, 然后kill掉 PID=`ps aux |grep python|grep [r]epo |awk '{print $2}'` [[ -n $PID ]] && kill $PID}start_sync() { repo sync &}restart_sync() { kill_prog start_sync}# 如果网络流量在retry_delay时间内小于min_speed, 则认为repo sync已经卡住了min_speed="50"retry_delay=600((counter=0))((n_retries=0))restart_syncwhile [[ 1 ]]; do # 用ifstat检测网速 speed=`ifstat 1 1 | tail -n 1 | awk '{print $1}'` result=$(echo "$speed < $min_speed" | bc) if [[ $result == "1" ]]; then ((counter++)) else ((counter=0)) fi if ((counter > retry_delay)); then ((counter=0)) echo "netspeed low. restart!" ((n_retries++)) restart_sync elif [[ counter -gt 10 ]]; then echo -e "\n" "netspeed low counter is " $counter "\n"; fidoneecho "completed with $n_retries retries"
来自
http://blog.csdn.net/xia0pang/article/details/20281071
0 0
- Android Source:优雅的repo sync自动重试
- 优雅的repo sync自动重试
- 优雅的repo sync自动重试
- repo sync失败后自动重试
- repo sync 获取Android Source 遭遇 the remote end hung up unexpectedly 的解决办法
- 自动repo sync脚本
- repo sync 时的自动续接脚本[转]
- Android 的source (需安装 git repo)
- 下载android源码repo sync失败的解决办法
- 下载android源码repo sync失败的解…
- android 源码下载中遇到的问题 repo sync
- 如何正确的repo sync?
- 自动repo sync脚本,记得chmod哟~
- repo sync 自动重启脚本
- repo sync
- repo sync 时自动切换当前分支的remote track分支的问题
- Android源码下载repo sync脚本
- linux 下 android 源码下载 (repo sync)
- 创建GitHub技术博客全攻略
- [C++] 智能指针与循环引用
- 如何在JavaScript捕获鼠标事件
- 生成闭区间随机指定维度数组方法
- 自然语言处理(NLP)网上资源整理
- Android Source:优雅的repo sync自动重试
- PHP基础----PHP常用功能----07PHP 字符串
- 2015.9.4 打印一个学生的成绩数组
- NLP资源
- PHP基础----PHP常用功能----08PHP 数组
- 'VB编程 编写一个竞赛评分的函数过程。评委打分为参数(数组参数),选手得分为函数值。记分规则为:去掉一个最高分,去掉一个最低分,然后求平均。调用该函数,由键盘输入5个评委的打分(存放在数组中),输出
- 自然语言处理工具2
- 不再受别人影响
- 自然语言处理工具1