The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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:
    1
    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 Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    675
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
Loading...

Share This Page