[vlma-devel] commit: Ensure that ports are not in use before running VLC and the web interface. (Adrien Grand )

git version control git at videolan.org
Fri Mar 20 04:25:45 CET 2009


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Fri Mar 20 04:25:02 2009 +0100| [1fd4c433e28002a10cb9713b3850f4c677b4b305] | committer: Adrien Grand 

Ensure that ports are not in use before running VLC and the web interface.

> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=1fd4c433e28002a10cb9713b3850f4c677b4b305
---

 vlma-watchdog/src/conf.py |    5 +++--
 vlma-watchdog/src/vlc.py  |   24 +++++++++++++++++++++++-
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/vlma-watchdog/src/conf.py b/vlma-watchdog/src/conf.py
index 9abf317..0d41811 100644
--- a/vlma-watchdog/src/conf.py
+++ b/vlma-watchdog/src/conf.py
@@ -6,13 +6,14 @@ LOG_LEVEL = 20
 # Name of the VLC executable (give the full path if vlc is not
 # available in the PATH environment variable)
 VLC_EXE = "vlc"
+VLC_TELNET_PORT = 4212
 def get_VLC_ARGS(version):
   if version.find(" 0.8.") >= 0:
     # VLC 0.8.x
-    return "-vvv --rtsp-host 0.0.0.0:5554 --intf telnet"
+    return "-vvv --rtsp-host 0.0.0.0:5554 --intf telnet --telnet-port %d" %VLC_TELNET_PORT
   else:
     # VLC 0.9 and higher
-    return "-vvv --ignore-config --rtsp-host 0.0.0.0:5554 --intf lua --lua-intf telnet"
+    return "-vvv --ignore-config --rtsp-host 0.0.0.0:5554 --intf lua --lua-intf telnet --lua-config \"telnet={hosts={'*:%d'}}\"" %VLC_TELNET_PORT
 
 CPU_LOAD_THRESHOLD = 6.0
 VLC_CPU_THRESHOLD  = 80.0
diff --git a/vlma-watchdog/src/vlc.py b/vlma-watchdog/src/vlc.py
index 0490007..5c9be64 100644
--- a/vlma-watchdog/src/vlc.py
+++ b/vlma-watchdog/src/vlc.py
@@ -7,7 +7,7 @@
 
 # Imports
 
-import logging, math, os, signal, sys, threading, time, conf, web, subprocess
+import logging, math, os, signal, sys, threading, time, conf, web, socket, subprocess
 
 global vlcInstance
 
@@ -308,6 +308,20 @@ def signalHandler(signum, frame):
   vlcInstance.stop()
   sys.exit(0)
 
+def check_port(port):
+  """Check whether the provided port is available"""
+  s = socket.socket()
+  s.settimeout(0.5)
+  result = False
+  try:
+    s.connect(("localhost", port))
+  except:
+    result = True
+  finally:
+    s.close()
+  return result
+
+
 if __name__ == '__main__':
   # Init logging
   logger = logging.getLogger('')
@@ -319,6 +333,14 @@ if __name__ == '__main__':
   signal.signal(signal.SIGHUP, signalHandler)
   signal.signal(signal.SIGTERM, signalHandler)
   signal.signal(signal.SIGQUIT, signalHandler)
+  # Check that ports are not in use
+  msg = "Cannot listen on port %d (%s), port is already in use"
+  if not check_port(conf.VLC_TELNET_PORT):
+    logger.error(msg, conf.VLC_TELNET_PORT, "VLC telnet port")
+    sys.exit(1)
+  if not check_port(conf.SERVER_PORT):
+    logger.error(msg, conf.SERVER_PORT, "Watchdog HTTP interface")
+    sys.exit(1)
   # Start VLC
   vlcInstance = VLC()
   monitor = Monitor(vlcInstance)



More information about the vlma-devel mailing list