Service Management CLI Commands

Commands for managing, monitoring, and interacting with nself services. With v0.3.5 delivering 100% service reliability (17/17 services), enhanced SSL support, and smart port allocation.

✨ Enhanced in v0.3.5: Perfect Service Reliability

  • 100% Success Rate: All 17 services start successfully every time
  • Volume Mount Fixes: Resolved critical Docker volume mounting issues
  • Smart Port Allocation: Organized port management prevents conflicts
  • Enhanced Health Monitoring: Better status checking and auto-recovery

Core Service Commands

nself up 100% Reliable

Start all services with guaranteed success (v0.3.5):

# Start all services (100% success rate in v0.3.5)
nself up

# Start specific services
nself up postgres hasura
nself up --services postgres,hasura,minio

# Start with recreation (rebuild containers)
nself up --recreate

# Start in detached mode (background)
nself up --detach

# Start with custom configuration
nself up --env-file .env.staging

# Start with SSL enabled (default in v0.3.5)
# All services automatically use HTTPS when available

nself down

Stop services gracefully:

# Stop all services
nself down

# Stop specific services
nself down postgres hasura

# Stop and remove volumes (⚠️ data loss)
nself down --volumes

# Force stop (immediate shutdown)
nself down --force

# Stop and remove everything
nself down --remove-all

nself restart

Restart services (down + up):

# Restart all services
nself restart

# Restart specific service
nself restart postgres

# Restart with rebuild
nself restart --build

# Rolling restart (zero downtime)
nself restart --rolling

Service Status and Monitoring

nself status

Check service status:

# Basic status
nself status

# Example output:
# SERVICE     STATUS    HEALTH    UPTIME     PORTS
# postgres    Running   Healthy   2h 15m     5432->5432
# hasura      Running   Healthy   2h 14m     8080->8080
# minio       Running   Healthy   2h 14m     9000->9000, 9001->9001
# redis       Running   Healthy   2h 14m     6379->6379
# nginx       Running   Healthy   2h 13m     80->80, 443->443

# Detailed status
nself status --verbose

# JSON output for scripting
nself status --format json

# Check specific service
nself status postgres

nself ps

List running containers:

# List all containers
nself ps

# Show resource usage
nself ps --stats

# Show full command
nself ps --no-trunc

Service Logs

nself logs

View service logs:

# View all logs
nself logs

# Follow logs (tail -f style)
nself logs -f

# Show last N lines
nself logs --tail 100

# Show logs for specific service
nself logs postgres
nself logs hasura
nself logs nginx

# Show logs with timestamps
nself logs --timestamps

# Filter by time period
nself logs --since "2h"
nself logs --until "2025-08-06 15:00"

Service Interaction

nself exec

Execute commands inside service containers:

# Access PostgreSQL
nself exec postgres psql -U postgres

# Interactive bash shell
nself exec -it postgres bash
nself exec -it hasura sh

# Run one-off commands
nself exec postgres pg_dump -U postgres myproject > backup.sql
nself exec redis redis-cli ping
nself exec minio mc ls local/

# Execute as specific user
nself exec --user root postgres bash

Database Service Management

PostgreSQL Commands

# Access PostgreSQL CLI
nself exec postgres psql -U postgres

# Create database backup
nself exec postgres pg_dump -U postgres myproject > backup.sql

# Restore database
nself exec -i postgres psql -U postgres myproject < backup.sql

# Check database status
nself exec postgres pg_isready -U postgres

# View active connections
nself exec postgres psql -U postgres -c "SELECT * FROM pg_stat_activity;"

# Database size information
nself exec postgres psql -U postgres -c "SELECT pg_database.datname, pg_size_pretty(pg_database_size(pg_database.datname)) AS size FROM pg_database;"

Database Configuration

# View PostgreSQL configuration
nself exec postgres psql -U postgres -c "SHOW ALL;"

# Check specific settings
nself exec postgres psql -U postgres -c "SHOW shared_buffers;"
nself exec postgres psql -U postgres -c "SHOW max_connections;"

# View database statistics
nself exec postgres psql -U postgres -c "SELECT * FROM pg_stat_database;"

# Check for slow queries
nself exec postgres psql -U postgres -c "SELECT query, mean_time, calls FROM pg_stat_statements ORDER BY mean_time DESC LIMIT 10;"

Hasura Service Management

Hasura Console Commands

# Access Hasura console (auto-opens browser)
nself hasura console

# Access Hasura CLI inside container
nself exec hasura hasura-cli version

# Apply migrations
nself exec hasura hasura-cli migrate apply

# Check migration status
nself exec hasura hasura-cli migrate status

# Reload metadata
nself exec hasura hasura-cli metadata reload

# Export metadata
nself exec hasura hasura-cli metadata export

GraphQL API Testing

# Test GraphQL endpoint
curl -X POST http://localhost:8080/v1/graphql \
  -H "Content-Type: application/json" \
  -H "X-Hasura-Admin-Secret: your-secret" \
  -d '{"query": "{ __schema { queryType { name } } }"}'

# Check Hasura health
curl http://localhost:8080/healthz

# View Hasura configuration
nself exec hasura hasura-cli console --api-port 9695

Storage Service Management

MinIO Commands

# Access MinIO client
nself exec minio mc --help

# List buckets
nself exec minio mc ls local/

# Create bucket
nself exec minio mc mb local/my-new-bucket

# Upload file
nself exec minio mc cp /local/file.txt local/my-bucket/

# Download file
nself exec minio mc cp local/my-bucket/file.txt /local/

# Set bucket policy
nself exec minio mc policy set public local/my-bucket

# Mirror directory
nself exec minio mc mirror /local/directory local/my-bucket/

Redis Service Management

Redis Commands

# Access Redis CLI
nself exec redis redis-cli

# Test Redis connection
nself exec redis redis-cli ping

# Get Redis info
nself exec redis redis-cli info

# Monitor Redis commands
nself exec redis redis-cli monitor

# Check Redis memory usage
nself exec redis redis-cli info memory

# List all keys (be careful in production)
nself exec redis redis-cli keys "*"

# Clear all Redis data
nself exec redis redis-cli flushall

Nginx Service Management

Nginx Commands

# Test nginx configuration
nself exec nginx nginx -t

# Reload nginx configuration
nself exec nginx nginx -s reload

# View nginx configuration
nself exec nginx cat /etc/nginx/nginx.conf

# Check nginx status
curl http://localhost/status

# View access logs
nself exec nginx tail -f /var/log/nginx/access.log

# View error logs
nself exec nginx tail -f /var/log/nginx/error.log

Custom Service Management

NestJS Services

# Access NestJS service
nself exec nestjs npm run start:dev

# View NestJS logs
nself logs nestjs

# Run tests
nself exec nestjs npm test

# Install new packages
nself exec nestjs npm install package-name

# Generate NestJS components
nself exec nestjs nest generate controller users

BullMQ Worker Services

# View BullMQ worker logs
nself logs bullmq-worker

# Check queue status
nself exec redis redis-cli llen bull:default:wait

# Clear failed jobs
nself exec redis redis-cli del bull:default:failed

# Monitor job processing
nself exec bullmq-worker npm run monitor

Service Health Checks

nself health

Comprehensive health checking:

# Check all service health
nself health

# Check specific service health
nself health postgres
nself health hasura

# Deep health check with diagnostics
nself health --deep

# Health check with custom timeout
nself health --timeout 30s

# Export health status
nself health --format json > health.json

Service Configuration

nself config service

Service-specific configuration:

# View service configuration
nself config service postgres
nself config service hasura

# Update service configuration
nself config service postgres --max-connections 200
nself config service redis --maxmemory 256mb

# Reset service configuration
nself config service postgres --reset

# Validate service configuration
nself config service --validate

Service Performance

nself perf

Performance monitoring and analysis:

# Monitor service performance
nself perf

# Service-specific performance
nself perf postgres
nself perf hasura

# Generate performance report
nself perf --report

# Real-time performance monitoring
nself perf --watch

# Performance with custom metrics
nself perf --metrics cpu,memory,io,network

Troubleshooting Services

Common Service Issues

# Service won't start
nself logs [service-name]
nself exec [service-name] ps aux

# Service keeps crashing
nself restart [service-name] --no-deps
nself exec [service-name] /bin/sh

# Performance issues
nself exec [service-name] top
nself perf [service-name]

# Network connectivity issues
nself exec service1 ping service2
nself exec service1 nc -zv service2 5432

# Configuration issues
nself config validate
nself config service [service-name] --check

Service Scaling

nself scale

Scale services for load:

# Scale specific service
nself scale hasura 3

# Scale multiple services
nself scale hasura=3 nestjs=2

# Auto-scaling
nself scale --auto --cpu-threshold 70

# Scale with resource limits
nself scale hasura 3 --memory 512M --cpus 0.5

Automation and Scripting

Service Management Script

#!/bin/bash
# service-manager.sh

case "$1" in
  start)
    echo "Starting all services..."
    nself up --detach
    ;;
  stop)
    echo "Stopping all services..."
    nself down
    ;;
  restart)
    echo "Restarting services..."
    nself restart
    ;;
  status)
    nself status --verbose
    ;;
  health)
    if nself health --quick; then
      echo "All services healthy"
      exit 0
    else
      echo "Service health check failed"
      exit 1
    fi
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|status|health}"
    exit 1
    ;;
esac

Best Practices

  • Graceful Shutdowns - Always use nself down instead of force-killing containers
  • Health Monitoring - Regularly check service health with nself health
  • Log Management - Monitor logs and set up log rotation
  • Resource Limits - Set appropriate CPU and memory limits for services
  • Service Dependencies - Understand service startup order and dependencies
  • Backup Before Changes - Always backup before making service configuration changes
  • Testing - Test service interactions after configuration changes

Next Steps