refactor(setup): remove tmux dependency from setup.sh
This commit is contained in:
@@ -13,18 +13,27 @@ info() { echo -e "${GREEN}[+]${NC} $*"; }
|
|||||||
warn() { echo -e "${YELLOW}[!]${NC} $*"; }
|
warn() { echo -e "${YELLOW}[!]${NC} $*"; }
|
||||||
die() { echo -e "${RED}[✗] FATAL:${NC} $*" >&2; exit 1; }
|
die() { echo -e "${RED}[✗] FATAL:${NC} $*" >&2; exit 1; }
|
||||||
|
|
||||||
SESSION="theplug"
|
start_proxy() {
|
||||||
|
API_PORT=$(grep -E '^API_PORT=' .env | cut -d '=' -f2)
|
||||||
|
API_PORT=${API_PORT:-3671}
|
||||||
|
|
||||||
|
info "Launching FastAPI on port $API_PORT..."
|
||||||
|
PYTHONPATH=app uv run uvicorn app.main:app --host 0.0.0.0 --port "$API_PORT" 2>&1 &
|
||||||
|
PID=$!
|
||||||
|
warn "Started thePlug with PID [$PID], 'pkill -9 $PID' to kill it"
|
||||||
|
}
|
||||||
|
|
||||||
# ── 1. ensure we're in thePlug ────────────────────────────────────────────────
|
# ── 1. ensure we're in thePlug ────────────────────────────────────────────────
|
||||||
if [[ "$PWD" != "/srv/theplug" ]]; then
|
if [[ -d "/srv/theplug" ]]; then
|
||||||
if tmux has-session -t "$SESSION" 2>/dev/null; then
|
info "thePlug già presente — avvio diretto..."
|
||||||
info "thePlug già in esecuzione — attaching..."
|
cd /srv/theplug
|
||||||
exec tmux attach -t "$SESSION"
|
start_proxy
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd /srv
|
cd /srv
|
||||||
git clone https://git.reloia.uk/reloia/thePlug theplug || die "git clone failed"
|
git clone https://git.reloia.uk/reloia/thePlug theplug || die "git clone failed"
|
||||||
cd theplug
|
cd theplug
|
||||||
fi
|
|
||||||
|
|
||||||
chmod +x ./setup.sh
|
chmod +x ./setup.sh
|
||||||
|
|
||||||
@@ -66,56 +75,26 @@ if ! command -v uv &>/dev/null; then
|
|||||||
info "uv installed: $(uv --version)"
|
info "uv installed: $(uv --version)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ── 5. ensure tmux is available ───────────────────────────────────────────────
|
# ── 5. venv + deps ────────────────────────────────────────────────────────────
|
||||||
if ! command -v tmux &>/dev/null; then
|
|
||||||
warn "tmux not found — installing..."
|
|
||||||
sudo apt-get install -y tmux || die "tmux installation failed"
|
|
||||||
info "tmux installed"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# ── 6. venv + deps ────────────────────────────────────────────────────────────
|
|
||||||
info "Pinning Python 3.14..."
|
info "Pinning Python 3.14..."
|
||||||
uv python pin 3.14
|
uv python pin 3.14
|
||||||
|
|
||||||
info "Creating/updating venv..."
|
info "Creating venv..."
|
||||||
uv venv
|
uv venv
|
||||||
source .venv/bin/activate
|
|
||||||
|
|
||||||
info "Syncing dependencies..."
|
info "Syncing dependencies..."
|
||||||
uv sync
|
uv sync
|
||||||
|
|
||||||
# ── 7. run in tmux with autorestart ───────────────────────────────────────────
|
# 6 start
|
||||||
if tmux has-session -t "$SESSION" 2>/dev/null; then
|
start_proxy
|
||||||
warn "tmux session '$SESSION' already exists — killing it..."
|
|
||||||
tmux kill-session -t "$SESSION"
|
|
||||||
fi
|
|
||||||
|
|
||||||
info "Launching FastAPI in tmux session '$SESSION'..."
|
echo -e ""
|
||||||
|
|
||||||
API_PORT=$(grep -E '^API_PORT=' .env | cut -d '=' -f2)
|
|
||||||
API_PORT=${API_PORT:-3671}
|
|
||||||
tmux new-session -d -s "$SESSION" "bash -c '
|
|
||||||
cd $(pwd)
|
|
||||||
source .venv/bin/activate
|
|
||||||
while true; do
|
|
||||||
echo \"[\$(date +%T)] Starting uvicorn...\"
|
|
||||||
PYTHONPATH=app uv run uvicorn app.main:app --host 0.0.0.0 --port $API_PORT 2>&1 | tee uvicorn.log
|
|
||||||
echo \"[\$(date +%T)] Process exited — restarting in 3s (Ctrl+C to stop)\"
|
|
||||||
sleep 3
|
|
||||||
done
|
|
||||||
'"
|
|
||||||
|
|
||||||
echo -e "";
|
|
||||||
info "Automatically generated Secrets:"
|
info "Automatically generated Secrets:"
|
||||||
info " MONGO_PASS: $MONGO_PASS"
|
info " MONGO_PASS: $MONGO_PASS"
|
||||||
info " JWT_SECRET: $JWT_SECRET"
|
info " JWT_SECRET: $JWT_SECRET"
|
||||||
info " AUTH_PASS: $AUTH_PASS - questa è importante"
|
info " AUTH_PASS: $AUTH_PASS - questa è importante"
|
||||||
warn "Save them — these won't be showed again (non è vero basta che leggi $PLUG_DIR/.env)"
|
warn "Save them — these won't be showed again (non è vero basta che leggi $PLUG_DIR/.env)"
|
||||||
echo -e "";
|
echo -e ""
|
||||||
|
|
||||||
info "Installed this script into /usr/bin/theplug"
|
info "Installed thePlug in $PLUG_DIR"
|
||||||
info "Installed in $PLUG_DIR"
|
echo -e ""
|
||||||
echo -e "";
|
|
||||||
|
|
||||||
info "Done — attach with: 'theplug' or 'tmux attach -t $SESSION'"
|
|
||||||
warn "To detatch from tmux do: ctrl+b d"
|
|
||||||
Reference in New Issue
Block a user