Spaces:
Paused
Paused
Download start_server.sh from Shadowfilebot/vs-code: direct link, hf CLI and curl.
- Browser
- Download file 2.75 kB
-
https://huggingface.co/spaces/Shadowfilebot/vs-code/resolve/main/start_server.sh
- Command line
-
hf download hf://spaces/Shadowfilebot/vs-code/start_server.sh
-
curl -L -o start_server.sh https://huggingface.co/spaces/Shadowfilebot/vs-code/resolve/main/start_server.sh
2.75 kB
| JUPYTER_TOKEN="${JUPYTER_TOKEN:=huggingface}" | |
| MC_PORT="${MC_PORT:=25565}" | |
| NOTEBOOK_DIR="/data" | |
| MC_DIR="$NOTEBOOK_DIR/minecraft" | |
| # Copy sẵn các file plugin từ repo vào /data/minecraft/plugins nếu có | |
| mkdir -p "$MC_DIR/plugins" | |
| if compgen -G "$HOME/app/*.jar" > /dev/null; then | |
| cp -u "$HOME/app"/*.jar "$MC_DIR/plugins/" 2>/dev/null || true | |
| fi | |
| # Tự động khởi động và Auto-restart Server Minecraft nếu tìm thấy file jar server | |
| ( | |
| while true; do | |
| SERVER_JAR=$(find "$MC_DIR" "$NOTEBOOK_DIR/server" -maxdepth 2 -type f \( -iname "*paper*.jar" -o -iname "*purpur*.jar" -o -iname "*spigot*.jar" -o -iname "*server*.jar" -o -iname "*forge*.jar" -o -iname "*fabric*.jar" -o -iname "*.jar" ! -iname "*Plugin*.jar" \) 2>/dev/null | head -n 1) | |
| if [ -n "$SERVER_JAR" ]; then | |
| JAR_DIR=$(dirname "$SERVER_JAR") | |
| echo "[$(date '+%Y-%m-%d %H:%M:%S')] [MC AUTO-RESTART] Khởi động Minecraft server: $SERVER_JAR" | tee -a "$NOTEBOOK_DIR/MC_SERVER.log" | |
| cd "$JAR_DIR" || exit | |
| java -Xms1G -Xmx${MC_RAM:-4G} -jar "$SERVER_JAR" nogui 2>&1 | tee -a "$NOTEBOOK_DIR/MC_SERVER.log" | |
| EXIT_CODE=$? | |
| echo "[$(date '+%Y-%m-%d %H:%M:%S')] [MC AUTO-RESTART] Server dừng với exit code $EXIT_CODE. Tự động khởi động lại sau 5 giây..." | tee -a "$NOTEBOOK_DIR/MC_SERVER.log" | |
| sleep 5 | |
| else | |
| sleep 10 | |
| fi | |
| done | |
| ) & | |
| # Tự động mở port ảo TCP 25565 bằng bore.pub (Không cần tài khoản, tự kết nối lại nếu đứt) | |
| ( | |
| while true; do | |
| bore local "$MC_PORT" --to bore.pub 2>&1 | while IFS= read -r line; do | |
| echo "$line" | |
| if [[ "$line" =~ (bore\.pub:[0-9]+) ]]; then | |
| echo "==========================================" > "$NOTEBOOK_DIR/IP_SERVER.txt" | |
| echo "ĐỊA CHỈ VÀO SERVER MINECRAFT:" >> "$NOTEBOOK_DIR/IP_SERVER.txt" | |
| echo "${BASH_REMATCH[1]}" >> "$NOTEBOOK_DIR/IP_SERVER.txt" | |
| echo "==========================================" >> "$NOTEBOOK_DIR/IP_SERVER.txt" | |
| fi | |
| done | |
| sleep 5 | |
| done | |
| ) & | |
| jupyter labextension disable "@jupyterlab/apputils-extension:announcements" | |
| jupyter-lab \ | |
| --ip 0.0.0.0 \ | |
| --port 7860 \ | |
| --no-browser \ | |
| --allow-root \ | |
| --ServerApp.token="$JUPYTER_TOKEN" \ | |
| --ServerApp.tornado_settings="{'headers': {'Content-Security-Policy': 'frame-ancestors *'}}" \ | |
| --ServerApp.cookie_options="{'SameSite': 'None', 'Secure': True}" \ | |
| --ServerApp.disable_check_xsrf=True \ | |
| --LabApp.news_url=None \ | |
| --LabApp.check_for_updates_class="jupyterlab.NeverCheckForUpdate" \ | |
| --notebook-dir=$NOTEBOOK_DIR |