diff --git a/auto_pt/views.py b/auto_pt/views.py index 1eb4a0b..af2ee27 100644 --- a/auto_pt/views.py +++ b/auto_pt/views.py @@ -1163,8 +1163,11 @@ def get_config_api(request): msg=res.msg ).to_dict(), safe=False) if request.GET.get('name') == 'hosts': - file_path = '/etc/hosts' + file_path = os.path.join(BASE_DIR, 'db/hosts') try: + if not os.path.exists(file_path): + subprocess.Popen('touch db/hosts', shell=True, stdout=subprocess.PIPE, ) + pass with open(file_path, 'rb') as f: response = HttpResponse(f) logger.info(response) @@ -1187,7 +1190,7 @@ def save_config_api(request): if content.get('name') == 'ptools.toml': file_path = os.path.join(BASE_DIR, 'db/ptools.toml') if content.get('name') == 'hosts': - file_path = '/etc/hosts' + file_path = os.path.join(BASE_DIR, 'db/hosts') try: with open(file_path, 'w') as f: f.write(content.get('settings')) diff --git a/start.sh b/start.sh index 5924321..6ae00f9 100644 --- a/start.sh +++ b/start.sh @@ -33,12 +33,17 @@ echo "列出代码文件信息" ls -l echo "安装并升级pip依赖" pip install -r requirements.txt -U -echo "写入U2 hosts" -echo 172.64.153.252 u2.dmhy.org >>/etc/hosts -echo 104.25.26.31 u2.dmhy.org >>/etc/hosts -echo 104.25.61.106 u2.dmhy.org >>/etc/hosts -echo 104.25.62.106 u2.dmhy.org >>/etc/hosts -echo 172.67.98.15 u2.dmhy.org >>/etc/hosts +if [ ! -f db/hosts ]; then + echo "未自定义HOSTS,默认写入" + echo 172.64.153.252 u2.dmhy.org >>/etc/hosts + echo 104.25.26.31 u2.dmhy.org >>/etc/hosts + echo 104.25.61.106 u2.dmhy.org >>/etc/hosts + echo 104.25.62.106 u2.dmhy.org >>/etc/hosts + echo 172.67.98.15 u2.dmhy.org >>/etc/hosts +else + echo '存在自定义HOSTS文件,apply' + mv db/hosts /etc/hosts +fi echo "启动服务" python manage.py migrate python manage.py runserver 0.0.0.0:$DJANGO_WEB_PORT diff --git a/templates/auto_pt/status.html b/templates/auto_pt/status.html index de4db79..5c8db89 100644 --- a/templates/auto_pt/status.html +++ b/templates/auto_pt/status.html @@ -373,27 +373,20 @@
+ 签到 + + + 更新 数据 - - 签到 - - - - 签到 - - - -