change technic to detect running liquidsoap instance

This commit is contained in:
bkfox 2017-01-11 09:39:55 +01:00
parent 68d7e9b49e
commit ddeb1f692e
2 changed files with 10 additions and 17 deletions

View File

@ -141,21 +141,17 @@ class Streamer:
""" """
Check if there is a process that has not been killed Check if there is a process that has not been killed
""" """
# TODO: this method does not work in case the working if not os.path.exists(self.socket_path):
# directory has been erased then regenerated
if not os.path.exists(self.path + ".pid"):
return return
with open(self.path + ".pid") as file: import psutil
pid = file.read() conns = [
os.kill(int(pid), signal.SIGKILL) conn for conn in psutil.net_connections(kind='unix')
if conn.laddr == self.socket_path
def __prevent_zombie(self): ]
""" for conn in conns:
Write process pid if conn.pid is not None:
""" os.kill(conn.pid, signal.SIGKILL)
with open(self.path + ".pid", "w") as file:
file.write(str(self.process.pid))
def process_run(self): def process_run(self):
""" """
@ -174,7 +170,6 @@ class Streamer:
self.__check_for_zombie() self.__check_for_zombie()
self.process = subprocess.Popen(args, stderr=subprocess.STDOUT) self.process = subprocess.Popen(args, stderr=subprocess.STDOUT)
self.__prevent_zombie()
atexit.register(lambda: self.process_terminate()) atexit.register(lambda: self.process_terminate())
def process_terminate(self): def process_terminate(self):
@ -186,9 +181,6 @@ class Streamer:
self.process.kill() self.process.kill()
self.process = None self.process = None
# the zombie has been killed
os.remove(self.path + ".pid")
def process_wait(self): def process_wait(self):
""" """
Wait for the process to terminate if there is a process Wait for the process to terminate if there is a process

View File

@ -3,6 +3,7 @@ Django>=1.10.3
django-taggit>=0.18.3 django-taggit>=0.18.3
mutagen==1.35.1 mutagen==1.35.1
watchdog>=0.8.3 watchdog>=0.8.3
psutil>=5.0.1
dateutils>=0.6.6 dateutils>=0.6.6
bleach>=1.4.3 bleach>=1.4.3
django-htmlmin>=0.10.0 django-htmlmin>=0.10.0