mirror of
https://github.com/manualdousuario/marreta.git
synced 2025-09-01 10:10:14 +00:00
automatização do registro de environments
This commit is contained in:
parent
5096aacb83
commit
891c6df97a
1 changed files with 27 additions and 72 deletions
|
@ -14,99 +14,52 @@
|
|||
# - Inicia e verifica serviços (PHP-FPM e Nginx)
|
||||
###########################################
|
||||
|
||||
# Output colors
|
||||
# Cores de saída / Output colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
NC='\033[0m' # No Color / Sem Cor
|
||||
|
||||
# Success log function
|
||||
# Função de log de sucesso / Success log function
|
||||
log_success() {
|
||||
echo -e "${GREEN}[✓] $1${NC}"
|
||||
}
|
||||
|
||||
# Error log function
|
||||
# Função de log de erro / Error log function
|
||||
log_error() {
|
||||
echo -e "${RED}[✗] $1${NC}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Info log function
|
||||
# Função de log de informação / Info log function
|
||||
log_info() {
|
||||
echo -e "${YELLOW}[i] $1${NC}"
|
||||
}
|
||||
|
||||
echo -e "\n${YELLOW}=== Starting Marreta ===${NC}\n"
|
||||
|
||||
# === Environment Variables Configuration ===
|
||||
# === Configuração das Variáveis de Ambiente / Environment Variables Configuration ===
|
||||
log_info "Configuring environment variables..."
|
||||
|
||||
if [ -n "${SITE_NAME}" ]; then
|
||||
echo "SITE_NAME=\"${SITE_NAME}\"" >> /app/.env
|
||||
fi
|
||||
# Arquivo de ambiente (.env) / Env file (.env)
|
||||
ENV_FILE="/app/.env"
|
||||
|
||||
if [ -n "${SITE_DESCRIPTION}" ]; then
|
||||
echo "SITE_DESCRIPTION=\"${SITE_DESCRIPTION}\"" >> /app/.env
|
||||
fi
|
||||
# Limpa o arquivo de ambiente / Clean Env file
|
||||
> "$ENV_FILE"
|
||||
|
||||
if [ -n "${SITE_URL}" ]; then
|
||||
echo "SITE_URL=${SITE_URL}" >> /app/.env
|
||||
fi
|
||||
while IFS='=' read -r key value; do
|
||||
# If value contains spaces and is not already quoted, add quotes
|
||||
# Se o valor contém espaços e não está entre aspas, adiciona aspas
|
||||
if [[ "$value" =~ \ ]] && ! [[ "$value" =~ ^\".*\"$ ]]; then
|
||||
value="\"$value\""
|
||||
fi
|
||||
|
||||
if [ -n "${LANGUAGE}" ]; then
|
||||
echo "LANGUAGE=${LANGUAGE}" >> /app/.env
|
||||
fi
|
||||
|
||||
if [ -n "${DNS_SERVERS}" ]; then
|
||||
echo "DNS_SERVERS=${DNS_SERVERS}" >> /app/.env
|
||||
fi
|
||||
|
||||
# S3 Settings
|
||||
if [ -n "${S3_CACHE_ENABLED}" ]; then
|
||||
echo "S3_CACHE_ENABLED=${S3_CACHE_ENABLED}" >> /app/.env
|
||||
fi
|
||||
|
||||
if [ -n "${S3_ACCESS_KEY}" ]; then
|
||||
echo "S3_ACCESS_KEY=${S3_ACCESS_KEY}" >> /app/.env
|
||||
fi
|
||||
|
||||
if [ -n "${S3_SECRET_KEY}" ]; then
|
||||
echo "S3_SECRET_KEY=${S3_SECRET_KEY}" >> /app/.env
|
||||
fi
|
||||
|
||||
if [ -n "${S3_BUCKET}" ]; then
|
||||
echo "S3_BUCKET=${S3_BUCKET}" >> /app/.env
|
||||
fi
|
||||
|
||||
if [ -n "${S3_REGION}" ]; then
|
||||
echo "S3_REGION=${S3_REGION}" >> /app/.env
|
||||
fi
|
||||
|
||||
if [ -n "${S3_FOLDER}" ]; then
|
||||
echo "S3_FOLDER=${S3_FOLDER}" >> /app/.env
|
||||
fi
|
||||
|
||||
if [ -n "${S3_ACL}" ]; then
|
||||
echo "S3_ACL=${S3_ACL}" >> /app/.env
|
||||
fi
|
||||
|
||||
if [ -n "${S3_ENDPOINT}" ]; then
|
||||
echo "S3_ENDPOINT=${S3_ENDPOINT}" >> /app/.env
|
||||
fi
|
||||
|
||||
# Selenium Settings
|
||||
if [ -n "${SELENIUM_HOST}" ]; then
|
||||
echo "SELENIUM_HOST=${SELENIUM_HOST}" >> /app/.env
|
||||
fi
|
||||
|
||||
# Hawk.so Settings
|
||||
if [ -n "${HAWK_TOKEN}" ]; then
|
||||
echo "HAWK_TOKEN=${HAWK_TOKEN}" >> /app/.env
|
||||
fi
|
||||
echo "$key=$value" >> "$ENV_FILE"
|
||||
done < <(env)
|
||||
|
||||
log_success "Environment variables configured"
|
||||
|
||||
# === Permissions Adjustment ===
|
||||
# === Ajuste de Permissões / Permissions Adjustment ===
|
||||
log_info "Adjusting directory permissions..."
|
||||
|
||||
chown -R www-data:www-data /app/cache /app/logs
|
||||
|
@ -114,7 +67,7 @@ chmod -R 775 /app/cache /app/logs
|
|||
|
||||
log_success "Permissions adjusted"
|
||||
|
||||
# === Service Check Functions ===
|
||||
# === Funções de Verificação de Serviços / Service Check Functions ===
|
||||
check_nginx() {
|
||||
if ! pgrep nginx > /dev/null; then
|
||||
log_error "Failed to start Nginx"
|
||||
|
@ -131,10 +84,10 @@ check_php_fpm() {
|
|||
fi
|
||||
}
|
||||
|
||||
# === Services Initialization ===
|
||||
# === Inicialização dos Serviços / Services Initialization ===
|
||||
echo -e "\n${YELLOW}=== Starting services ===${NC}\n"
|
||||
|
||||
# PHP-FPM Directory
|
||||
# Diretório do PHP-FPM / PHP-FPM Directory
|
||||
if [ ! -d /var/run/php ]; then
|
||||
log_info "Creating PHP-FPM directory..."
|
||||
mkdir -p /var/run/php
|
||||
|
@ -142,13 +95,13 @@ if [ ! -d /var/run/php ]; then
|
|||
log_success "PHP-FPM directory created"
|
||||
fi
|
||||
|
||||
# Starting PHP-FPM
|
||||
# Iniciando PHP-FPM / Starting PHP-FPM
|
||||
log_info "Starting PHP-FPM..."
|
||||
php-fpm &
|
||||
sleep 3
|
||||
check_php_fpm
|
||||
|
||||
# Checking Nginx configuration
|
||||
# Verificando configuração do Nginx / Checking Nginx configuration
|
||||
log_info "Checking Nginx configuration..."
|
||||
nginx -t
|
||||
if [ $? -ne 0 ]; then
|
||||
|
@ -157,7 +110,7 @@ else
|
|||
log_success "Valid Nginx configuration"
|
||||
fi
|
||||
|
||||
# Starting Nginx
|
||||
# Iniciando Nginx / Starting Nginx
|
||||
log_info "Starting Nginx..."
|
||||
nginx -g "daemon off;" &
|
||||
sleep 3
|
||||
|
@ -165,6 +118,8 @@ check_nginx
|
|||
|
||||
echo -e "\n${GREEN}=== Marreta initialized ===${NC}\n"
|
||||
|
||||
# Aguarda qualquer processo terminar / Wait for any process to exit
|
||||
wait -n
|
||||
|
||||
# Sai com o status do processo que terminou primeiro / Exit with status of process that exited first
|
||||
exit $?
|
||||
|
|
Loading…
Add table
Reference in a new issue