| name | Railway CLI |
| description | Railway CLI operations for authentication, context management, deployment, monitoring, and troubleshooting. Use when working with Railway infrastructure, deploying services, or managing environments. |
Railway CLI for IOTA SDK
Check Authentication
railway whoami
Context Management
Check current context:
railway status
List all projects with IDs:
railway list --json | jq '.'
Link project manually (create .railway/config.json):
mkdir -p .railway
cat > .railway/config.json << 'EOF'
{
"projectId": "<your-project-id>"
}
EOF
Switch environment:
railway environment <environment>
Deployment
Deploy to specific environment and service:
railway up -s <service> -e <environment> --detach
Redeploy latest deployment:
railway redeploy -s <service> -e <environment> -y
Check deployment status:
railway status -s <service> -e <environment>
Monitoring
View deployment logs (real-time stream):
railway logs -s <service> -e <environment> --deployment
View build logs:
railway logs -s <service> -e <environment> --build
Get logs in JSON format (for parsing):
railway logs -s <service> -e <environment> --deployment --json
Filter logs for errors/panics:
railway logs -s iota-sdk -e staging --deployment 2>&1 | grep -i -E "(panic|error|fatal)"
railway logs -s iota-sdk -e staging --deployment --json 2>&1 | \
jq -r 'select(.message | test("panic|error|fatal"; "i")) | "\(.timestamp) \(.message)"'
Get context around errors:
railway logs -s iota-sdk -e staging --deployment 2>&1 | grep -A 30 "panic"
railway logs -s iota-sdk -e staging --deployment 2>&1 | tail -100
Note: Railway enforces a rate limit of 500 logs/sec per replica. High-volume logging may result in dropped messages.
Variables
Get all variables for a service:
railway variables -s <service> -e <environment> --kv
Set a variable:
railway variables -s <service> -e <environment> --set "KEY=value"
Running Commands
Execute local command with remote environment variables:
railway run -s <service> -e <environment> -- <command>
Note: railway run executes locally, not on the remote service. Use for running local commands with staging/production environment variables.
Database Access
Connect to database shell:
railway connect db -e <environment>
Get database connection URL:
railway variables -s db -e <environment> --kv | grep DATABASE_PUBLIC_URL
SSH into service (requires active deployment):
railway ssh -s <service> -e <environment>
Common Operations for IOTA SDK
Analyzing Panics and Errors
Find recent panics with stack traces:
railway logs -s iota-sdk -e staging --deployment 2>&1 | grep -A 30 "panic"
railway logs -s iota-sdk -e staging --deployment --json 2>&1 | \
jq -r 'select(.message | test("your-pattern"; "i")) | .message' | tail -50
Common error patterns for IOTA SDK:
- Translation errors:
"message .* not found in language"
- Database errors:
"pq:|postgres:|connection|timeout"
- HTTP panics:
"http: panic serving"
- Multi-tenant errors:
"tenant_id|organization_id|forbidden"
- Permission errors:
"permission denied|insufficient permissions"
Running Migrations on Staging
Get database credentials and run migrations locally:
railway variables -s db -e staging --kv | grep DATABASE_PUBLIC_URL
export DB_HOST=<host-from-url>
export DB_PORT=<port-from-url>
export DB_NAME=<database-from-url>
export DB_USER=<user-from-url>
export DB_PASSWORD=<password-from-url>
make db migrate status
make db migrate up
make db migrate down
Deploying New Version
railway status -s iota-sdk -e staging
railway up -s iota-sdk -e staging --detach
railway logs -s iota-sdk -e staging --deployment
railway status -s iota-sdk -e staging
railway logs -s iota-sdk -e staging --deployment 2>&1 | grep -i error | tail -20
Environment Variable Management
railway variables -s iota-sdk -e staging --kv
railway variables -s iota-sdk -e staging --set "LOG_LEVEL=debug"
railway variables -s iota-sdk -e staging --set "DB_HOST=new-host"
railway redeploy -s iota-sdk -e staging -y
Database Backup
DB_URL=$(railway variables -s db -e staging --kv | grep DATABASE_PUBLIC_URL | cut -d'=' -f2)
pg_dump "$DB_URL" > backup_$(date +%Y%m%d_%H%M%S).sql
pg_dump "$DB_URL" | gzip > backup_$(date +%Y%m%d_%H%M%S).sql.gz
IOTA SDK Project Structure
Environment Names:
staging - Staging environment
production - Production environment
Service Names (adjust based on actual setup):
iota-sdk - Main Go application
db - PostgreSQL database
Example with actual service names:
railway up -s iota-sdk -e staging --detach
railway logs -s iota-sdk -e staging --deployment
railway connect db -e staging
Troubleshooting
"Project not found": Create .railway/config.json with projectId
"No deployment found": Service has no active deployment in that environment
SSH connection fails: Ensure deployment is running, use railway logs to check status
Logs not showing: Check service name and environment are correct
Variable not updating: Redeploy service after setting variables
Production Safety
Always specify -e staging explicitly when working with staging to avoid accidentally affecting production.
Before Running Production Operations
- Double-check the environment flag (
-e production)
- Verify current context with
railway status
- Test on staging first
- Have a rollback plan ready
- Announce deployment to team
- Monitor logs during deployment
Production Deployment Checklist
Emergency Rollback
railway status -s iota-sdk -e production
git checkout <previous-version>
railway up -s iota-sdk -e production --detach
Quick Reference
railway whoami
railway status
railway up -s iota-sdk -e staging --detach
railway redeploy -s iota-sdk -e staging -y
railway logs -s iota-sdk -e staging --deployment
railway logs -s iota-sdk -e staging --deployment | grep -i error
railway variables -s iota-sdk -e staging --kv
railway variables -s iota-sdk -e staging --set "KEY=value"
railway connect db -e staging
railway variables -s db -e staging --kv | grep DATABASE_PUBLIC_URL
railway ssh -s iota-sdk -e staging
Common Workflows
Debug Production Issue
railway logs -s iota-sdk -e production --deployment | tail -100
railway logs -s iota-sdk -e production --deployment | grep -i error -A 10
railway variables -s iota-sdk -e production --kv | grep DB_
railway ssh -s iota-sdk -e production
Update Environment Configuration
railway variables -s iota-sdk -e staging --kv > current_vars.txt
railway variables -s iota-sdk -e staging --set "NEW_FEATURE_FLAG=true"
railway variables -s iota-sdk -e staging --set "LOG_LEVEL=info"
railway redeploy -s iota-sdk -e staging -y
railway logs -s iota-sdk -e staging --deployment | head -50
Monitor Deployment
watch -n 5 'railway status -s iota-sdk -e staging'
railway logs -s iota-sdk -e staging --deployment
watch -n 10 'railway logs -s iota-sdk -e staging --deployment | grep -i error | tail -20'