zhanghuaao commited on
Commit
850ea6b
·
1 Parent(s): ff0eb35

add keep alive

Browse files
Files changed (2) hide show
  1. Dockerfile +2 -0
  2. start.sh +15 -0
Dockerfile CHANGED
@@ -1,6 +1,8 @@
1
  FROM ubuntu:22.04
2
 
3
  ENV DEBIAN_FRONTEND=noninteractive
 
 
4
 
5
  # 基础依赖
6
  RUN apt-get update && apt-get install -y --no-install-recommends \
 
1
  FROM ubuntu:22.04
2
 
3
  ENV DEBIAN_FRONTEND=noninteractive
4
+ ENV PING_URL=https://zhanghuaao-code-server.hf.space/
5
+ ENV PING_INTERVAL=3600
6
 
7
  # 基础依赖
8
  RUN apt-get update && apt-get install -y --no-install-recommends \
start.sh CHANGED
@@ -1,6 +1,21 @@
1
  #!/usr/bin/env bash
2
  set -e
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  mkdir -p /home/coder/.config/code-server
5
 
6
  # 生成配置文件
 
1
  #!/usr/bin/env bash
2
  set -e
3
 
4
+ # ===== Keepalive: 后台定时 curl(可用环境变量控制)=====
5
+ PING_URL="${PING_URL:-}"
6
+ PING_INTERVAL="${PING_INTERVAL:-300}"
7
+
8
+ if [ -n "$PING_URL" ]; then
9
+ (
10
+ while true; do
11
+ echo "[keepalive] $(date -Iseconds) curl $PING_URL"
12
+ curl -fsS -L --max-time 20 "$PING_URL" >/dev/null 2>&1 || true
13
+ sleep "$PING_INTERVAL"
14
+ done
15
+ ) &
16
+ fi
17
+ # =========================================================
18
+
19
  mkdir -p /home/coder/.config/code-server
20
 
21
  # 生成配置文件