Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cron 环境变量转义 & 新的环境变量 Ray_Crontab #256

Merged
merged 6 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ dotnet Ray.BiliBiliTool.Console.dll --runTasks=Daily&LiveLottery

* 确认没有同类 issue 后,自己可新建 issue,描述问题或建议

* 如果想自己解决,请 fork 仓库后,在**devlop 分支**进行编码开发,完成后**提交 pr 到 devlop 分支**,并标注解决的 issue 编号
* 如果想自己解决,请 fork 仓库后,在**develop 分支**进行编码开发,完成后**提交 pr 到 develop 分支**,并标注解决的 issue 编号

我会尽快进行代码审核,测试成功后会合并入 main 主分支,提前感谢您的贡献。

Expand Down
1 change: 1 addition & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Window系统推荐使用Docker Desktop,官方下载安装包,一路鼠标点
# 下载项目里面的模板,`my_crontab`文件以及`docker-compose.yml`文件

# 如需修改定时运行时间,请修改`my_crontab`中的cron表达式,然后再次执行启动容器命令。
# 或考虑配置`Ray_Crontab`环境变量
wget https://github.com/RayWangQvQ/BiliBiliToolPro/blob/main/docker/sample/my_crontab

# 根据 docker-compose.yaml 里面的注释编辑所需配置,`environment` 下可以通过环境变量自由添加自定义配置,其中Cookie是必填的,所以请至少填入Cookie并保存。
Expand Down
13 changes: 8 additions & 5 deletions docker/entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ set -e

# https://stackoverflow.com/questions/27771781/how-can-i-access-docker-set-environment-variables-from-a-cron-job
echo "[step 1/4]导入环境变量"
printenv | grep -v "no_proxy" > /etc/environment
declare -p | grep -v "no_proxy" > /etc/cron.env
echo "=>完成"

echo "[step 2/4]配置cron定时任务"
myarray=(`find /app -maxdepth 1 -name "custom_crontab"`)
if [ ${#myarray[@]} -gt 0 ]; then
echo "BASH_ENV=/etc/cron.env" > /etc/cron.d/bilicron
if ! [ -z $Ray_Crontab ]; then
echo "=>检测到对应的环境变量,使用其值作为配置"
echo $Ray_Crontab >> /etc/cron.d/bilicron
elif [ -e "/app/custom_crontab" ]; then
echo "=>检测到自定义了cron定时任务,使用自定义配置"
cp /app/custom_crontab /etc/cron.d/bilicron
cat /app/custom_crontab >> /etc/cron.d/bilicron
else
echo "=>使用默认cron定时任务配置"
cp /app/crontab /etc/cron.d/bilicron
cat /app/crontab >> /etc/cron.d/bilicron
fi
echo "=>完成"

Expand Down
21 changes: 21 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
- [3.7. 日志相关](#37-日志相关)
- [3.7.1. Console日志输出等级](#371-console日志输出等级)
- [3.7.2. Console日志输出样式](#372-console日志输出样式)
- [3.8. crontab相关](#38-crontab相关)

<!-- /TOC -->

Expand Down Expand Up @@ -642,6 +643,7 @@ https://cp.xuthus.cc/
| 默认值 | 空 |
| 环境变量 | `Ray_Serilog__WriteTo__8__Args__api` |
| GitHub Secrets | `PUSHOTHERAPI` |

<a id="markdown-3672-placeholder" name="3672-placeholder"></a>
##### 3.6.7.2. placeholder

Expand All @@ -652,6 +654,7 @@ https://cp.xuthus.cc/
| 默认值 | 空 |
| 环境变量 | `Ray_Serilog__WriteTo__8__Args__placeholder` |
| GitHub Secrets | `PUSHOTHERPLACEHOLDER` |

<a id="markdown-3673-bodyjsontemplate" name="3673-bodyjsontemplate"></a>
##### 3.6.7.3. bodyJsonTemplate

Expand Down Expand Up @@ -828,3 +831,21 @@ BiliBiliTool 使用 Serilog 作为日志组件,所以可以参考 Serilog 的
| 环境变量 | `Ray_Serilog__WriteTo__0__Args__outputTemplate` |
| GitHub Secrets | `CONSOLELOGTEMPLATE` |

<a id="markdown-38-crontab相关" name="38-crontab相关"></a>
#### 3.8 crontab相关
适用于 [方式四:docker容器化运行(推荐)](../docker/README.md),用于配置定时任务,效果与 `my_crontab` 文件相同,且优先级高于 `my_crontab`。

使用例:
```yaml
environment:
Ray_BiliBiliCookies: somecookies
Ray_Crontab: |
0 15 * * * dotnet /app/Ray.BiliBiliTool.Console.dll --runTasks=Daily >> /var/log/cron.log
0 22 * * * dotnet /app/Ray.BiliBiliTool.Console.dll --runTasks=LiveLottery >> /var/log/cron.log
```

| TITLE | CONTENT |
| ---------- | -------------- |
| 值域 | 一串字符串 |
| 默认值 | 空 |
| 环境变量 | `Ray_Crontab` |