entrypoint.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/bin/bash
  2. echo "Container is starting..."
  3. : '
  4. CONFIGURATION
  5. On restart grant sudo if set, store random ip
  6. '
  7. CONTAINER_IP=$(hostname -i)
  8. GATEWAY_IP=$(ip route | awk '/default/ { print $3 }')
  9. OLD_IP="tst"
  10. SUDO="NO"
  11. : '
  12. START SERVICES
  13. On unpause conditionally start only those services that user already enabled
  14. '
  15. MONGODB_STATUS="off"
  16. ELASTICSEARCH_STATUS="off"
  17. REDIS_STATUS="off"
  18. MEMCACHED_STATUS="off"
  19. SSHD_STATUS="off"
  20. PHP56FPM_STATUS="off"
  21. PHP70FPM_STATUS="off"
  22. PHP71FPM_STATUS="off"
  23. PHP72FPM_STATUS="off"
  24. PHP73FPM_STATUS="off"
  25. PHP74FPM_STATUS="off"
  26. PHP80FPM_STATUS="off"
  27. PHP81FPM_STATUS="off"
  28. PHP82FPM_STATUS="off"
  29. PHP83FPM_STATUS="off"
  30. PHP84FPM_STATUS="off"
  31. MYSQL_STATUS="off"
  32. CRON_STATUS="off"
  33. NGINX_STATUS="off"
  34. start_service() {
  35. if [ "$1" == "on" ]; then
  36. echo "Starting $2..."
  37. service "$2" start
  38. fi
  39. }
  40. start_service "$MONGODB_STATUS" "mongodb"
  41. start_service "$ELASTICSEARCH_STATUS" "elasticsearch"
  42. start_service "$REDIS_STATUS" "redis-server"
  43. start_service "$MEMCACHED_STATUS" "memcached"
  44. start_service "$SSHD_STATUS" "ssh"
  45. start_service "$PHP56FPM_STATUS" "php5.6-fpm"
  46. start_service "$PHP70FPM_STATUS" "php7.0-fpm"
  47. start_service "$PHP71FPM_STATUS" "php7.1-fpm"
  48. start_service "$PHP72FPM_STATUS" "php7.2-fpm"
  49. start_service "$PHP73FPM_STATUS" "php7.3-fpm"
  50. start_service "$PHP74FPM_STATUS" "php7.4-fpm"
  51. start_service "$PHP80FPM_STATUS" "php8.0-fpm"
  52. start_service "$PHP81FPM_STATUS" "php8.1-fpm"
  53. start_service "$PHP82FPM_STATUS" "php8.2-fpm"
  54. start_service "$PHP83FPM_STATUS" "php8.3-fpm"
  55. start_service "$PHP84FPM_STATUS" "php8.4-fpm"
  56. start_service "$MYSQ_STATUS" "mysql"
  57. start_service "$CRON_STATUS" "cron"
  58. start_service "$NGINX_STATUS" "nginx"
  59. : '
  60. CRON
  61. fix for https://github.com/stefanpejcic/OpenPanel/issues/75
  62. '
  63. chown :crontab /var/spool/cron/crontabs/
  64. : '
  65. NGINX
  66. Enable all user websites and create directory for access logs.
  67. '
  68. # Function to update IP in nginx config files
  69. replace_gateway_ip_and_ip_in_sites() {
  70. local conf_dir="/etc/nginx/sites-available"
  71. if [ -n "$GATEWAY_IP" ]; then
  72. for conf_file in "$conf_dir"/*; do
  73. if [ -f "$conf_file" ]; then
  74. sed -i "s/set_real_ip_from[[:space:]]*[^;]*;/set_real_ip_from $GATEWAY_IP;/g" "$conf_file"
  75. echo "Updated $conf_file with GATEWAY_IP."
  76. fi
  77. done
  78. if [ -n "$OLD_IP" ]; then
  79. for file in $conf_dir; do
  80. if [ -f "$file" ]; then
  81. echo "Updating IP in $file..."
  82. sed -i "s/$OLD_IP/$CONTAINER_IP/g" "$file"
  83. echo "Linking $file to nginx sites-enabled..."
  84. ln -s "$file" /etc/nginx/sites-enabled/
  85. fi
  86. done
  87. fi
  88. else
  89. echo "Error: GATEWAY_IP is not set."
  90. fi
  91. }
  92. replace_gateway_ip_and_ip_in_sites
  93. sites_available_dir="/etc/nginx/sites-available"
  94. if [ "$(ls -A $sites_available_dir | grep -v 'default')" ]; then
  95. service nginx start
  96. echo "Nginx service started."
  97. else
  98. echo "No websites found in $sites_available_dir. Nginx service not started automatically."
  99. fi
  100. # sudo
  101. if grep -q 'SUDO="YES"' /etc/entrypoint.sh; then
  102. # Add user with UID 1000 to the sudo group
  103. usermod -aG sudo -u 1000 $(getent passwd 1000 | cut -d: -f1)
  104. fi
  105. # Save the current IP for reuse
  106. sed -i "s/$OLD_IP/$CONTAINER_IP/g" "$0"