entrypoint.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/bin/bash
  2. set -e
  3. echo "🚀 Starting APT Mirror Container..."
  4. # Function to handle shutdown gracefully
  5. cleanup() {
  6. echo "🛑 Shutting down services..."
  7. if [ -n "$NGINX_PID" ]; then
  8. kill $NGINX_PID
  9. fi
  10. if [ -n "$MIRROR_PID" ]; then
  11. kill $MIRROR_PID
  12. fi
  13. exit 0
  14. }
  15. # Set up signal handlers
  16. trap cleanup SIGTERM SIGINT
  17. # Create necessary directories if they don't exist
  18. mkdir -p /var/log/nginx
  19. mkdir -p /var/log/apt-mirror
  20. mkdir -p /var/spool/apt-mirror
  21. mkdir -p /var/www/mirror.intra
  22. # Set proper permissions
  23. chown -R www-data:www-data /var/www
  24. chown -R www-data:www-data /var/spool/apt-mirror
  25. # Create symlink for apt-mirror data if it doesn't exist
  26. if [ ! -L /var/www/mirror.intra/mirror ]; then
  27. ln -sf /var/spool/apt-mirror/mirror /var/www/mirror.intra/mirror
  28. fi
  29. # Enable nginx sites if configs are mounted
  30. if [ -f /etc/nginx/sites-available/mirror.intra.conf ]; then
  31. echo "🔗 Enabling nginx sites..."
  32. # Remove default site if it exists
  33. rm -f /etc/nginx/sites-enabled/default
  34. ln -sf /etc/nginx/sites-available/mirror.intra.conf /etc/nginx/sites-enabled/ 2>/dev/null || true
  35. ln -sf /etc/nginx/sites-available/admin.mirror.intra.conf /etc/nginx/sites-enabled/ 2>/dev/null || true
  36. ln -sf /etc/nginx/sites-available/files.mirror.intra.conf /etc/nginx/sites-enabled/ 2>/dev/null || true
  37. echo "✅ Nginx sites enabled"
  38. else
  39. echo "⚠️ Nginx configuration not found. Please ensure nginx config volume is mounted."
  40. fi
  41. # Check if htpasswd file exists
  42. if [ ! -f /etc/nginx/.htpasswd ]; then
  43. echo "❌ htpasswd file not found. Please ensure data/conf/nginx/.htpasswd is mounted."
  44. exit 1
  45. fi
  46. echo "✅ htpasswd file found"
  47. # Start admin server
  48. echo "🌐 Starting admin server..."
  49. cd /var/admin && npm run start &
  50. ADMIN_PID=$!
  51. # Wait a moment for admin to start
  52. sleep 2
  53. # Start nginx
  54. echo "🌐 Starting nginx..."
  55. nginx -g "daemon off;" &
  56. NGINX_PID=$!
  57. sleep 2
  58. # Check if nginx started successfully
  59. if ! kill -0 $NGINX_PID 2>/dev/null; then
  60. echo "❌ Failed to start nginx"
  61. exit 1
  62. fi
  63. echo "✅ nginx started successfully (PID: $NGINX_PID)"
  64. # Start apt-mirror2 sync in background if configuration exists
  65. if [ -f /etc/apt/mirror.list ]; then
  66. echo "🔄 Starting apt-mirror2 sync..."
  67. /usr/local/bin/mirror-sync.sh &
  68. MIRROR_PID=$!
  69. echo "✅ apt-mirror2 sync started (PID: $MIRROR_PID)"
  70. else
  71. echo "⚠️ No apt-mirror2 configuration found. Skipping sync."
  72. fi
  73. # Start health check service
  74. echo "🏥 Starting health check service..."
  75. /usr/local/bin/health-check.sh &
  76. HEALTH_PID=$!
  77. echo "🎉 All services started successfully!"
  78. echo "📊 Services running:"
  79. echo " - nginx (PID: $NGINX_PID)"
  80. if [ -n "$MIRROR_PID" ]; then
  81. echo " - apt-mirror2 sync (PID: $MIRROR_PID)"
  82. fi
  83. echo " - health check (PID: $HEALTH_PID)"
  84. # Wait for any process to exit
  85. wait
  86. # If we get here, something went wrong
  87. echo "❌ One of the services exited unexpectedly"
  88. exit 1