Fix bash and jps
parent
b0bea6f2ee
commit
9615073df2
10
mbadmin.jps
10
mbadmin.jps
|
@ -587,7 +587,15 @@ actions:
|
|||
- cmd[cp]:
|
||||
user: root
|
||||
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
|
||||
return:
|
||||
|
|
|
@ -764,15 +764,12 @@ remove_ssl_certificate() {
|
|||
return 1
|
||||
fi
|
||||
|
||||
# Remove the HTTPS-domain listener section - find both <name> and <n> tags to handle inconsistencies
|
||||
grep -n -E "<(name|n)>HTTPS-${domain}</(name|n)>" "$config_file" > /dev/null || {
|
||||
log "No listener found for domain ${domain}, continuing with certificate removal only.";
|
||||
}
|
||||
|
||||
awk -v domain="$domain" '
|
||||
# Remove the HTTPS-domain listener section
|
||||
local domain_pattern="HTTPS-${domain}"
|
||||
awk -v domain="$domain" -v pattern="$domain_pattern" '
|
||||
BEGIN { skip = 0; }
|
||||
/HTTPS-'"$domain"'/,/<\/listener>/ {
|
||||
if ($0 ~ /HTTPS-'"$domain"'/) {
|
||||
$0 ~ pattern,/<\/listener>/ {
|
||||
if ($0 ~ pattern) {
|
||||
skip = 1;
|
||||
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..."
|
||||
local vhost_name="${domain//[.]/_}"
|
||||
|
||||
# Check if virtualhost exists
|
||||
grep -n -E "<(name|n)>${vhost_name}</(name|n)>" "$config_file" > /dev/null || {
|
||||
log "No virtual host found for ${vhost_name}, skipping this step.";
|
||||
cp "$temp_file" "${temp_file}.new";
|
||||
}
|
||||
|
||||
if [ ! -f "${temp_file}.new" ]; then
|
||||
awk -v vhost="$vhost_name" '
|
||||
# Check if virtualhost exists (safer approach)
|
||||
if grep -q "$vhost_name" "$config_file"; then
|
||||
# Process only if virtual host might exist
|
||||
local vhost_pattern="$vhost_name"
|
||||
awk -v vhost="$vhost_name" -v pattern="$vhost_pattern" '
|
||||
BEGIN { skip = 0; }
|
||||
/'"$vhost"'/,/<\/virtualHost>/ {
|
||||
if ($0 ~ /'"$vhost"'/) {
|
||||
$0 ~ pattern,/<\/virtualHost>/ {
|
||||
if ($0 ~ pattern) {
|
||||
skip = 1;
|
||||
print "<!-- VirtualHost for " vhost " removed by ssl_manager.sh -->";
|
||||
}
|
||||
|
@ -811,6 +805,9 @@ remove_ssl_certificate() {
|
|||
}
|
||||
{ if (!skip) print; }
|
||||
' "$temp_file" > "${temp_file}.new"
|
||||
else
|
||||
log "No virtual host found for ${vhost_name}, skipping this step.";
|
||||
cp "$temp_file" "${temp_file}.new"
|
||||
fi
|
||||
|
||||
# 4. Remove any domain mappings from shared listeners
|
||||
|
@ -899,18 +896,36 @@ remove_ssl_certificate() {
|
|||
|
||||
# 8. Clean up LiteSpeed logs for this 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
|
||||
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
|
||||
else
|
||||
log "ACME challenge directory not found, skipping cache cleanup."
|
||||
fi
|
||||
|
||||
# 10. Restart LiteSpeed to apply configuration changes
|
||||
# 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 "ERROR: Failed to restart LiteSpeed after certificate removal."
|
||||
return 1
|
||||
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
|
||||
|
||||
# 11. Send email notification if configured
|
||||
|
|
Loading…
Reference in New Issue