Initial commit

This commit is contained in:
Jage9
2026-02-20 08:16:43 -05:00
commit b246c9a7fd
53 changed files with 9538 additions and 0 deletions

116
deploy/README.md Normal file
View File

@@ -0,0 +1,116 @@
# Deployment Guide
Target example: AlmaLinux/cPanel host with files under `/home/bestmidi`.
## 1) Place project files
- Repo root: `/home/bestmidi/chgrid`
## 2) Make deploy scripts executable (once)
```bash
cd /home/bestmidi/chgrid
chmod +x deploy/scripts/*.sh
```
## 3) Install server (uv)
Verify server files first:
```bash
ls -l /home/bestmidi/chgrid/server/pyproject.toml
```
Run install scripts from repo root (`/home/bestmidi/chgrid`), not from `server/`.
```bash
cd /home/bestmidi/chgrid
./deploy/scripts/install_server.sh /home/bestmidi/chgrid
```
Notes:
- Script defaults to Python `3.13` (`PYTHON_SPEC=3.13`).
- It reuses existing `.venv` instead of replacing it interactively.
- If you need to force a fresh 3.13 env:
- `rm -rf /home/bestmidi/chgrid/server/.venv`
- rerun `./deploy/scripts/install_server.sh /home/bestmidi/chgrid`
This creates:
- `/home/bestmidi/chgrid/server/.venv`
- `/home/bestmidi/chgrid/server/config.toml` (if missing)
Edit `/home/bestmidi/chgrid/server/config.toml`:
- `server.bind_ip = "127.0.0.1"`
- `server.port = 8765`
- `network.allow_insecure_ws = true`
- `tls.cert_file = ""`
- `tls.key_file = ""`
- `storage.state_file = "runtime/items.json"`
## 4) Build and publish client
```bash
cd /home/bestmidi/chgrid
./deploy/scripts/deploy_client.sh /home/bestmidi/chgrid /home/bestmidi/public_html/chgrid /chgrid/
```
Notes:
- Third arg is Vite base path for production assets.
- For `https://bestmidi.com/chgrid/`, use `/chgrid/`.
- For site root deploy (`https://bestmidi.com/`), use `/`.
## 5) Install/restart signaling service (systemd)
```bash
cd /home/bestmidi/chgrid
./deploy/scripts/install_service.sh /home/bestmidi/chgrid
```
Logs:
```bash
journalctl -u chgrid-signaling.service -f
```
## 6) Apache websocket proxy
Install using script:
```bash
cd /home/bestmidi/chgrid
./deploy/scripts/install_apache.sh \
/home/bestmidi/chgrid \
/etc/apache2/conf.d/userdata/ssl/2_4/bestmidi/yourdomain.com/chgrid.conf
```
Notes:
- Replace `yourdomain.com` with your real domain.
- Script copies `deploy/apache/chgrid-vhost-snippet.conf`, runs `rebuildhttpdconf`, then restarts Apache via WHM restart command.
## 7) Optional HTTPS relay for HTTP radio streams
If stream sources are plain HTTP (for example ports `8000`, `8010`, `8020`, `8030`), add relays in:
`/etc/apache2/conf.d/userdata/ssl/2_4/bestmidi/bestmidi.com/chgrid.conf`
Example:
```apache
ProxyPass /listen/8000/ http://127.0.0.1:8000/
ProxyPassReverse /listen/8000/ http://127.0.0.1:8000/
ProxyPass /listen/8010/ http://127.0.0.1:8010/
ProxyPassReverse /listen/8010/ http://127.0.0.1:8010/
ProxyPass /listen/8020/ http://127.0.0.1:8020/
ProxyPassReverse /listen/8020/ http://127.0.0.1:8020/
ProxyPass /listen/8030/ http://127.0.0.1:8030/
ProxyPassReverse /listen/8030/ http://127.0.0.1:8030/
```
Apply changes:
```bash
sudo /usr/local/cpanel/scripts/rebuildhttpdconf
sudo /usr/local/cpanel/scripts/restartsrv_httpd
```
Usage example in Chat Grid:
- `https://bestmidi.com/listen/8000/stream`

View File

@@ -0,0 +1,7 @@
# Add inside your SSL VirtualHost include for bestmidi.com.
# Keep your existing main DocumentRoot unchanged when hosting Chat Grid under /chgrid.
# Required modules: proxy, proxy_http, proxy_wstunnel
# Proxy websocket signaling endpoint to local Python service.
ProxyPass /ws ws://127.0.0.1:8765
ProxyPassReverse /ws ws://127.0.0.1:8765

27
deploy/scripts/deploy_client.sh Executable file
View File

@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -euo pipefail
REPO_ROOT="${1:-/home/bestmidi/chgrid}"
PUBLISH_DIR="${2:-/home/bestmidi/public_html/chgrid}"
BASE_PATH="${3:-/chgrid/}"
CLIENT_DIR="$REPO_ROOT/client"
if [[ ! -d "$CLIENT_DIR" ]]; then
echo "error: client directory not found: $CLIENT_DIR" >&2
exit 1
fi
if ! command -v rsync >/dev/null 2>&1; then
echo "error: rsync is required but not found in PATH" >&2
exit 1
fi
cd "$CLIENT_DIR"
npm install
VITE_BASE_PATH="$BASE_PATH" npm run build
mkdir -p "$PUBLISH_DIR"
rsync -a --delete dist/ "$PUBLISH_DIR/"
echo "client deploy complete: $PUBLISH_DIR"
echo "client base path: $BASE_PATH"

View File

@@ -0,0 +1,41 @@
#!/usr/bin/env bash
set -euo pipefail
REPO_ROOT="${1:-/home/bestmidi/chgrid}"
INCLUDE_PATH="${2:-}"
RESTART_CMD="${3:-/usr/local/cpanel/scripts/restartsrv_httpd}"
SNIPPET_PATH="$REPO_ROOT/deploy/apache/chgrid-vhost-snippet.conf"
if [[ -z "$INCLUDE_PATH" ]]; then
echo "usage: $0 <repo_root> <apache_include_path> [restart_cmd]" >&2
echo "example: $0 /home/bestmidi/chgrid /etc/apache2/conf.d/userdata/ssl/2_4/bestmidi/example.com/chgrid.conf" >&2
exit 1
fi
if [[ ! -f "$SNIPPET_PATH" ]]; then
echo "error: snippet not found: $SNIPPET_PATH" >&2
exit 1
fi
sudo mkdir -p "$(dirname "$INCLUDE_PATH")"
sudo cp "$SNIPPET_PATH" "$INCLUDE_PATH"
echo "installed apache include: $INCLUDE_PATH"
if [[ -x /usr/local/cpanel/scripts/rebuildhttpdconf ]]; then
sudo /usr/local/cpanel/scripts/rebuildhttpdconf
else
echo "warning: /usr/local/cpanel/scripts/rebuildhttpdconf not found; skipping rebuild" >&2
fi
if [[ -x "$RESTART_CMD" ]]; then
sudo "$RESTART_CMD"
elif [[ -x /scripts/restartsrv_httpd ]]; then
sudo /scripts/restartsrv_httpd
else
echo "error: apache restart command not found" >&2
echo "tried: $RESTART_CMD and /scripts/restartsrv_httpd" >&2
exit 1
fi
echo "apache include applied and apache restarted"

View File

@@ -0,0 +1,53 @@
#!/usr/bin/env bash
set -euo pipefail
REPO_ROOT="${1:-/home/bestmidi/chgrid}"
SERVER_DIR="$REPO_ROOT/server"
PYTHON_SPEC="${PYTHON_SPEC:-3.13}"
if ! command -v uv >/dev/null 2>&1; then
echo "error: uv is required but not found in PATH" >&2
exit 1
fi
if [[ ! -d "$SERVER_DIR" ]]; then
echo "error: server directory not found: $SERVER_DIR" >&2
exit 1
fi
if [[ ! -f "$SERVER_DIR/pyproject.toml" ]]; then
echo "error: missing $SERVER_DIR/pyproject.toml" >&2
echo " verify repository files were copied to /home/bestmidi/chgrid/server" >&2
exit 1
fi
cd "$SERVER_DIR"
# Avoid interactive prompts: reuse existing venv; create only when missing.
if [[ ! -d .venv ]]; then
uv venv .venv --python "$PYTHON_SPEC"
echo "created .venv with Python $PYTHON_SPEC"
else
echo "using existing .venv"
fi
if [[ -x .venv/bin/python ]]; then
VENV_PYTHON_VERSION="$(
.venv/bin/python -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")'
)"
if [[ "$VENV_PYTHON_VERSION" != "$PYTHON_SPEC" ]]; then
echo "warning: .venv uses Python $VENV_PYTHON_VERSION (requested $PYTHON_SPEC)" >&2
echo " remove .venv and rerun script to recreate with Python $PYTHON_SPEC" >&2
fi
fi
uv sync --no-dev --project "$SERVER_DIR"
if [[ ! -f config.toml ]]; then
cp config.example.toml config.toml
echo "created $SERVER_DIR/config.toml from template"
fi
mkdir -p runtime
echo "server install complete"
echo "next: edit $SERVER_DIR/config.toml (TLS, bind_ip, port)"

View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -euo pipefail
REPO_ROOT="${1:-/home/bestmidi/chgrid}"
UNIT_NAME="${2:-chgrid-signaling.service}"
SRC_UNIT="$REPO_ROOT/deploy/systemd/$UNIT_NAME"
DST_UNIT="/etc/systemd/system/$UNIT_NAME"
if [[ ! -f "$SRC_UNIT" ]]; then
echo "error: unit file not found: $SRC_UNIT" >&2
exit 1
fi
sudo cp "$SRC_UNIT" "$DST_UNIT"
sudo systemctl daemon-reload
sudo systemctl enable --now "$UNIT_NAME"
sudo systemctl restart "$UNIT_NAME"
sudo systemctl status "$UNIT_NAME" --no-pager

View File

@@ -0,0 +1,16 @@
[Unit]
Description=chgrid client preview server (vite)
After=network.target
[Service]
Type=simple
User=chgrid
Group=chgrid
WorkingDirectory=/opt/chgrid/client
Environment=PATH=/usr/bin:/bin
ExecStart=/usr/bin/npm run preview -- --host 0.0.0.0 --port 4173
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,16 @@
[Unit]
Description=chgrid signaling server
After=network.target
[Service]
Type=simple
User=bestmidi
Group=bestmidi
WorkingDirectory=/home/bestmidi/chgrid/server
Environment=PATH=/home/bestmidi/chgrid/server/.venv/bin:/usr/bin:/bin
ExecStart=/home/bestmidi/chgrid/server/.venv/bin/python main.py --config /home/bestmidi/chgrid/server/config.toml
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target