Skip to content

Instantly share code, notes, and snippets.

View koliadych's full-sized avatar

Fintechner koliadych

View GitHub Profile
@koliadych
koliadych / 36-restore-and-fix-deploy.sh
Created May 11, 2026 09:21
fintechner restore env + watch backfill
#!/bin/bash
# 1) restore connector.env now, 2) tell user the deploy gist is patched.
set -euo pipefail
export AWS_PAGER=""
REGION=ap-northeast-1
INSTANCE_ID=i-089ad4a6b76132ba2
ADMIN_EMAIL="koliadych@gmail.com"
echo "=== Restoring connector.env from Secrets Manager ==="
DB_PWD=$(aws --region "$REGION" secretsmanager get-secret-value --secret-id fintechner/db-password --query SecretString --output text)
@koliadych
koliadych / 35-restart-and-watch.sh
Created May 11, 2026 09:12
fintechner restart + watch backfill
#!/bin/bash
set -euo pipefail
export AWS_PAGER=""
REGION=ap-northeast-1
INSTANCE_ID=i-089ad4a6b76132ba2
CMD_ID=$(aws --region "$REGION" ssm send-command \
--instance-ids "$INSTANCE_ID" \
--document-name AWS-RunShellScript \
--parameters '{"commands":["echo === restart connector ===","sudo systemctl restart fintechner-connector","sleep 10","echo === backfill log lines ===","sudo journalctl -u fintechner-connector --since \"30 sec ago\" --no-pager | grep -iE \"closedtrades|backfill|closed trade|fatal|ERROR\" | head -30","echo === closed_trades count after restart ===","sudo docker exec timescale psql -U fintechner -d fintechner -tA -c \"SELECT COUNT(*) FROM closed_trades;\""]}' \
@koliadych
koliadych / 34-ct-diag.sh
Created May 11, 2026 09:11
fintechner closed-trades diagnostic
#!/bin/bash
set -euo pipefail
export AWS_PAGER=""
REGION=ap-northeast-1
INSTANCE_ID=i-089ad4a6b76132ba2
SQL_B64=$(base64 -w0 <<'SQL'
SELECT 'closed_trades:'||COUNT(*) FROM closed_trades;
SELECT 'fills by origin:' AS x;
SELECT origin, COUNT(*) FROM fills GROUP BY origin;
@koliadych
koliadych / 33-protect-and-count.sh
Created May 11, 2026 07:10
fintechner protect + count
#!/bin/bash
set -euo pipefail
export AWS_PAGER=""
REGION=ap-northeast-1
INSTANCE_ID=i-089ad4a6b76132ba2
echo "=== 1. Enable termination protection (idempotent) ==="
aws --region "$REGION" ec2 modify-instance-attribute \
--instance-id "$INSTANCE_ID" \
--disable-api-termination "{\"Value\":true}"
@koliadych
koliadych / 32-status.sh
Created May 11, 2026 07:07
fintechner full status inventory
#!/bin/bash
# fintechner — live inventory of the deployed system.
set -euo pipefail
export AWS_PAGER=""
REGION=ap-northeast-1
INSTANCE_ID=i-089ad4a6b76132ba2
echo "============================================================"
echo " AWS-side"
echo "============================================================"
@koliadych
koliadych / 31-cold-backup-keys.sh
Created May 10, 2026 23:28
fintechner cold backup keys reveal
#!/bin/bash
# fintechner — gate #7: print all critical secrets to terminal so you can
# write them on paper / save to password manager. NEVER paste output to chat.
#
# If AWS Secrets Manager has a regional outage you cannot re-sign or
# decrypt the credential store. These are your only fallbacks.
set -euo pipefail
export AWS_PAGER=""
REGION=ap-northeast-1
@koliadych
koliadych / 30-alarms.sh
Created May 10, 2026 23:28
fintechner CloudWatch health alarms
#!/bin/bash
# fintechner — readiness gate #6: CloudWatch health alarms + email SNS.
# Catches "EC2 unreachable / instance dead" cases that in-process alerts
# can't surface. ~$0/mo (SNS first 1k notifications free, alarms first 10 free).
set -euo pipefail
export AWS_PAGER=""
REGION=ap-northeast-1
INSTANCE_ID=i-089ad4a6b76132ba2
EMAIL=koliadych@gmail.com
@koliadych
koliadych / 29-redeploy-and-protect.sh
Created May 10, 2026 23:20
fintechner readiness gate 1 + redeploy
#!/bin/bash
# fintechner — redeploy (slippage + equity fixes) AND enable termination
# protection in one shot. Idempotent.
set -euo pipefail
export AWS_PAGER=""
REGION=ap-northeast-1
INSTANCE_ID=i-089ad4a6b76132ba2
echo "=== 1. Enable EC2 termination protection ==="
@koliadych
koliadych / 28-audit-v3.sh
Created May 10, 2026 22:19
fintechner audit v3
#!/bin/bash
set -euo pipefail
export AWS_PAGER=""
REGION=ap-northeast-1
INSTANCE_ID=i-089ad4a6b76132ba2
# Bundle the SQL queries into a single shell script, run it via base64 on
# the EC2. Avoids all the JSON-in-SSM-in-bash escape hell.
SCRIPT_B64=$(base64 -w0 <<'INNER'
psql() { sudo docker exec timescale psql -U fintechner -d fintechner -c "$1" 2>&1 | head -15; }
@koliadych
koliadych / 27-audit-v2.sh
Created May 10, 2026 22:17
fintechner audit v2 correct schemas
#!/bin/bash
set -euo pipefail
export AWS_PAGER=""
REGION=ap-northeast-1
INSTANCE_ID=i-089ad4a6b76132ba2
CMD_ID=$(aws --region "$REGION" ssm send-command \
--instance-ids "$INSTANCE_ID" \
--document-name AWS-RunShellScript \
--parameters '{"commands":[