Fix bash and jps

main
Anthony 2025-03-22 01:51:15 +08:00
parent b0bea6f2ee
commit 9615073df2
2 changed files with 50 additions and 27 deletions

View File

@ -587,7 +587,15 @@ actions:
- cmd[cp]: - cmd[cp]:
user: root user: root
commands: commands:
- bash /home/litespeed/mbmanager/ssl-manager/ssl_manager.sh --domain="${settings.domain}" --remove-cert=yes --confirm=yes - |
OUTPUT=$(bash /home/litespeed/mbmanager/ssl-manager/ssl_manager.sh --domain="${settings.domain}" --remove-cert=yes --confirm=yes 2>&1)
echo "$OUTPUT"
# Check if certificate was actually removed regardless of script exit code
if echo "$OUTPUT" | grep -q "Certificate for.*successfully revoked and removed"; then
exit 0
else
exit 1
fi
- if: ${response.exitcode} == 0 - if: ${response.exitcode} == 0
return: return:

View File

@ -764,15 +764,12 @@ remove_ssl_certificate() {
return 1 return 1
fi fi
# Remove the HTTPS-domain listener section - find both <name> and <n> tags to handle inconsistencies # Remove the HTTPS-domain listener section
grep -n -E "<(name|n)>HTTPS-${domain}</(name|n)>" "$config_file" > /dev/null || { local domain_pattern="HTTPS-${domain}"
log "No listener found for domain ${domain}, continuing with certificate removal only."; awk -v domain="$domain" -v pattern="$domain_pattern" '
}
awk -v domain="$domain" '
BEGIN { skip = 0; } BEGIN { skip = 0; }
/HTTPS-'"$domain"'/,/<\/listener>/ { $0 ~ pattern,/<\/listener>/ {
if ($0 ~ /HTTPS-'"$domain"'/) { if ($0 ~ pattern) {
skip = 1; skip = 1;
print "<!-- Listener for " domain " removed by ssl_manager.sh -->"; print "<!-- Listener for " domain " removed by ssl_manager.sh -->";
} }
@ -789,17 +786,14 @@ remove_ssl_certificate() {
log "Removing domain-specific virtual host if it exists..." log "Removing domain-specific virtual host if it exists..."
local vhost_name="${domain//[.]/_}" local vhost_name="${domain//[.]/_}"
# Check if virtualhost exists # Check if virtualhost exists (safer approach)
grep -n -E "<(name|n)>${vhost_name}</(name|n)>" "$config_file" > /dev/null || { if grep -q "$vhost_name" "$config_file"; then
log "No virtual host found for ${vhost_name}, skipping this step."; # Process only if virtual host might exist
cp "$temp_file" "${temp_file}.new"; local vhost_pattern="$vhost_name"
} awk -v vhost="$vhost_name" -v pattern="$vhost_pattern" '
if [ ! -f "${temp_file}.new" ]; then
awk -v vhost="$vhost_name" '
BEGIN { skip = 0; } BEGIN { skip = 0; }
/'"$vhost"'/,/<\/virtualHost>/ { $0 ~ pattern,/<\/virtualHost>/ {
if ($0 ~ /'"$vhost"'/) { if ($0 ~ pattern) {
skip = 1; skip = 1;
print "<!-- VirtualHost for " vhost " removed by ssl_manager.sh -->"; print "<!-- VirtualHost for " vhost " removed by ssl_manager.sh -->";
} }
@ -811,6 +805,9 @@ remove_ssl_certificate() {
} }
{ if (!skip) print; } { if (!skip) print; }
' "$temp_file" > "${temp_file}.new" ' "$temp_file" > "${temp_file}.new"
else
log "No virtual host found for ${vhost_name}, skipping this step.";
cp "$temp_file" "${temp_file}.new"
fi fi
# 4. Remove any domain mappings from shared listeners # 4. Remove any domain mappings from shared listeners
@ -899,18 +896,36 @@ remove_ssl_certificate() {
# 8. Clean up LiteSpeed logs for this domain # 8. Clean up LiteSpeed logs for this domain
log "Cleaning up log files for $domain..." log "Cleaning up log files for $domain..."
find /var/log/lsws/ -name "*$domain*" -type f -delete if [ -d "/var/log/lsws/" ]; then
find /var/log/lsws/ -name "*$domain*" -type f -delete 2>/dev/null || true
else
log "LiteSpeed log directory '/var/log/lsws/' not found, skipping log cleanup."
fi
# 9. Clean related cache files # 9. Clean related cache files
log "Cleaning related cache files..." log "Cleaning related cache files..."
find /var/www/webroot/ROOT/.well-known/acme-challenge/ -type f -delete 2>/dev/null if [ -d "/var/www/webroot/ROOT/.well-known/acme-challenge/" ]; then
find /var/www/webroot/ROOT/.well-known/acme-challenge/ -type f -delete 2>/dev/null || true
# 10. Restart LiteSpeed to apply configuration changes
if restart_litespeed; then
log "LiteSpeed restarted successfully after certificate removal."
else else
log "ERROR: Failed to restart LiteSpeed after certificate removal." log "ACME challenge directory not found, skipping cache cleanup."
return 1 fi
# 10. Restart LiteSpeed only if it's running and configuration was changed
local config_changed=false
if grep -q "removed by ssl_manager.sh" "$config_file"; then
config_changed=true
fi
if $config_changed; then
log "Configuration changes detected. Restarting LiteSpeed to apply changes..."
if restart_litespeed; then
log "LiteSpeed restarted successfully after certificate removal."
else
log "WARNING: Failed to restart LiteSpeed after certificate removal. Manual restart may be required."
# Don't return error, continue with the successful certificate removal
fi
else
log "No configuration changes detected. Skipping LiteSpeed restart."
fi fi
# 11. Send email notification if configured # 11. Send email notification if configured