#!/usr/bin/env bash # 한땀 작업실 서버를 macOS 로그인 항목(launchd)으로 등록한다. # bash scripts/studio-service.sh install # 설치 + 시작 # bash scripts/studio-service.sh status # 상태 # bash scripts/studio-service.sh stop # 중지 + 등록 해제 set -euo pipefail LABEL="io.lala.teamat-studio" PLIST="$HOME/Library/LaunchAgents/$LABEL.plist" REPO="$(cd "$(dirname "$0")/.." && pwd)" PORT="${PORT:-8081}" PY="$(command -v python3)" case "${1:-install}" in install) mkdir -p "$HOME/Library/LaunchAgents" "$HOME/Library/Logs" cat > "$PLIST" < Label$LABEL ProgramArguments $PY$REPO/studio/server.py --port$PORT WorkingDirectory$REPO RunAtLoad KeepAlive StandardOutPath$HOME/Library/Logs/teamat-studio.log StandardErrorPath$HOME/Library/Logs/teamat-studio.err.log PLISTEOF # 손으로 띄운 서버가 있으면 먼저 정리(포트 충돌 방지) pkill -f "[s]tudio/server.py" 2>/dev/null || true launchctl bootout "gui/$(id -u)/$LABEL" 2>/dev/null || true launchctl bootstrap "gui/$(id -u)" "$PLIST" launchctl kickstart -k "gui/$(id -u)/$LABEL" 2>/dev/null || true sleep 1 echo "설치 완료: $LABEL (포트 $PORT)" curl -s -o /dev/null -w "로컬 응답: HTTP %{http_code}\n" "http://127.0.0.1:$PORT/m" || true ;; status) launchctl print "gui/$(id -u)/$LABEL" 2>/dev/null | sed -n '1,10p' || echo "실행 중 아님" curl -s -o /dev/null -w "로컬 응답: HTTP %{http_code}\n" "http://127.0.0.1:$PORT/m" || true ;; stop) launchctl bootout "gui/$(id -u)/$LABEL" 2>/dev/null || true rm -f "$PLIST" echo "중지 및 등록 해제" ;; *) echo "사용법: bash scripts/studio-service.sh [install|status|stop]" >&2 exit 1 ;; esac