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.

rndc reload as user?

Discussion in 'cPanel Developers' started by morissette, May 16, 2012.

  1. morissette

    morissette Well-Known Member

    Joined:
    May 24, 2009
    Messages:
    119
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Austin, TX
    cPanel Access Level:
    Root Administrator
    Is there an API call to reload rndc? I have a cpanel plugin im developing which modifies dns but it looks like named isn't being reloaded.
     
  2. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    Anything that edits DNS zones will restart named (add/remove sub/parked/addon domains, edit dns zones, etc). However, thos may not be useful unless you want to mess with the account. You could make your own api2 call that connects to dnsadmin by creating /usr/local/cpanel/Cpanel/DNSAPI.pm:

    Code:
    package Cpanel::DNSAPI;
    BEGIN{ push( @INC, '/usr/local/cpanel'); }
    
    use Cpanel::DnsUtils::AskDnsAdmin ();
    
    sub api2 {
        my $func = shift;
        my %API;
    
        $API{'reload'}{'func'} = 'api2_reload';
        $API{'reload'}{'engine'} = 'hasharray';
      
        return \%{ $API{$func} };
    }
    
    
    sub api2_reload{
      my %OPTS = @_;
    
      my $domain_to_reload = $OPTS{'domain'}; #sanitize this as you don't know what the code in dnsadmin looks like
    
      #original usage is below, my usage is not tested
      #my %RELOADLIST = shift;  
      #Cpanel::DnsUtils::AskDnsAdmin::askdnsadmin( 'RELOADZONES', 0, join( ',', keys %RELOADLIST ) );
    
      Cpanel::DnsUtils::AskDnsAdmin::askdnsadmin( 'RELOADZONES', 0, $domain_to_reload );
    }
    
    1;
    
    Now, I pulled the askdnsadmin function call from /usr/local/cpanel/Cpanel/DnsUtils.pm so you'll have to go through that module to see how the %RELOADLIST is built for what to send as the zones to reload but it should do the trick.

    You could then call it with:

    Code:
    https://domain.com:2083/xml-api/cpanel?cpanel_xmlapi_module=DNSAPI&cpanel_xmlapi_func=reload&cpanel_xmlapi_apiversion=2&domain=thedomain.tld




    Now, there's also a call for ZoneEdit::resetzone which will reload named but it likely will wipe out your changes: ZoneEdit Module Documentation


    You'll want to make sure you're using the ZoneEdit functions to edit the DNS zone or it will likely be rebuilt without your changes at some future point.
     
  3. morissette

    morissette Well-Known Member

    Joined:
    May 24, 2009
    Messages:
    119
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Austin, TX
    cPanel Access Level:
    Root Administrator
    Late reply but whatevs,

    So I am using cptt and the ZoneEdit functions in TT and rndc is not being reloaded. Any ideas?
     
  4. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator

    It's reloading fine on my test box:

    add_zone_record:

    Code:
    https://domain.com:2083/cpsessXXXXXXXXXX/xml-api/cpanel?cpanel_xmlapi_module=ZoneEdit&cpanel_xmlapi_func=add_zone_record&domain=domain.com&name=domain.com&type=TXT&txtdata=test
    
    output:

    Code:
    <cpanelresult>
    <apiversion>2</apiversion>
    <data>
    <name>result</name>
    <newserial>2012080201</newserial>
    <status>1</status>
    <statusmsg>
    Bind reloading on hostname using rndc zone: [domain.com]
    </statusmsg>
    </data>
    <event>
    <result>1</result>
    </event>
    <func>add_zone_record</func>
    <module>ZoneEdit</module>
    </cpanelresult>
    

    edit_zone_record:


    Code:
    https://domain.com:2083/cpsessXXXXXXXXXX/xml-api/cpanel?cpanel_xmlapi_module=ZoneEdit&cpanel_xmlapi_func=edit_zone_record&domain=domain.com&Line=31&type=TXT&txtdata=updated
    


    output:

    Code:
    <cpanelresult>
    <apiversion>2</apiversion>
    <data>
    <name>result</name>
    <newserial>2012080202</newserial>
    <status>1</status>
    <statusmsg>
    Bind reloading on hostname using rndc zone: [domain.com]
    </statusmsg>
    </data>
    <event>
    <result>1</result>
    </event>
    <func>edit_zone_record</func>
    <module>ZoneEdit</module>
    </cpanelresult>
    


    You should note that if you're doing this programmatically, you'll need to wait for the nameserver reload to complete which could take up to a minute. If you have another function immediately looking at the zone, it will fail as that's going to happen in milliseconds.
     

Share This Page