Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-25 08:29:08

0001 #!/bin/bash
0002 # Nightly update of PanDA bot MCP servers.
0003 # For each server repo: git pull, if new commits found run rebuild, track changes.
0004 # If any server updated, restart the bot so it picks up the new code.
0005 # Run via cron: 30 3 * * * /data/wenauseic/github/swf-monitor/scripts/update_mcp_servers.sh
0006 
0007 set -uo pipefail
0008 
0009 GITHUB_DIR="/data/wenauseic/github"
0010 NODE_PATH="/eic/u/wenauseic/.nvm/versions/node/v22.17.0/bin"
0011 VENV_BIN="$GITHUB_DIR/swf-testbed/.venv/bin"
0012 LOG="/tmp/mcp_servers_update.log"
0013 BOT_SERVICE="swf-panda-bot"
0014 
0015 exec > "$LOG" 2>&1
0016 echo "=== MCP server update $(date -u +%Y-%m-%dT%H:%M:%SZ) ==="
0017 
0018 CHANGED=0
0019 
0020 pull_and_check() {
0021     local name="$1"
0022     local dir="$2"
0023 
0024     if [ ! -d "$dir/.git" ]; then
0025         echo "--- $name: $dir not found, skipping"
0026         return 1
0027     fi
0028 
0029     echo "--- $name"
0030     local before
0031     before=$(git -C "$dir" rev-parse HEAD)
0032     # Stash any local changes (e.g. package-lock.json from npm install)
0033     local stashed=0
0034     if ! git -C "$dir" diff --quiet 2>/dev/null; then
0035         git -C "$dir" stash -q 2>&1 && stashed=1
0036     fi
0037     git -C "$dir" pull --ff-only 2>&1 || { echo "  WARN: pull failed"; [ "$stashed" -eq 1 ] && git -C "$dir" stash pop -q 2>/dev/null; return 1; }
0038     [ "$stashed" -eq 1 ] && git -C "$dir" stash pop -q 2>/dev/null || true
0039     local after
0040     after=$(git -C "$dir" rev-parse HEAD)
0041 
0042     if [ "$before" = "$after" ]; then
0043         echo "  no changes"
0044         return 1
0045     else
0046         echo "  updated: ${before:0:8} → ${after:0:8}"
0047         return 0
0048     fi
0049 }
0050 
0051 # --- xrootd (Node.js) ---
0052 if pull_and_check "xrootd" "$GITHUB_DIR/xrootd-mcp-server"; then
0053     echo "  rebuilding..."
0054     export PATH="$NODE_PATH:$PATH"
0055     (cd "$GITHUB_DIR/xrootd-mcp-server" && npm install && npm run build) 2>&1
0056     if [ $? -eq 0 ]; then
0057         echo "  rebuild OK"
0058         CHANGED=1
0059     else
0060         echo "  ERROR: rebuild failed"
0061     fi
0062 fi
0063 
0064 # --- github (Go) ---
0065 if pull_and_check "github" "$GITHUB_DIR/github-mcp-server"; then
0066     echo "  rebuilding..."
0067     (cd "$GITHUB_DIR/github-mcp-server" && PATH=$PATH:/usr/local/go/bin go build -o github-mcp-server ./cmd/github-mcp-server) 2>&1
0068     if [ $? -eq 0 ]; then
0069         echo "  rebuild OK"
0070         CHANGED=1
0071     else
0072         echo "  ERROR: rebuild failed"
0073     fi
0074 fi
0075 
0076 # --- zenodo (Node.js) ---
0077 if pull_and_check "zenodo" "$GITHUB_DIR/zenodo-mcp-server"; then
0078     echo "  rebuilding..."
0079     export PATH="$NODE_PATH:$PATH"
0080     (cd "$GITHUB_DIR/zenodo-mcp-server" && npm install && npm run build) 2>&1
0081     if [ $? -eq 0 ]; then
0082         echo "  rebuild OK"
0083         CHANGED=1
0084     else
0085         echo "  ERROR: rebuild failed"
0086     fi
0087 fi
0088 
0089 # --- lxr (Python, no build needed) ---
0090 if pull_and_check "lxr" "$GITHUB_DIR/lxr-mcp-server"; then
0091     echo "  no build step needed"
0092     CHANGED=1
0093 fi
0094 
0095 # --- uproot (Python, pip install) ---
0096 if pull_and_check "uproot" "$GITHUB_DIR/uproot-mcp-server"; then
0097     echo "  rebuilding..."
0098     ("$VENV_BIN/pip" install -e "$GITHUB_DIR/uproot-mcp-server[xrootd]") 2>&1
0099     if [ $? -eq 0 ]; then
0100         echo "  rebuild OK"
0101         CHANGED=1
0102     else
0103         echo "  ERROR: rebuild failed"
0104     fi
0105 fi
0106 
0107 # --- rucio-eic (Python, pip install) ---
0108 if pull_and_check "rucio-eic" "$GITHUB_DIR/rucio-eic-mcp-server"; then
0109     echo "  rebuilding..."
0110     ("$VENV_BIN/pip" install -e "$GITHUB_DIR/rucio-eic-mcp-server") 2>&1
0111     if [ $? -eq 0 ]; then
0112         echo "  rebuild OK"
0113         CHANGED=1
0114     else
0115         echo "  ERROR: rebuild failed"
0116     fi
0117 fi
0118 
0119 # --- Restart bot if anything changed ---
0120 if [ "$CHANGED" -eq 1 ]; then
0121     echo ""
0122     echo "=== Restarting $BOT_SERVICE ==="
0123     sudo systemctl restart "$BOT_SERVICE" 2>&1
0124     sleep 5
0125     if systemctl is-active --quiet "$BOT_SERVICE"; then
0126         echo "  bot restarted OK"
0127     else
0128         echo "  ERROR: bot failed to start"
0129         sudo journalctl -u "$BOT_SERVICE" --since "30 sec ago" --no-pager 2>&1 | tail -10
0130     fi
0131 else
0132     echo ""
0133     echo "=== No changes — bot not restarted ==="
0134 fi
0135 
0136 echo "=== done $(date -u +%Y-%m-%dT%H:%M:%SZ) ==="