Skip to content

Commit 77ebe26

Browse files
committed
fix: handle SSH service restart gracefully in different environments (fixes #2)
- Check both sshd and ssh service names - Suppress error output to avoid confusing users - Show warning instead of success when restart fails - Provide manual restart instructions for WSL2/container environments - Resolves issue where script showed error and success messages - Fixes #2
1 parent 44f44d8 commit 77ebe26

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

erp-server-setup.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,14 @@ EOF
256256

257257
# Validar configuração
258258
if sshd -t 2>/dev/null; then
259-
systemctl restart sshd || systemctl restart ssh
260-
print_message success "SSH configurado com sucesso na porta ${ssh_port}"
259+
# Tentar reiniciar SSH (compatível com diferentes ambientes)
260+
if systemctl restart sshd 2>/dev/null || systemctl restart ssh 2>/dev/null; then
261+
print_message success "SSH configurado com sucesso na porta ${ssh_port}"
262+
else
263+
# Em alguns ambientes (WSL2, containers), o serviço pode não estar disponível
264+
print_message warning "SSH configurado, mas não foi possível reiniciar o serviço (pode estar desabilitado)"
265+
print_message info "Reinicie manualmente ou aguarde o próximo boot: sudo systemctl restart ssh"
266+
fi
261267
else
262268
print_message error "Erro na configuração SSH. Restaurando backup..."
263269
cp "${BACKUP_DIR}/sshd_config.backup-"* /etc/ssh/sshd_config 2>/dev/null || true

0 commit comments

Comments
 (0)