Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
默认为2小时重启一次aria2b 可设置为1h到24h CRA2B=false则为禁用自动重启aria2b
- Loading branch information
Showing
6 changed files
with
39 additions
and
4 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
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 |
---|---|---|
@@ -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 |
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,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 |
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 |
---|---|---|
|
@@ -46,3 +46,4 @@ then | |
else | ||
cp /aria2/conf/rpc-tracker0 /etc/crontabs/root | ||
fi | ||
|
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 |
---|---|---|
|
@@ -7,3 +7,6 @@ chown -R abc:abc \ | |
|
||
chmod a+x \ | ||
/aria2/script/* | ||
|
||
# set cron-restart-a2b | ||
bash /aria2/script/cron-restart-a2b.sh |