Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Removing an Addon domain with commands / ssh / script

Discussion in 'cPanel Developers' started by jonahnaylor, Jun 18, 2016.

Tags:
  1. jonahnaylor

    jonahnaylor Registered

    Joined:
    Jul 25, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    51
    Hi hopefully someone can help. I'm writing a script to remove an addon domain but so far it's not getting rid of it...

    Currently I've just tried to use the safer cpanel scripts and a few commands to achieve this but I'm hoping some can fill in the gaps as to what I'm missing so that when I navigate back into that account after running the script the domain is no longer there under the Addon Domains section. Any help appreciated, here is what I have so far:

    Code:
    set -x                                                                  # Turns tracing on so we can see what is happening
    ex +g/$addonDOMAIN/d' -cwq /var/cpanel/users/$cpanelACC                 # Remove all lines containing addon domain in users file
    ex +g/$addonDOMAIN/d' -cwq /var/cpanel/userdata/$cpanelACC/main         # Remove all lines containing addon domain in userdata file
    
    /usr/local/cpanel/scripts/killdns $addonDOMAIN                          # Remove Addon Domain from BIND
    /usr/local/cpanel/scripts/killvhost $addonDOMAIN                        # Remove Addon Domain http entries
    /usr/local/cpanel/scripts/rebuildhttpdconf                              # Rebuild Apache Configuration
    set +x                                                                  # Turns tracing off again
    
    APACHE_CONFIG=$(/usr/local/apache/bin/apachectl configtest 2>&1)        # Check condition of Apache with a test
    
    if [[ $APACHE_CONFIG =~ "Syntax OK" ]]; then
        echo "Apache config is ok. Restarting Apache."
    
        RESTART_APACHE=$(/usr/local/cpanel/scripts/restartsrv httpd)
    
        if [[ $RESTART_APACHE =~ "Apache successfully restarted" ]]; then
            echo "Apache restarted successfully"
        else
            echo "Apache restart failed: $RESTART_APACHE"
        fi
    else
        echo "Apache config problem. Will not restart apache: $APACHE_CONFIG"
    fi
    
     
  2. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,384
    Likes Received:
    1,951
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

    It looks like you are attempting to manipulate configuration files through the script. I suggest using cPanel API 2 instead. Here's a cPanel API 2 function you can use:

    cPanel API 2 Functions - AddonDomain::deladdondomain - Software Development Kit - cPanel Documentation

    You may also find this document helpful:

    Guide to cPanel API 2 - Software Development Kit - cPanel Documentation

    Note that cPanel UAPI is recommended over cPanel API 2, however no equivalent UAPI function exists at this time.

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice