Skip to content

Commit 37717ca

Browse files
author
duanhongyi
committed
change sdns
1 parent 9182510 commit 37717ca

1 file changed

Lines changed: 19 additions & 17 deletions

File tree

bin/sdns.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import ippool, dnsserver
3232
from icmp import ping
3333

34+
3435
def loadconfig(path):
3536
if not isfile(path):
3637
print "[FATAL] can't find config file %s !" % path
@@ -116,6 +117,22 @@ def prepare_run(run_env):
116117
run_env['tcp'].append([f,ip])
117118
run_env['udp'].append([p,ip])
118119

120+
def sdns_write_pid(pid_file):
121+
pid = str(os.getpid())
122+
with open(pid_file, 'w') as f:
123+
f.write(pid)
124+
125+
126+
def sdns_kill_pid(pid_file):
127+
if not os.path.exists(pid_file): return
128+
try:
129+
with open(pid_file, 'r') as f:
130+
pid = int(f.read())
131+
a = os.kill(pid, signal.SIGKILL)
132+
print 'PID %s has been killed, return code:%s' % (pid, a)
133+
except OSError as e:
134+
logger.info(e)
135+
print 'PID was not discovered.'
119136

120137
# run it through twistd!
121138
if __name__ == '__main__':
@@ -124,27 +141,12 @@ def prepare_run(run_env):
124141
'..',
125142
'sdns.pid',
126143
)
127-
def write_pid():
128-
pid = str(os.getpid())
129-
with open(pid_file, 'w') as f:
130-
f.write(pid)
131-
def kill_pid():
132-
if not os.path.exists(pid_file): return
133-
try:
134-
with open(pid_file, 'r') as f:
135-
pid = int(f.read())
136-
a = os.kill(pid, signal.SIGKILL)
137-
print 'PID %s has been killed, return code:%s' % (pid, a)
138-
except OSError as e:
139-
logger.info(e)
140-
print 'PID was not discovered.'
141-
142-
kill_pid()
144+
sdns_kill_pid(pid_file)
143145
run_env = {'udp':[], 'tcp':[], 'closed':0, 'updated': False, 'finder':None}
144146
prepare_run(run_env)
145147
for e in run_env['tcp']:
146148
reactor.listenTCP(53, e[0], interface=e[1])
147149
for e in run_env['udp']:
148150
reactor.listenUDP(53, e[0], interface=e[1])
149-
write_pid()
151+
sdns_write_pid(pid_file)
150152
reactor.run()

0 commit comments

Comments
 (0)