Skip to content

Commit

Permalink
添加ENV CRA2B=2h
Browse files Browse the repository at this point in the history
默认为2小时重启一次aria2b
可设置为1h到24h
CRA2B=false则为禁用自动重启aria2b
  • Loading branch information
SuperNG6 committed Aug 27, 2023
1 parent a053825 commit f4600f9
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Expand Up @@ -15,7 +15,8 @@ FROM lsiobase/alpine:3.17-69ac1933-ls26
# set label
LABEL maintainer="NG6"
ENV TZ=Asia/Shanghai UT=true SECRET=yourtoken CACHE=128M QUIET=true \
SMD=true RUT=true A2B=true PORT=6800 WEBUI=true WEBUI_PORT=8080 BTPORT=32516 \
SMD=true RUT=true A2B=true CRA2B=2h \
PORT=6800 WEBUI=true WEBUI_PORT=8080 BTPORT=32516 \
PUID=1026 PGID=100

# copy local files && aria2c
Expand Down
1 change: 0 additions & 1 deletion root/aria2/conf/rpc-tracker0
@@ -1,6 +1,5 @@
# do daily/weekly/monthly maintenance
# min hour day month weekday command
0 */2 * * * ps -ef | grep aria2b | grep -v grep | awk '{print $2}' | xargs kill -9
0 * * * * run-parts /etc/periodic/hourly
0 2 * * * run-parts /etc/periodic/daily
0 3 * * 6 run-parts /etc/periodic/weekly
Expand Down
3 changes: 1 addition & 2 deletions root/aria2/conf/rpc-tracker1
@@ -1,4 +1,3 @@
# do daily/weekly/monthly maintenance
# min hour day month weekday command
0 5 * * * bash /aria2/script/rpc_tracker.sh
0 */2 * * * ps -ef | grep aria2b | grep -v grep | awk '{print $2}' | xargs kill -9
0 5 * * * bash /aria2/script/rpc_tracker.sh
32 changes: 32 additions & 0 deletions root/aria2/script/cron-restart-a2b.sh
@@ -0,0 +1,32 @@
#!/bin/bash

# 获取环境变量 CRA2B 的值
CRA2B_VALUE=$CRA2B

# 检查 CRA2B 的值是否为 "false"
if [ "$CRA2B_VALUE" = "false" ]; then
# 删除现有的 aria2b cron 任务
(crontab -l | grep -v "ps -ef | grep aria2b | grep -v grep | awk '{print \$2}' | xargs kill -9") | crontab -
echo "CRA2B 设置为 false。已移除定时重启 aria2b 定时任务。"
else
# 检查 CRA2B 的值是否在 "1-24h" 范围内
if [[ $CRA2B_VALUE =~ ^[1-9]$|^1[0-9]$|^2[0-4]$ ]]; then
# 删除现有的 aria2b cron 任务
(crontab -l | grep -v "ps -ef | grep aria2b | grep -v grep | awk '{print \$2}' | xargs kill -9") | crontab -
echo "已移除现有的定时重启 aria2b 任务。"

# 设置新的 cron job,在每小时的整点执行杀死 aria2b 进程的命令
(crontab -l ; echo "0 */$CRA2B_VALUE * * * ps -ef | grep aria2b | grep -v grep | awk '{print \$2}' | xargs kill -9") | crontab -
echo "已设置定时任务,在每 $CRA2B_VALUE 小时的整点执行重启 aria2b 进程的命令。"
else
# 默认将 CRA2B 设置为 2 小时
CRA2B_VALUE=2
# 删除现有的 aria2b cron 任务
(crontab -l | grep -v "ps -ef | grep aria2b | grep -v grep | awk '{print \$2}' | xargs kill -9") | crontab -
echo "CRA2B 的值无效。已将 CRA2B 设置为默认值 2 小时。"

# 设置新的 cron job,在每小时的整点执行杀死 aria2b 进程的命令
(crontab -l ; echo "0 */$CRA2B_VALUE * * * ps -ef | grep aria2b | grep -v grep | awk '{print \$2}' | xargs kill -9") | crontab -
echo "已设置定时任务,在每 $CRA2B_VALUE 小时的整点执行重启 aria2b 进程的命令。"
fi
fi
1 change: 1 addition & 0 deletions root/etc/cont-init.d/30-config
Expand Up @@ -46,3 +46,4 @@ then
else
cp /aria2/conf/rpc-tracker0 /etc/crontabs/root
fi

3 changes: 3 additions & 0 deletions root/etc/cont-init.d/40-config
Expand Up @@ -7,3 +7,6 @@ chown -R abc:abc \

chmod a+x \
/aria2/script/*

# set cron-restart-a2b
bash /aria2/script/cron-restart-a2b.sh

0 comments on commit f4600f9

Please sign in to comment.