vol_breakout 멀티종목 tick, vol_live HTML 모니터, 마감 봉만 저장하는 캔들 다운로드, 텔레그램 체결 알림, cron/watch 감시 스크립트 및 테스트를 포함한다. Co-authored-by: Cursor <cursoragent@cursor.com>
83 lines
2.4 KiB
Bash
Executable File
83 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# macOS LaunchAgent — vol_live 모니터(8766) 로그인 시 자동 기동·유지
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
LABEL="com.bithumb.vol-monitor"
|
|
PLIST_SRC="${ROOT}/scripts/com.bithumb.vol-monitor.plist.template"
|
|
PLIST_DST="${HOME}/Library/LaunchAgents/${LABEL}.plist"
|
|
LOG="${ROOT}/data/spot/operations/vol_monitor_serve.log"
|
|
|
|
usage() {
|
|
cat <<EOF
|
|
Usage: $(basename "$0") [--install|--uninstall|--status]
|
|
|
|
--install LaunchAgent 등록 + 즉시 기동 (로그인·크래시 시 자동 재시작)
|
|
--uninstall LaunchAgent 제거
|
|
--status 실행 상태 확인
|
|
|
|
접속: http://127.0.0.1:8766/vol_live_monitor.html
|
|
EOF
|
|
}
|
|
|
|
resolve_python() {
|
|
# shellcheck source=scripts/_cron_env.sh
|
|
source "${ROOT}/scripts/_cron_env.sh"
|
|
resolve_bithumb_python
|
|
}
|
|
|
|
render_plist() {
|
|
local python_bin="$1"
|
|
mkdir -p "${ROOT}/data/spot/operations"
|
|
sed \
|
|
-e "s|__ROOT__|${ROOT}|g" \
|
|
-e "s|__PYTHON__|${python_bin}|g" \
|
|
-e "s|__LOG__|${LOG}|g" \
|
|
"$PLIST_SRC"
|
|
}
|
|
|
|
cmd="${1:---status}"
|
|
case "$cmd" in
|
|
--install)
|
|
PYTHON="$(resolve_python)" || exit 1
|
|
mkdir -p "${HOME}/Library/LaunchAgents"
|
|
render_plist "$PYTHON" > "$PLIST_DST"
|
|
launchctl bootout "gui/$(id -u)/${LABEL}" 2>/dev/null || true
|
|
launchctl bootstrap "gui/$(id -u)" "$PLIST_DST"
|
|
launchctl enable "gui/$(id -u)/${LABEL}" 2>/dev/null || true
|
|
launchctl kickstart -k "gui/$(id -u)/${LABEL}" 2>/dev/null || true
|
|
sleep 2
|
|
if curl -sf -o /dev/null --connect-timeout 3 "http://127.0.0.1:8766/vol_live_monitor.html"; then
|
|
echo "LaunchAgent 설치 완료 — http://127.0.0.1:8766/vol_live_monitor.html"
|
|
else
|
|
echo "LaunchAgent 등록됨. 접속 안 되면 로그 확인: $LOG" >&2
|
|
tail -15 "$LOG" 2>/dev/null || true
|
|
fi
|
|
;;
|
|
--uninstall)
|
|
launchctl bootout "gui/$(id -u)/${LABEL}" 2>/dev/null || true
|
|
rm -f "$PLIST_DST"
|
|
echo "LaunchAgent 제거됨"
|
|
;;
|
|
--status)
|
|
if launchctl print "gui/$(id -u)/${LABEL}" >/dev/null 2>&1; then
|
|
echo "LaunchAgent: 등록됨"
|
|
launchctl print "gui/$(id -u)/${LABEL}" 2>/dev/null | grep -E "state =|pid =|last exit" || true
|
|
else
|
|
echo "LaunchAgent: 미등록"
|
|
fi
|
|
if curl -sf -o /dev/null --connect-timeout 2 "http://127.0.0.1:8766/vol_live_monitor.html"; then
|
|
echo "HTTP 8766: 응답 OK"
|
|
else
|
|
echo "HTTP 8766: 연결 불가 (서버 미기동)"
|
|
fi
|
|
;;
|
|
-h|--help)
|
|
usage
|
|
;;
|
|
*)
|
|
usage >&2
|
|
exit 1
|
|
;;
|
|
esac
|