entrypoint.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. OLD_IP="tst"
  9. SUDO="NO"
  10. # Configuration files and directories
  11. memcached_dir="/var/run/memcached/"
  12. apache_default_site="/etc/apache2/sites-available/000-default.conf"
  13. : '
  14. START SERVICES
  15. On unpause conditionally start only those services that user already enabled
  16. '
  17. MONGODB_STATUS="off"
  18. ELASTICSEARCH_STATUS="off"
  19. REDIS_STATUS="off"
  20. MEMCACHED_STATUS="off"
  21. SSHD_STATUS="off"
  22. PHP56FPM_STATUS="off"
  23. PHP70FPM_STATUS="off"
  24. PHP71FPM_STATUS="off"
  25. PHP72FPM_STATUS="off"
  26. PHP73FPM_STATUS="off"
  27. PHP74FPM_STATUS="off"
  28. PHP80FPM_STATUS="off"
  29. PHP81FPM_STATUS="off"
  30. PHP82FPM_STATUS="off"
  31. PHP83FPM_STATUS="off"
  32. PHP84FPM_STATUS="off"
  33. MYSQL_STATUS="off"
  34. CRON_STATUS="off"
  35. APACHE_STATUS="off"
  36. start_service() {
  37. if [ "$1" == "on" ]; then
  38. echo "Starting $2..."
  39. service "$2" start
  40. fi
  41. }
  42. start_service "$MONGODB_STATUS" "mongodb"
  43. start_service "$ELASTICSEARCH_STATUS" "elasticsearch"
  44. start_service "$REDIS_STATUS" "redis-server"
  45. start_service "$MEMCACHED_STATUS" "memcached"
  46. start_service "$SSHD_STATUS" "ssh"
  47. start_service "$PHP56FPM_STATUS" "php5.6-fpm"
  48. start_service "$PHP70FPM_STATUS" "php7.0-fpm"
  49. start_service "$PHP71FPM_STATUS" "php7.1-fpm"
  50. start_service "$PHP72FPM_STATUS" "php7.2-fpm"
  51. start_service "$PHP73FPM_STATUS" "php7.3-fpm"
  52. start_service "$PHP74FPM_STATUS" "php7.4-fpm"
  53. start_service "$PHP80FPM_STATUS" "php8.0-fpm"
  54. start_service "$PHP81FPM_STATUS" "php8.1-fpm"
  55. start_service "$PHP82FPM_STATUS" "php8.2-fpm"
  56. start_service "$PHP83FPM_STATUS" "php8.3-fpm"
  57. start_service "$PHP84FPM_STATUS" "php8.4-fpm"
  58. start_service "$MYSQ_STATUS" "mysql"
  59. start_service "$CRON_STATUS" "cron"
  60. start_service "$APACHE_STATUS" "apache2"
  61. : '
  62. CRON
  63. fix for https://github.com/stefanpejcic/OpenPanel/issues/75
  64. '
  65. chown :crontab /var/spool/cron/crontabs/
  66. : '
  67. APACHE
  68. Enable all user websites and create directory for access logs.
  69. '
  70. #Make domlogs
  71. mkdir -p /var/log/apache2/domlogs
  72. # Replace the old IP address with the containers new IP in nginx config files and enable website
  73. replace_ip_in_sites() {
  74. if [ -n "$OLD_IP" ]; then
  75. local site_files="/etc/apache2/sites-available"
  76. for file in $site_files; do
  77. if [ -f "$file" ]; then
  78. echo "Updating IP in $file..."
  79. sed -i "s/$OLD_IP/$CONTAINER_IP/g" "$file"
  80. echo "Added $file to apache2 sites-enabled..."
  81. a2ensite "$file"
  82. fi
  83. done
  84. fi
  85. }
  86. # (OLD_IP Has value only on re-run)
  87. replace_ip_in_sites
  88. # to prevent users from editing the files..
  89. chmod 700 /etc/apache2/sites-available
  90. chmod 700 /etc/apache2/sites-enabled
  91. sites_available_dir="/etc/apache2/sites-available"
  92. if [ "$(grep 'OLD_IP="tst"' /etc/entrypoint.sh)" ]; then
  93. echo "Apache is not started, since there are no websites yet."
  94. else
  95. # if there are any sites, start the service
  96. if [ "$(ls -A $sites_available_dir | grep -v 'default')" ]; then
  97. service apache2 start
  98. echo "Apache service started."
  99. else
  100. echo "No websites found in $sites_available_dir. Apache service not started automatically."
  101. fi
  102. fi
  103. # sudo
  104. if grep -q 'SUDO="YES"' /etc/entrypoint.sh; then
  105. # Add user with UID 1000 to the sudo group
  106. usermod -aG sudo -u 1000 $(getent passwd 1000 | cut -d: -f1)
  107. fi
  108. # Save the current IP for reuse
  109. sed -i "s/$OLD_IP/$CONTAINER_IP/g" "$0"