diff --git a/auto_pt/urls.py b/auto_pt/urls.py index b4fc421..700fc9c 100644 --- a/auto_pt/urls.py +++ b/auto_pt/urls.py @@ -10,4 +10,5 @@ urlpatterns = [ path(r'test_notify', views.test_notify, name='test_notify'), path(r'restart', views.restart_container, name='restart_container'), path(r'do_restart', views.do_restart, name='do_restart'), + path(r'do_update', views.do_update, name='do_update'), ] diff --git a/auto_pt/views.py b/auto_pt/views.py index ad382e7..8bfd410 100644 --- a/auto_pt/views.py +++ b/auto_pt/views.py @@ -84,7 +84,8 @@ def do_restart(request): try: print('重启') # print(os.system('pwd')) - subprocess.Popen('./update.sh') + subprocess.Popen('chmod +x ./update.sh') + subprocess.Popen('./restart.sh') return JsonResponse(data=CommonResponse.success( msg='重启指令发送成功!!' ).to_dict(), safe=False) @@ -94,6 +95,23 @@ def do_restart(request): ).to_dict(), safe=False) +def do_update(request): + try: + print('更新') + # print(os.system('pwd')) + p = subprocess.Popen('chmod +x ./update.sh') + + subprocess.Popen('./update.sh') + p.wait() + return JsonResponse(data=CommonResponse.success( + msg='更新成功!!' + ).to_dict(), safe=False) + except Exception as e: + return JsonResponse(data=CommonResponse.error( + msg='更新指令发送失败!' + str(e) + ).to_dict(), safe=False) + + def restart_container(request): scraper = pt_spider.get_scraper() res = scraper.get('https://gitee.com/ngfchl/ptools/raw/master/update.md') diff --git a/restart.sh b/restart.sh new file mode 100644 index 0000000..e4978fc --- /dev/null +++ b/restart.sh @@ -0,0 +1 @@ +docker restart $CONTAINER_NAME diff --git a/templates/auto_pt/restart.html b/templates/auto_pt/restart.html index e78b166..c217a07 100644 --- a/templates/auto_pt/restart.html +++ b/templates/auto_pt/restart.html @@ -10,7 +10,8 @@
更新日志 - 重启更新 + 拉取更新 + 重启
@@ -69,6 +70,44 @@ }); }) + }).catch(res => { + console.log(res) + this.$message({ + type: 'info', + message: '已取消重启' + }); + }); + }, + do_update() { + this.$confirm('此操作会拉取软件更新软件,新版本不一定稳定,是否继续?', '提示', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning' + }).then(() => { + axios.get( + "{% url "do_update" %}" + {#url + '/task/do_restart'#} + ).then(res => { + if (res.data.code === 0) { + this.$message({ + type: 'success', + message: res.data.msg + }); + } else { + console.log(res) + this.$message({ + type: 'warning', + message: res.data.msg + }); + } + + }).catch(res => { + this.$message({ + type: 'error', + message: "更新失败!" + }); + }) + }).catch(res => { console.log(res) this.$message({ diff --git a/update.sh b/update.sh index 5e51660..51fd2f5 100755 --- a/update.sh +++ b/update.sh @@ -1,5 +1,5 @@ git pull https://gitee.com/ngfchl/ptools && python manage.py makemigrations && python manage.py migrate && - python manage.py loaddata db/pt.json && - docker restart $CONTAINER_NAME + python manage.py loaddata db/pt.json +