homelab infrastructure services
at main 86 lines 2.8 kB view raw
1#!/bin/bash 2# tin machine status - Show machine environment status 3 4set -euo pipefail 5 6# Get tinsnip root and source libraries 7SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 8TINSNIP_ROOT="$(dirname "$(dirname "$SCRIPT_DIR")")" 9source "$TINSNIP_ROOT/lib/core.sh" 10source "$TINSNIP_ROOT/lib/uid.sh" 11 12# Show machine environment status 13show_machine_status() { 14 local service_env="$1" 15 16 # Parse service-environment 17 local parsed_output 18 if ! parsed_output=$(parse_machine_name "$service_env" 2>/dev/null); then 19 error_with_prefix "Machine Status" "Invalid machine environment format: '$service_env'" 20 echo "Expected: <service>-<environment> (e.g., gazette-prod, bsky-pds-dev)" >&2 21 exit 1 22 fi 23 24 local service=$(echo "$parsed_output" | sed -n '1p') 25 local environment=$(echo "$parsed_output" | sed -n '2p') 26 27 echo "Machine Environment Status: $service_env" 28 echo "========================================" 29 echo 30 31 # Calculate UID and check user exists 32 local service_uid 33 if service_uid=$(calculate_service_uid "$service" "$environment" 2>/dev/null); then 34 echo "Service: $service" 35 echo "Environment: $environment" 36 echo "UID: $service_uid" 37 38 if getent passwd "$service_uid" >/dev/null 2>&1; then 39 local username=$(getent passwd "$service_uid" | cut -d: -f1) 40 echo "User: $username" 41 else 42 echo "User: missing ❌" 43 echo "Create with: tin machine create $service $environment" 44 return 1 45 fi 46 else 47 error_with_prefix "Machine Status" "Cannot calculate UID for $service_env" 48 return 1 49 fi 50 51 # Check NFS mount 52 local mount_point="/mnt/$service-$environment" 53 echo "Mount: $mount_point" 54 if mountpoint -q "$mount_point" 2>/dev/null; then 55 echo " Status: mounted ✅" 56 echo " Usage: $(df -h "$mount_point" | tail -1 | awk '{print $3 "/" $2 " (" $5 " used)"}')" 57 else 58 echo " Status: not mounted ❌" 59 fi 60 61 # Check Docker access 62 if sudo -u "$service-$environment" docker version >/dev/null 2>&1; then 63 echo "Docker: accessible ✅" 64 else 65 echo "Docker: not accessible ❌" 66 fi 67 68 echo 69 echo "Environment variables:" 70 if sudo -u "$service-$environment" bash -c 'source ~/.tinsnip-env-loader.sh 2>/dev/null && env | grep ^TIN_' 2>/dev/null; then 71 echo " Environment: loaded ✅" 72 else 73 echo " Environment: not configured ❌" 74 fi 75} 76 77# Main execution 78if [[ $# -eq 0 ]]; then 79 error_with_prefix "Machine Status" "Service-environment required" 80 echo "Usage: tin machine status <service-env>" >&2 81 echo "Example: tin machine status gazette-prod" >&2 82 exit 1 83fi 84 85service_env="$1" 86show_machine_status "$service_env"