-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
213 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# yukictl | ||
|
||
### Table of Content | ||
|
||
+ [Introduction](#introduction) | ||
+ [Handbook](#handbook) | ||
- [自动补全](#自动补全) | ||
- [获取同步状态](#获取同步状态) | ||
- [手动开始同步任务](#手动开始同步任务) | ||
- [更新仓库同步配置](#更新仓库同步配置) | ||
- [获取同步日志](#获取同步日志) | ||
|
||
### Introduction | ||
|
||
yuki 的命令行客户端。 | ||
|
||
### Handbook | ||
|
||
#### 自动补全 | ||
|
||
```bash | ||
# Zsh: | ||
$ yukictl completion zsh | ||
|
||
# Bash: | ||
$ yukictl completion bash | ||
``` | ||
|
||
#### 获取同步状态 | ||
|
||
```bash | ||
$ yukictl meta ls [repo] | ||
``` | ||
|
||
#### 手动开始同步任务 | ||
|
||
```bash | ||
$ yukictl sync <repo> | ||
``` | ||
|
||
开启同步任务的 debug 模式,并查看同步日志 | ||
```bash | ||
$ yukictl sync --debug <repo> | ||
``` | ||
|
||
#### 更新仓库同步配置 | ||
|
||
新增或修改完仓库的 YAML 配置后,需要执行下面的命令来更新配置。 | ||
```bash | ||
$ yukictl reload <repo> | ||
``` | ||
注意:在新增配置前需要先创建仓库相应的 `storageDir`。 | ||
|
||
如果不带任何参数的话,则该命令会更新所有仓库的同步配置,并且删除配置里没有但数据库里有的仓库配置。 | ||
```bash | ||
$ yukictl reload | ||
``` | ||
|
||
若需要删除仓库,则可以删除相应的配置文件然后执行 `yukictl repo rm <repo>` 或直接 `yukictl reload` 来从数据库里删除配置。 | ||
|
||
#### 获取同步日志 | ||
|
||
当前的同步日志: | ||
```bash | ||
$ yukictl ct logs <container ID or repo name> | ||
``` | ||
|
||
跟踪并从倒数第 5 行开始: | ||
```bash | ||
$ yukictl ct logs --tail 5 -f <container ID or repo name> | ||
``` | ||
|
||
列出以往的同步日志: | ||
```bash | ||
$ yukictl repo logs --stats <repo name> | ||
``` | ||
|
||
查看以往倒数第二次同步日志的倒数 10 行: | ||
```bash | ||
$ yukictl repo logs -n 1 --tail 10 <repo name> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# yukid | ||
|
||
### Table of Content | ||
* [Introduction](#introduction) | ||
* [Server Configuration](#server-configuration) | ||
* [Repo Configuration](#repo-configuration) | ||
|
||
### Introduction | ||
|
||
yukid 是 yuki 的服务端,负责定期同步仓库,并且提供 RESTful API 用于管理。 | ||
|
||
### Server Configuration | ||
|
||
yukid 的配置,路径 `/etc/yuki/daemon.toml` | ||
|
||
```toml | ||
## 设置 debug 为 true 后会打开 echo web 框架的 debug 模式 | ||
## 以及在日志里输出程序里打印日志的位置 | ||
#debug = true | ||
|
||
## 设置 MongoDB 地址 | ||
## 完整格式为 | ||
## [mongodb://][user:pass@]host1[:port1][,host2[:port2],...][/database][?options] | ||
#db_url = "127.0.0.1:27017" | ||
|
||
## 设置 db 名字 | ||
#db_name = "mirror" | ||
|
||
## 数据所在位置的文件系统 | ||
## 可选的值为 "zfs" | "xfs" | "default" | ||
## 影响获取仓库大小的方式,如果是 "default" 的话仓库大小恒为 `-1` | ||
fs = "default" | ||
|
||
## 每个仓库的同步配置存放的文件夹 | ||
## 每个配置的后缀名必须是 `.yaml` | ||
## 配置的格式参考下方 Repo Configuration | ||
repo_config_dir = "/path/to/config-dir" | ||
|
||
## 设置 Docker Daemon 地址 | ||
## unix local socket: unix:///var/run/docker.sock | ||
## tcp: tcp://127.0.0.1:2375 | ||
#docker_endpoint = "unix:///var/run/docker.sock" | ||
|
||
## 设置同步程序的运行时的 uid 跟 gid,会影响仓库文件的 uid 跟 gid | ||
## 格式为 uid:gid | ||
#owner = "1000:1000" | ||
|
||
## 设置日志所在文件夹 | ||
#log_dir = "/var/log/yuki/" | ||
|
||
## 设置 log level | ||
## 可选的值为 "debug" | "info" | "warn" | "error" | ||
#log_level = "info" | ||
|
||
## 设置监听地址 | ||
#listen_addr = "127.0.0.1:9999" | ||
|
||
## 设置同步仓库的时候默认绑定的 IP | ||
#bind_ip = "1.2.3.4" | ||
|
||
## 设置创建的 container 的名字前缀 | ||
#name_prefix = "syncing-" | ||
|
||
## 设置同步完后执行的命令 | ||
#post_sync = ["/path/to/the/program"] | ||
|
||
## 设置更新用到的 docker images 的频率 | ||
## 格式为 crontab | ||
#images_upgrade_interval = "@every 1h" | ||
``` | ||
|
||
### Repo Configuration | ||
|
||
yukid 启动的时候只会从数据库里读取仓库的同步配置,不会读取 `repo_config_dir` 下的配置,所以如果有新增配置的话需要执行 `yukictl reload` 来把配置写到数据库中。 | ||
|
||
存放在 `repo_config_dir` 下的每个仓库的同步配置,文件名必须以 `.yaml` 结尾。 | ||
|
||
示例如下。不同的 image 需要的 envs 可参考 [这里](https://github.com/ustclug/ustcmirror-images#table-of-content)。 | ||
```yaml | ||
name: bioc # required | ||
image: ustcmirror/rsync:latest # required | ||
interval: 2 2 31 4 * # required | ||
storageDir: /srv/repo/bioc # required | ||
logRotCycle: 1 # 保留多少次同步日志 | ||
bindIP: 1.2.3.4 | ||
retry: 2 # 同步失败后的重试次数 | ||
envs: # 传给同步程序的环境变量 | ||
RSYNC_HOST: rsync.exmaple.com | ||
RSYNC_PATH: / | ||
RSYNC_RSH: ssh -i /home/mirror/.ssh/id_rsa | ||
RSYNC_USER: bioc-rsync | ||
volumes: # 同步的时候需要挂载的 volume | ||
# 注意: 由于 MongoDB 的限制,key 不能包含 `.` | ||
/etc/passwd: /etc/passwd:ro | ||
/ssh: /home/mirror/.ssh:ro | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func PrettySize(size int64) string { | ||
if size < 0 { | ||
return "unknown" | ||
} | ||
const n = float64(1024) | ||
a := float64(size) | ||
units := []string{"B", "KiB", "MiB", "GiB"} | ||
for _, u := range units { | ||
if a < n { | ||
return fmt.Sprintf("%.1f %s", a, u) | ||
} | ||
a /= n | ||
} | ||
return fmt.Sprintf("%.1f TiB", a) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters