1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-30 18:50:58 +00:00

Notify users if x11vnc process has crashed. Fix #1401.

This commit is contained in:
grossmj 2018-10-06 21:30:39 +08:00
parent 22f7ca0243
commit 97c68f56bf

View File

@ -82,12 +82,14 @@ class DockerVM(BaseNode):
self._ethernet_adapters = [] self._ethernet_adapters = []
self._temporary_directory = None self._temporary_directory = None
self._telnet_servers = [] self._telnet_servers = []
self._xvfb_process = None
self._x11vnc_process = None self._x11vnc_process = None
self._console_resolution = console_resolution self._console_resolution = console_resolution
self._console_http_path = console_http_path self._console_http_path = console_http_path
self._console_http_port = console_http_port self._console_http_port = console_http_port
self._console_websocket = None self._console_websocket = None
self._extra_hosts = extra_hosts self._extra_hosts = extra_hosts
self._closing = False
self._volumes = [] self._volumes = []
# Keep a list of created bridge # Keep a list of created bridge
@ -425,6 +427,11 @@ class DockerVM(BaseNode):
elif state == "running": elif state == "running":
return return
else: else:
if self._console_type == "vnc" and not self._x11vnc_process:
# start the x11vnc process in case it had previously crashed
self._x11vnc_process = yield from asyncio.create_subprocess_exec("x11vnc", "-forever", "-nopw", "-shared", "-geometry", self._console_resolution, "-display", "WAIT:{}".format(self._display), "-rfbport", str(self.console), "-rfbportv6", str(self.console), "-noncache", "-listen", self._manager.port_manager.console_host)
yield from self._clean_servers() yield from self._clean_servers()
yield from self.manager.query("POST", "containers/{}/start".format(self._cid)) yield from self.manager.query("POST", "containers/{}/start".format(self._cid))
@ -532,22 +539,11 @@ class DockerVM(BaseNode):
self._xvfb_process = yield from asyncio.create_subprocess_exec("Xvfb", "-nolisten", "tcp", ":{}".format(self._display), "-screen", "0", self._console_resolution + "x16") self._xvfb_process = yield from asyncio.create_subprocess_exec("Xvfb", "-nolisten", "tcp", ":{}".format(self._display), "-screen", "0", self._console_resolution + "x16")
# We pass a port for TCPV6 due to a crash in X11VNC if not here: https://github.com/GNS3/gns3-server/issues/569 # We pass a port for TCPV6 due to a crash in X11VNC if not here: https://github.com/GNS3/gns3-server/issues/569
self._x11vnc_process = yield from asyncio.create_subprocess_exec("x11vnc", "-forever", "-nopw", "-shared", "-geometry", self._console_resolution, "-display", "WAIT:{}".format(self._display), "-rfbport", str(self.console), "-rfbportv6", str(self.console), "-noncache", "-listen", self._manager.port_manager.console_host) self._x11vnc_process = yield from asyncio.create_subprocess_exec("x11vnc", "-forever", "-nopw", "-shared", "-geometry", self._console_resolution, "-display", "WAIT:{}".format(self._display), "-rfbport", str(self.console), "-rfbportv6", str(self.console), "-noncache", "-listen", self._manager.port_manager.console_host)
x11_socket = os.path.join("/tmp/.X11-unix/", "X{}".format(self._display)) x11_socket = os.path.join("/tmp/.X11-unix/", "X{}".format(self._display))
yield from wait_for_file_creation(x11_socket) yield from wait_for_file_creation(x11_socket)
#monitor_process(self._xvfb_process, self._xvfb_callback) # sometimes the x11vnc process can crash
#monitor_process(self._x11vnc_process, self._x11vnc_callback) monitor_process(self._x11vnc_process, self._x11vnc_callback)
def _xvfb_callback(self, returncode):
"""
Called when the process has stopped.
:param returncode: Process returncode
"""
if returncode != 0:
self.project.emit("log.error", {"message": "The Xvfb process has stopped, return code: {}.".format(returncode)})
def _x11vnc_callback(self, returncode): def _x11vnc_callback(self, returncode):
""" """
@ -556,8 +552,9 @@ class DockerVM(BaseNode):
:param returncode: Process returncode :param returncode: Process returncode
""" """
if returncode != 0: if returncode != 0 and self._closing is False:
self.project.emit("log.error", {"message": "The x11vnc process has stopped, return code: {}.".format(returncode)}) self.project.emit("log.error", {"message": "The x11vnc process has stopped with return code {} for node '{}'. Please restart this node.".format(returncode, self.name)})
self._x11vnc_process = None
@asyncio.coroutine @asyncio.coroutine
def _start_http(self): def _start_http(self):
@ -740,6 +737,7 @@ class DockerVM(BaseNode):
Closes this Docker container. Closes this Docker container.
""" """
self._closing = True
if not (yield from super().close()): if not (yield from super().close()):
return False return False
yield from self.reset() yield from self.reset()
@ -751,6 +749,7 @@ class DockerVM(BaseNode):
state = yield from self._get_container_state() state = yield from self._get_container_state()
if state == "paused" or state == "running": if state == "paused" or state == "running":
yield from self.stop() yield from self.stop()
if self.console_type == "vnc": if self.console_type == "vnc":
if self._x11vnc_process: if self._x11vnc_process:
try: try:
@ -758,11 +757,22 @@ class DockerVM(BaseNode):
yield from self._x11vnc_process.wait() yield from self._x11vnc_process.wait()
except ProcessLookupError: except ProcessLookupError:
pass pass
self._x11vnc_process = None
if self._xvfb_process:
try: try:
self._xvfb_process.terminate() self._xvfb_process.terminate()
yield from self._xvfb_process.wait() yield from self._xvfb_process.wait()
except ProcessLookupError: except ProcessLookupError:
pass pass
self._xvfb_process = None
display = "/tmp/.X11-unix/X{}".format(self._display)
try:
if os.path.exists(display):
os.remove(display)
except OSError as e:
log.warning("Could not remove display {}: {}".format(display, e))
# v 1/True/true or 0/False/false, Remove the volumes associated to the container. Default false. # v 1/True/true or 0/False/false, Remove the volumes associated to the container. Default false.
# force - 1/True/true or 0/False/false, Kill then remove the container. Default false. # force - 1/True/true or 0/False/false, Kill then remove the container. Default false.
try: try: