BETA-457 - ajuste o install e congiruacao do host para cenários já instaldos
This commit is contained in:
124
install.sh
Normal file → Executable file
124
install.sh
Normal file → Executable file
@@ -26,6 +26,23 @@ BOLD='\033[1m'
|
||||
DIM='\033[2m'
|
||||
NC='\033[0m'
|
||||
|
||||
# ─── Sudo ─────────────────────────────────────────────────────
|
||||
SUDO=""
|
||||
[ "$EUID" -ne 0 ] && SUDO="sudo"
|
||||
|
||||
_SUDO_REQUESTED=false
|
||||
request_sudo() {
|
||||
[ "$_SUDO_REQUESTED" = "true" ] && return 0
|
||||
[ -z "$SUDO" ] && return 0
|
||||
echo ""
|
||||
print_warn "Esta etapa requer permissões de superusuário."
|
||||
if ! sudo -v; then
|
||||
print_error "Não foi possível obter permissões de superusuário."
|
||||
exit 1
|
||||
fi
|
||||
_SUDO_REQUESTED=true
|
||||
}
|
||||
|
||||
# ─── Repositório Git ──────────────────────────────────────────
|
||||
INSTALL_DIR="attendancesystem"
|
||||
BRANCH="${BRANCH:-release/V1.4}"
|
||||
@@ -139,6 +156,89 @@ check_deps() {
|
||||
print_ok "Todas as dependências OK"
|
||||
}
|
||||
|
||||
# ══════════════════════════════════════════════════════════════
|
||||
# Configurar limite de log do Docker
|
||||
# ══════════════════════════════════════════════════════════════
|
||||
|
||||
configure_docker_log_limit() {
|
||||
print_step "Configurando limite de log do Docker..."
|
||||
|
||||
local daemon_json="/etc/docker/daemon.json"
|
||||
|
||||
if [ -f "$daemon_json" ] && grep -q '"max-size"' "$daemon_json"; then
|
||||
print_ok "Limite de log já configurado em ${daemon_json}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
request_sudo
|
||||
|
||||
if [ -f "$daemon_json" ]; then
|
||||
$SUDO cp "$daemon_json" "${daemon_json}.bak"
|
||||
print_warn "Backup do daemon.json criado em ${daemon_json}.bak"
|
||||
fi
|
||||
|
||||
$SUDO mkdir -p "$(dirname "$daemon_json")"
|
||||
|
||||
$SUDO tee "$daemon_json" > /dev/null <<'EOF'
|
||||
{
|
||||
"log-driver": "json-file",
|
||||
"log-opts": {
|
||||
"max-size": "100m",
|
||||
"max-file": "5"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
print_ok "Limite de log configurado em ${daemon_json} (max-size: 100m, max-file: 5)"
|
||||
|
||||
if systemctl is-active --quiet docker; then
|
||||
$SUDO systemctl restart docker
|
||||
print_ok "Docker reiniciado para aplicar a configuração de log"
|
||||
fi
|
||||
}
|
||||
|
||||
# ══════════════════════════════════════════════════════════════
|
||||
# Garantir Docker como serviço systemd
|
||||
# ══════════════════════════════════════════════════════════════
|
||||
|
||||
ensure_docker_service() {
|
||||
print_step "Verificando serviço do Docker no systemd..."
|
||||
|
||||
if ! command -v systemctl &>/dev/null; then
|
||||
print_error "systemctl não encontrado. Este instalador requer systemd."
|
||||
exit 1
|
||||
fi
|
||||
print_ok "systemctl encontrado"
|
||||
|
||||
if systemctl is-active --quiet docker; then
|
||||
print_ok "Docker já está rodando como serviço systemd"
|
||||
return 0
|
||||
fi
|
||||
|
||||
print_warn "Docker não está ativo como serviço. Configurando..."
|
||||
|
||||
request_sudo
|
||||
|
||||
local override_dir="/etc/systemd/system/docker.service.d"
|
||||
$SUDO mkdir -p "$override_dir"
|
||||
$SUDO tee "$override_dir/restart-policy.conf" > /dev/null <<'EOF'
|
||||
[Service]
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
EOF
|
||||
|
||||
$SUDO systemctl daemon-reload
|
||||
$SUDO systemctl enable docker
|
||||
$SUDO systemctl start docker
|
||||
|
||||
if systemctl is-active --quiet docker; then
|
||||
print_ok "Docker habilitado e iniciado como serviço systemd"
|
||||
print_ok "Docker iniciará automaticamente com o SO e será reiniciado se cair"
|
||||
else
|
||||
print_error "Falha ao iniciar o serviço docker. Verifique com: journalctl -u docker"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# ══════════════════════════════════════════════════════════════
|
||||
# Clonar / atualizar repositório
|
||||
# ══════════════════════════════════════════════════════════════
|
||||
@@ -365,6 +465,27 @@ EOF
|
||||
print_ok ".env.prod gerado"
|
||||
}
|
||||
|
||||
# ══════════════════════════════════════════════════════════════
|
||||
# Garantir .env.observability
|
||||
# ══════════════════════════════════════════════════════════════
|
||||
|
||||
ensure_observability_env() {
|
||||
local env_file="${INSTALL_DIR}/.env.observability"
|
||||
|
||||
if [ -f "$env_file" ]; then
|
||||
print_ok ".env.observability já existe"
|
||||
return 0
|
||||
fi
|
||||
|
||||
cat > "$env_file" <<'EOF'
|
||||
SeventhLogs__CustomLevel__Warning__0=Microsoft.AspNetCore
|
||||
SeventhLogs__CustomLevel__Warning__1=Microsoft.AspNetCore.Hosting.Diagnostics
|
||||
SeventhLogs__CustomLevel__Warning__2=System.Net.Http.HttpClient.OtlpTraceExporter.ClientHandler
|
||||
SeventhLogs__CustomLevel__Warning__3=System.Net.Http.HttpClient.OtlpTraceExporter.LogicalHandler
|
||||
EOF
|
||||
print_ok ".env.observability criado"
|
||||
}
|
||||
|
||||
# ══════════════════════════════════════════════════════════════
|
||||
# Subir ambiente
|
||||
# ══════════════════════════════════════════════════════════════
|
||||
@@ -398,12 +519,15 @@ start_environment() {
|
||||
main() {
|
||||
print_banner
|
||||
check_deps
|
||||
ensure_docker_service
|
||||
configure_docker_log_limit
|
||||
clone_repo
|
||||
load_existing_env # detecta .env.prod existente
|
||||
collect_config # wizard com navegação
|
||||
show_summary # resumo com menu de edição
|
||||
|
||||
generate_envs
|
||||
ensure_observability_env
|
||||
|
||||
if confirm "Deseja subir o ambiente agora?"; then
|
||||
start_environment
|
||||
|
||||
Reference in New Issue
Block a user