Skip to content

Instantly share code, notes, and snippets.

@koliadych
Created May 10, 2026 20:43
Show Gist options
  • Select an option

  • Save koliadych/47d8d71652088803244b6dc6cb557767 to your computer and use it in GitHub Desktop.

Select an option

Save koliadych/47d8d71652088803244b6dc6cb557767 to your computer and use it in GitHub Desktop.
fintechner force install node on EC2
#!/bin/bash
set -euo pipefail
REGION=ap-northeast-1
INSTANCE_ID=i-089ad4a6b76132ba2
echo "=== Force-install Node.js + symlink + restart dashboard ==="
CMD_ID=$(aws --region "$REGION" ssm send-command \
--instance-ids "$INSTANCE_ID" \
--document-name AWS-RunShellScript \
--parameters 'commands=[
"echo --- before ---",
"which node || echo node-missing",
"ls -l /usr/bin/node /usr/local/bin/node 2>&1 | head -5",
"echo --- installing nodejs20 ---",
"sudo dnf install -y nodejs20 nodejs20-npm 2>&1 | tail -10",
"echo --- after install ---",
"ls -l /usr/bin/node /usr/local/bin/node /usr/bin/node20 2>&1 | head -5",
"echo --- finding node binary ---",
"rpm -ql nodejs20 2>/dev/null | grep /bin/node | head -5 || echo no-rpm-listing",
"echo --- ensuring /usr/bin/node ---",
"if [ ! -x /usr/bin/node ]; then for c in /usr/bin/node20 /usr/local/bin/node /opt/nodejs/bin/node; do [ -x \"$c\" ] && sudo ln -sf \"$c\" /usr/bin/node && break; done; fi",
"ls -l /usr/bin/node",
"/usr/bin/node --version",
"echo --- restart + status ---",
"sudo systemctl reset-failed fintechner-dashboard",
"sudo systemctl restart fintechner-dashboard",
"sleep 6",
"sudo systemctl is-active fintechner-dashboard",
"sudo ss -tlnp | grep :3000 || echo NO-LISTENER",
"echo --- curl localhost ---",
"curl -sS -o /dev/null -w \"http=%{http_code}\\n\" http://localhost:3000/ || echo curl-failed"
]' \
--query Command.CommandId --output text)
for i in $(seq 1 30); do
sleep 4
STATUS=$(aws --region "$REGION" ssm get-command-invocation --command-id "$CMD_ID" --instance-id "$INSTANCE_ID" --query Status --output text 2>/dev/null || echo Pending)
case "$STATUS" in Success|Failed|Cancelled|TimedOut) echo " $STATUS"; break ;; *) echo " ($i) $STATUS";; esac
done
echo
echo "============================================================"
aws --region "$REGION" ssm get-command-invocation --command-id "$CMD_ID" --instance-id "$INSTANCE_ID" --query StandardOutputContent --output text
echo
echo "--- STDERR ---"
aws --region "$REGION" ssm get-command-invocation --command-id "$CMD_ID" --instance-id "$INSTANCE_ID" --query StandardErrorContent --output text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment