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 @@