Service Management
TractStack runs as multiple services in production: systemd services for the Go backend and PM2 processes for the Astro frontend. Understanding service management is essential for maintaining a healthy production installation.
Service Architecture
Section titled “Service Architecture”Main Installation Services
Section titled “Main Installation Services”systemd services:
tractstack-go.service
- Go backend servicet8k-build-watcher.path
- Monitors build triggerst8k-build-watcher.service
- Processes build requests
PM2 processes:
astro-main
- Main installation Astro process
Dedicated Instance Services
Section titled “Dedicated Instance Services”systemd services:
tractstack-go@{SITE_ID}.service
- Site-specific Go backend
PM2 processes:
astro-{SITE_ID}
- Dedicated site Astro processes
systemd Service Management
Section titled “systemd Service Management”Main Installation Commands
Section titled “Main Installation Commands”Service status:
sudo systemctl status tractstack-gosudo systemctl status t8k-build-watcher.servicesudo systemctl status t8k-build-watcher.path
Start/stop/restart:
sudo systemctl start tractstack-gosudo systemctl stop tractstack-gosudo systemctl restart tractstack-go
Enable/disable auto-start:
sudo systemctl enable tractstack-gosudo systemctl disable tractstack-go
View logs:
sudo journalctl -u tractstack-go -fsudo journalctl -u tractstack-go --no-pager -n 50
Dedicated Instance Commands
Section titled “Dedicated Instance Commands”Service management (replace SITE_ID):
sudo systemctl status tractstack-go@SITE_IDsudo systemctl restart tractstack-go@SITE_IDsudo journalctl -u tractstack-go@SITE_ID -f
PM2 Process Management
Section titled “PM2 Process Management”Access PM2
Section titled “Access PM2”Switch to t8k user:
sudo -u t8k bash
PM2 Commands
Section titled “PM2 Commands”View all processes:
pm2 statuspm2 list
Restart processes:
pm2 restart astro-main # Main installationpm2 restart astro-SITE_ID # Dedicated instancepm2 restart all # All processes
Stop/start processes:
pm2 stop astro-mainpm2 start astro-main
View logs:
pm2 logs astro-mainpm2 logs astro-SITE_IDpm2 logs --lines 50
Real-time monitoring:
pm2 monit
Process details:
pm2 describe astro-mainpm2 show astro-main
Port Management
Section titled “Port Management”Port Allocation
Section titled “Port Allocation”TractStack automatically manages ports via /home/t8k/etc/t8k-ports.conf
:
Main installation:
- Go backend: Port 10000
- Astro frontend: Port 20000
Dedicated instances:
- Go backend: Ports 10001, 10002, 10003…
- Astro frontend: Ports 20001, 20002, 20003…
Check port allocations:
cat /home/t8k/etc/t8k-ports.conf
Verify port usage:
sudo netstat -tlnp | grep :10000sudo netstat -tlnp | grep :20000lsof -i :10000
nginx Integration
Section titled “nginx Integration”nginx Configuration
Section titled “nginx Configuration”Test configuration:
sudo nginx -t
Reload configuration:
sudo systemctl reload nginx
Restart nginx:
sudo systemctl restart nginx
Check nginx status:
sudo systemctl status nginx
nginx Logs
Section titled “nginx Logs”Error logs:
sudo tail -f /var/log/nginx/error.log
Access logs:
sudo tail -f /var/log/nginx/access.log
Service Health Checks
Section titled “Service Health Checks”Backend Health
Section titled “Backend Health”Check Go backend response:
curl -I http://localhost:10000/healthcurl -I http://localhost:10001/health # Dedicated instance
Frontend Health
Section titled “Frontend Health”Check Astro frontend:
curl -I http://localhost:20000curl -I http://localhost:20001 # Dedicated instance
Full Stack Health
Section titled “Full Stack Health”Check complete request flow:
curl -I https://yourdomain.comcurl -I https://tenant.yourdomain.com # Multi-tenant
Troubleshooting Services
Section titled “Troubleshooting Services”Service Won’t Start
Section titled “Service Won’t Start”Check service status:
sudo systemctl status tractstack-gosudo journalctl -u tractstack-go --no-pager
Common issues:
- Port already in use
- Missing configuration files
- Database connection errors
- Permission problems
Check port conflicts:
sudo netstat -tlnp | grep :10000sudo lsof -i :10000
PM2 Process Issues
Section titled “PM2 Process Issues”Process crashed:
pm2 logs astro-main --errpm2 describe astro-main
Restart failed process:
pm2 restart astro-mainpm2 reload astro-main
Delete and recreate process:
pm2 delete astro-mainpm2 start ecosystem.config.js
Performance Issues
Section titled “Performance Issues”High CPU usage:
top -u t8khtop -u t8k
Memory usage:
ps aux | grep tractstackpm2 monit
Disk space:
df -hdu -sh /home/t8k/
Service Monitoring
Section titled “Service Monitoring”Automated Monitoring
Section titled “Automated Monitoring”systemd auto-restart: Services are configured to restart automatically on failure.
PM2 auto-restart:
pm2 startup systemd -u t8k --hp /home/t8kpm2 save
Health Monitoring Scripts
Section titled “Health Monitoring Scripts”Service health check script:
#!/bin/bash# Check if services are runningsystemctl is-active --quiet tractstack-go || echo "tractstack-go is down"sudo -u t8k pm2 jlist | jq -r '.[] | select(.pm2_env.status != "online") | .name' | while read proc; do echo "PM2 process $proc is not online"done
Log Rotation
Section titled “Log Rotation”systemd logs: Automatically managed by journald with configurable retention.
PM2 logs:
pm2 install pm2-logrotatepm2 set pm2-logrotate:max_size 10Mpm2 set pm2-logrotate:retain 30
Service Updates
Section titled “Service Updates”Update Process
Section titled “Update Process”- Stop services:
sudo systemctl stop tractstack-gosudo -u t8k pm2 stop all
- Update code:
cd /home/t8k/src/tractstack-gogit pullgo build
cd /home/t8k/src/my-tractstackgit pullpnpm installpnpm build
- Start services:
sudo systemctl start tractstack-gosudo -u t8k pm2 start all
Automated Updates
Section titled “Automated Updates”Build concierge:
The t8k-concierge.sh
script handles automated builds and service restarts.
Trigger build:
echo "type=main,tenant=default,command=build" > /home/t8k/state/build-$(date +%s).csv
Proper service management ensures reliable TractStack operation. Regular monitoring and maintenance prevent issues and ensure optimal performance.