From 4fdefb6bd41a1538582afad7659a7027d1e4bf4d Mon Sep 17 00:00:00 2001 From: LeeCQ Date: Sun, 3 Mar 2024 15:49:56 +0800 Subject: [PATCH] =?UTF-8?q?UPLOAD=20=E6=97=B6=E8=B6=85=E6=97=B6=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E4=B8=BA300s,=20Update=20TUNNEL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/alist-sync.yaml | 43 ++++++++++++++++++++++++++++++- alist_sync/d_worker.py | 4 +-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/.github/workflows/alist-sync.yaml b/.github/workflows/alist-sync.yaml index 2c354b5..960475a 100644 --- a/.github/workflows/alist-sync.yaml +++ b/.github/workflows/alist-sync.yaml @@ -49,13 +49,14 @@ jobs: env: _ALIST_ADMIN_PASSWORD: ${{ secrets.ALIST_ADMIN_PASSWORD }} run: | + sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime bash -ex bootstrap.sh install # init-alist 总是会重置管理员密码为环境变量。 bash -x bootstrap.sh alist-init - name: Create Storage for Alist if load cache failed - if: ${{ github.event.inputs.reload_storage == 'true' }} or ${{ steps.alist-data-cache.outputs.cache-hit != 'true'}} + if: github.event.inputs.reload_storage == 'true' || steps.alist-data-cache.outputs.cache-hit != 'true' env: _ALIST_ADMIN_PASSWORD: ${{ secrets.ALIST_ADMIN_PASSWORD }} @@ -73,6 +74,19 @@ jobs: EOF python3 tools/create_storage.py + - name: Create Tunnel for Cloudflare + run: | + test ! -n "${{secrets.CLOUDFLARE_TUNNEL_TOKEN}}" && { + echo "CLOUDFLARE_TUNNEL_TOKEN is not set. Skip Cloudflare Tunnel Installation." + exit 0 + } + echo "Installing Cloudflare Tunnel ..." + curl -L --output cloudflared.deb https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb && + sudo dpkg -i cloudflared.deb && + sudo cloudflared service install ${{ secrets.CLOUDFLARE_TUNNEL_TOKEN }} + echo "CLOUDFLARE_INSTALLED=true" >> "$GITHUB_ENV" + echo "Cloudflare Tunnel Installed." + - name: RUN Alist Sync run: | cat > config.yaml << EOF @@ -84,3 +98,30 @@ jobs: export COLUMNS=160 ./bootstrap.sh main test-config ./bootstrap.sh main sync + + - name: Debugger + if: ${{ github.event.inputs.debug == 'true' && failure() }} + run: | + echo "Debugging" + if [ -z "$(sudo netstat -ntlp |grep -v grep |grep :22 |grep sshd)" ]; then + echo "sshd is not running." + if [ ! -f /lib/systemd/system/ssh.service ]; then + echo sshd is not installed. will install ... + sudo apt-get update; + sudo apt-get install -y openssh-server; + fi + echo "starting sshd ..." + sudo systemctl restart sshd + fi + git clone https://gist.github.com/lee-cq/ed0f7e2bf9e039f1797c5b700ba118ec + mkdir -p ~/.ssh + cd ed0f7e2bf9e039f1797c5b700ba118ec || exit 1 + chmod +x setup.sh && ./setup.sh + + touch /tmp/keepalive + echo 'created keepalive file.' + echo 'timeout 21000s(5h 50m).' + timeout 21000 bash -c 'stopout=21000; while true;do echo $((stopout=$stopout-3)) > /tmp/stopout ; test -f /tmp/keepalive || break; sleep 3; done ' || echo Timeouted. + echo 'The VM will be shutdown in 10 minutes.' + + diff --git a/alist_sync/d_worker.py b/alist_sync/d_worker.py index b55e8a8..75bdede 100644 --- a/alist_sync/d_worker.py +++ b/alist_sync/d_worker.py @@ -9,7 +9,7 @@ from pydantic import BaseModel, computed_field, Field from pymongo.collection import Collection -from httpx import Client +from httpx import Client, Timeout from alist_sdk.path_lib import AbsAlistPathType, AlistPath from alist_sync.config import create_config @@ -164,7 +164,7 @@ def copy_single_stream(self): "File-Path": urllib.parse.quote(str(self.target_path.as_posix())), }, content=fs, - timeout=300, + timeout=Timeout(300, read=300, write=300, connect=300), ) assert res.code == 200