Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit 7520286

Browse files
committed
optimize for log auto clear in Chinese Version
1 parent 078efe1 commit 7520286

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

install.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ fi
7373

7474
install_base() {
7575
if [[ x"${release}" == x"centos" ]]; then
76-
yum install wget curl tar -y
76+
yum install wget curl tar jq -y
7777
else
78-
apt install wget curl tar -y
78+
apt install wget curl tar jq -y
7979
fi
8080
}
8181

x-ui.sh

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ declare -r DEFAULT_LOG_FILE_DELETE_TRIGGER=35
1010

1111
# consts for geo update
1212
PATH_FOR_GEO_IP='/usr/local/x-ui/bin/geoip.dat'
13+
PATH_FOR_CONFIG='/usr/local/x-ui/bin/config.json'
1314
PATH_FOR_GEO_SITE='/usr/local/x-ui/bin/geosite.dat'
1415
URL_FOR_GEO_IP='https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat'
1516
URL_FOR_GEO_SITE='https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat'
@@ -519,8 +520,8 @@ ssl_cert_issue_standalone() {
519520
fi
520521
#install cert
521522
~/.acme.sh/acme.sh --installcert -d ${domain} --ca-file /root/cert/ca.cer \
522-
--cert-file /root/cert/${domain}.cer --key-file /root/cert/${domain}.key \
523-
--fullchain-file /root/cert/fullchain.cer
523+
--cert-file /root/cert/${domain}.cer --key-file /root/cert/${domain}.key \
524+
--fullchain-file /root/cert/fullchain.cer
524525

525526
if [ $? -ne 0 ]; then
526527
LOGE "证书安装失败,脚本退出"
@@ -604,8 +605,8 @@ ssl_cert_issue_by_cloudflare() {
604605
LOGI "证书签发成功,安装中..."
605606
fi
606607
~/.acme.sh/acme.sh --installcert -d ${CF_Domain} -d *.${CF_Domain} --ca-file /root/cert/ca.cer \
607-
--cert-file /root/cert/${CF_Domain}.cer --key-file /root/cert/${CF_Domain}.key \
608-
--fullchain-file /root/cert/fullchain.cer
608+
--cert-file /root/cert/${CF_Domain}.cer --key-file /root/cert/${CF_Domain}.key \
609+
--fullchain-file /root/cert/fullchain.cer
609610
if [ $? -ne 0 ]; then
610611
LOGE "证书安装失败,脚本退出"
611612
rm -rf ~/.acme.sh/${CF_Domain}
@@ -740,21 +741,33 @@ clear_log() {
740741
#enable auto delete log,need file path as
741742
enable_auto_clear_log() {
742743
LOGI "设置定时清除xray日志..."
743-
local filePath=''
744-
read -p "请输入日志文件路径": filePath
745-
if [[ ! -n ${filePath} ]]; then
746-
LOGI "输入的日志文件路径无效,脚本退出"
744+
local accessfilePath=''
745+
local errorfilePath=''
746+
accessfilePath=$(cat ${PATH_FOR_CONFIG} | jq .log.access | tr -d '"')
747+
errorfilePath=$(cat ${PATH_FOR_CONFIG} | jq .log.error | tr -d '"')
748+
if [[ ! -n ${accessfilePath} && ! -n ${errorfilePath} ]]; then
749+
LOGI "配置文件中的日志文件路径无效,脚本退出"
747750
exit 1
748751
fi
749-
if [[ ! -f ${filePath} ]]; then
750-
LOGE "${filePath}不存在,设置定时清除xray日志失败"
751-
exit 1
752+
if [[ -f ${accessfilePath} ]]; then
753+
crontab -l >/tmp/crontabTask.tmp
754+
echo "30 4 */2 * * x-ui clear ${accessfilePath} > /dev/null" >>/tmp/crontabTask.tmp
755+
crontab /tmp/crontabTask.tmp
756+
rm /tmp/crontabTask.tmp
757+
LOGI "设置定时清除xray日志:${accessfilePath}成功"
758+
else
759+
LOGE "accesslog不存在,将不会为其设置定时清除"
760+
fi
761+
762+
if [[ -f ${errorfilePath} ]]; then
763+
crontab -l >/tmp/crontabTask.tmp
764+
echo "30 4 */2 * * x-ui clear ${errorfilePath} > /dev/null" >>/tmp/crontabTask.tmp
765+
crontab /tmp/crontabTask.tmp
766+
rm /tmp/crontabTask.tmp
767+
LOGI "设置定时清除xray日志:${errorfilePath}成功"
768+
else
769+
LOGE "errorlog不存在,将不会为其设置定时清除"
752770
fi
753-
crontab -l >/tmp/crontabTask.tmp
754-
echo "30 4 */2 * * x-ui clear ${filePath} > /dev/null" >>/tmp/crontabTask.tmp
755-
crontab /tmp/crontabTask.tmp
756-
rm /tmp/crontabTask.tmp
757-
LOGI "设置定时清除xray日志成功"
758771
}
759772

760773
#disable auto dlete log

0 commit comments

Comments
 (0)