Fixed managePDNS: select pdns.conf path according to OS; removed unnecessary /32; Move temp file to pdns.conf

This commit is contained in:
Mode
2021-03-14 07:35:12 +00:00
parent 79f1fe469b
commit ab835ae92e

View File

@@ -22,7 +22,11 @@ class ServiceManager:
def managePDNS(self): def managePDNS(self):
type = self.extraArgs['type'] type = self.extraArgs['type']
path = '/etc/pdns/pdns.conf'
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
path = '/etc/pdns/pdns.conf'
else:
path = '/etc/powerdns/pdns.conf'
data = ProcessUtilities.outputExecutioner('sudo cat ' + path).splitlines() data = ProcessUtilities.outputExecutioner('sudo cat ' + path).splitlines()
#data = subprocess.check_output(shlex.split('sudo cat ' + path)).decode("utf-8").splitlines() #data = subprocess.check_output(shlex.split('sudo cat ' + path)).decode("utf-8").splitlines()
@@ -35,8 +39,9 @@ class ServiceManager:
ipStringNoSubnet = '' ipStringNoSubnet = ''
for items in SlaveServers.objects.all(): for items in SlaveServers.objects.all():
ipsString = ipsString + '%s/32, ' % (items.slaveServerIP) if items.slaveServerIP:
ipStringNoSubnet = ipStringNoSubnet + '%s, ' % (items.slaveServerIP) ipsString = ipsString + '%s/32, ' % (items.slaveServerIP)
ipStringNoSubnet = ipStringNoSubnet + '%s, ' % (items.slaveServerIP)
ipsString = ipsString.rstrip(', ') ipsString = ipsString.rstrip(', ')
ipStringNoSubnet = ipStringNoSubnet.rstrip(', ') ipStringNoSubnet = ipStringNoSubnet.rstrip(', ')
@@ -74,6 +79,9 @@ class ServiceManager:
writeToFile.writelines('disable-axfr=no\n') writeToFile.writelines('disable-axfr=no\n')
writeToFile.writelines('master=yes\n') writeToFile.writelines('master=yes\n')
writeToFile.close() writeToFile.close()
command = 'sudo mv ' + tempPath + ' ' + path
ProcessUtilities.executioner(command)
else: else:
import os import os
@@ -110,18 +118,18 @@ class ServiceManager:
writeToFile.writelines(items + '\n') writeToFile.writelines(items + '\n')
slaveData = """ slaveData = """
slave=yes slave=yes
daemon=yes daemon=yes
disable-axfr=yes disable-axfr=yes
guardian=yes guardian=yes
local-address=0.0.0.0 local-address=0.0.0.0
local-port=53 local-port=53
master=no master=no
slave-cycle-interval=60 slave-cycle-interval=60
setgid=pdns setgid=pdns
setuid=pdns setuid=pdns
superslave=yes superslave=yes
""" """
writeToFile.writelines(slaveData) writeToFile.writelines(slaveData)
writeToFile.close() writeToFile.close()
@@ -146,14 +154,14 @@ superslave=yes
repoPath = '/etc/yum.repos.d/elasticsearch.repo' repoPath = '/etc/yum.repos.d/elasticsearch.repo'
content = '''[elasticsearch] content = '''[elasticsearch]
name=Elasticsearch repository for 7.x packages name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1 gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0 enabled=0
autorefresh=1 autorefresh=1
type=rpm-md type=rpm-md
''' '''
writeToFile = open(repoPath, 'w') writeToFile = open(repoPath, 'w')
writeToFile.write(content) writeToFile.write(content)
@@ -316,5 +324,4 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
main() main()