File size: 4,345 Bytes
2e03dd9 65e02d8 35b9d37 2e03dd9 35b9d37 2e03dd9 35b9d37 65e02d8 35b9d37 11c931f 65e02d8 35b9d37 2c9a32e 65e02d8 11c931f 35b9d37 65e02d8 35b9d37 65e02d8 35b9d37 65e02d8 35b9d37 65e02d8 2c9a32e 35b9d37 11c931f 65e02d8 35b9d37 65e02d8 2e03dd9 11c931f 65e02d8 11c931f 2c9a32e 65e02d8 11c931f 65e02d8 11c931f 65e02d8 11c931f 2c9a32e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | #!/bin/bash
# 调试信息 - 非常重要!
echo "===== Debug Info ====="
echo "User: $(whoami)"
echo "Home: $HOME"
echo "UID: $(id -u)"
echo "GID: $(id -g)"
echo "Working dir: $(pwd)"
echo "Files in $HOME:"
ls -la $HOME
echo "Files in $HOME/.config:"
ls -la $HOME/.config || echo "No .config directory"
echo "Files in $HOME/.local/share:"
ls -la $HOME/.local/share || echo "No .local/share directory"
echo "======================"
# 1. 修复 Nginx 权限问题
cat > /tmp/nginx.conf <<EOF
worker_processes auto;
pid /tmp/nginx.pid;
events {
worker_connections 1024;
}
http {
client_body_temp_path /tmp/client_body;
fastcgi_temp_path /tmp/fastcgi_temp;
proxy_temp_path /tmp/proxy_temp;
scgi_temp_path /tmp/scgi_temp;
uwsgi_temp_path /tmp/uwsgi_temp;
server {
listen 7860;
root /var/www/html;
index index.html;
}
}
EOF
# 启动 Nginx
echo "Starting Nginx..."
nginx -c /tmp/nginx.conf -g "daemon off;" &
# 2. WebDAV同步 - 启动时恢复数据
echo "=== WebDAV Sync Setup ==="
if [[ "${WEBDAV_SYNC_ENABLED:-true}" == "true" ]]; then
echo "WebDAV sync is enabled, attempting to restore data..."
if /webdav-sync.sh restore; then
echo "Data restored from WebDAV successfully"
else
echo "Failed to restore from WebDAV, continuing with fresh setup"
fi
else
echo "WebDAV sync is disabled"
fi
echo "=========================="
# 3. 修复 code-server 权限问题
# 确保目录存在
mkdir -p $HOME/.config/code-server
mkdir -p $HOME/.local/share/code-server
mkdir -p $HOME/.local/share/code-server/extensions
mkdir -p $HOME/workspace
mkdir -p $HOME/projects
# 设置 VS Code 密码
PASSWORD=${VSCODE_PASSWORD:-"your_strong_password"}
export PASSWORD
# 启动 VS Code (添加详细日志)
echo "Starting code-server with extra logging..."
code-server \
--bind-addr 0.0.0.0:8080 \
--auth password \
--disable-telemetry \
--disable-update-check \
--log debug \
--verbose \
--config $HOME/.config/code-server/config.yaml \
--user-data-dir $HOME/.local/share/code-server \
--extensions-dir $HOME/.local/share/code-server/extensions \
$HOME/workspace 2>&1 | tee /tmp/code-server.log &
# 等待 code-server 启动
echo "Waiting for code-server to start..."
sleep 5
# 检查 code-server 是否在运行
if ! pgrep -f "code-server" > /dev/null; then
echo "ERROR: code-server failed to start!"
echo "--- code-server logs ---"
cat /tmp/code-server.log || echo "No logs available"
echo "-----------------------"
exit 1
fi
# 检查端口监听
echo "Checking network status:"
echo "Processes:"
ps aux
echo "Port 8080:"
ss -tulpn | grep 8080 || echo "No process listening on 8080"
# 3. 启动 Cloudflare Tunnel
echo "Starting Cloudflare Tunnel..."
cloudflared tunnel run --token $TUNNEL_TOKEN 2>&1 | tee /tmp/cloudflared.log &
# 4. 启动定期备份任务
if [[ "${WEBDAV_SYNC_ENABLED:-true}" == "true" ]]; then
echo "Starting periodic WebDAV backup..."
(
# 等待5分钟后开始第一次备份
sleep 300
while true; do
echo "=== Periodic WebDAV Backup ==="
if /webdav-sync.sh backup; then
echo "Periodic backup completed successfully"
else
echo "Periodic backup failed"
fi
echo "=============================="
# 每5分钟备份一次
sleep 300
done
) &
fi
# 5. 添加保活机制(防止容器退出)
echo "All services started. Waiting and pinging services periodically..."
LOOP_COUNT=0
while true; do
# 每30秒检查一次服务状态
echo "Service status (Loop: $LOOP_COUNT):"
echo "- Nginx: $(pgrep nginx | wc -l) processes"
echo "- code-server: $(pgrep -f "code-server" | wc -l) processes"
echo "- cloudflared: $(pgrep cloudflared | wc -l) processes"
# 访问本地服务保持活跃
curl -s http://localhost:7860 > /dev/null || echo "Nginx ping failed"
curl -s http://localhost:8080 > /dev/null || echo "code-server ping failed"
# 每10分钟显示一次WebDAV同步状态
if [[ $((LOOP_COUNT % 20)) -eq 0 ]] && [[ "${WEBDAV_SYNC_ENABLED:-true}" == "true" ]]; then
echo "WebDAV sync status: Enabled (backup every 5 minutes)"
fi
LOOP_COUNT=$((LOOP_COUNT + 1))
sleep 30
done |