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
"""
# TODO: this method does not work in case the working
# directory has been erased then regenerated
if not os.path.exists(self.path + ".pid"):
if not os.path.exists(self.socket_path):
return
with open(self.path + ".pid") as file:
pid = file.read()
os.kill(int(pid), signal.SIGKILL)
def __prevent_zombie(self):
"""
Write process pid
"""
with open(self.path + ".pid", "w") as file:
file.write(str(self.process.pid))
import psutil
conns = [
conn for conn in psutil.net_connections(kind='unix')
if conn.laddr == self.socket_path
]
for conn in conns:
if conn.pid is not None:
os.kill(conn.pid, signal.SIGKILL)
def process_run(self):
"""
@ -174,7 +170,6 @@ class Streamer:
self.__check_for_zombie()
self.process = subprocess.Popen(args, stderr=subprocess.STDOUT)
self.__prevent_zombie()
atexit.register(lambda: self.process_terminate())
def process_terminate(self):
@ -186,9 +181,6 @@ class Streamer:
self.process.kill()
self.process = None
# the zombie has been killed
os.remove(self.path + ".pid")
def process_wait(self):
"""
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
mutagen==1.35.1
watchdog>=0.8.3
psutil>=5.0.1
dateutils>=0.6.6
bleach>=1.4.3
django-htmlmin>=0.10.0