1.1 --- a/gmyth-stream/server/0.3/gms.py Mon Aug 13 22:29:00 2007 +0100
1.2 +++ b/gmyth-stream/server/0.3/gms.py Tue Aug 28 08:16:13 2007 +0100
1.3 @@ -5,12 +5,18 @@
1.4 __license__ = "GPL"
1.5 __version__ = "0.3"
1.6 __thanks__ = "Gustavo Sverzut Barbieri"
1.7 +__GMS_DATA_DIR__ = "/usr/share/gms/"
1.8
1.9 import sys
1.10 import os
1.11 import mimetypes
1.12 import logging as log
1.13 +
1.14 +if os.path.exists (__GMS_DATA_DIR__):
1.15 + sys.path.append(__GMS_DATA_DIR__)
1.16 +
1.17 from lib.server import serve_forever, load_plugins_transcoders
1.18 +from lib.utils import config
1.19
1.20 mimetypes.init()
1.21 log_level = log.INFO
1.22 @@ -23,9 +29,46 @@
1.23 "\t%(message)s"),
1.24 datefmt="%Y-%m-%d %H:%M:%S")
1.25
1.26 -if not os.path.exists(".transcoded"):
1.27 - os.mkdir(".transcoded")
1.28 +if config.get_transcoded_location () is None:
1.29 + print "Gms not configured"
1.30 + exit (0)
1.31
1.32 -pd = os.path.join("plugins", "transcoders")
1.33 -load_plugins_transcoders(pd)
1.34 +if not os.path.exists(config.get_transcoded_location()):
1.35 + os.mkdir(config.get_transcoded_location())
1.36 +
1.37 +
1.38 +if "-d" in sys.argv:
1.39 + #run with deamon
1.40 + try:
1.41 + pid = os.fork()
1.42 + if pid > 0:
1.43 + sys.exit(0)
1.44 + except OSError, e:
1.45 + print >>sys.stderr, "Fail to start deamon: %d (%s)" % (e.errno, e.strerror)
1.46 + sys.exit(1)
1.47 +
1.48 + os.chdir("/")
1.49 + os.setsid()
1.50 + os.umask(0)
1.51 +
1.52 + try:
1.53 + pid = os.fork()
1.54 + if pid > 0:
1.55 + fp = open ("/var/run/gms.pid", "w")
1.56 + fp.write ("%d" % pid)
1.57 + fp.close ()
1.58 + sys.exit(0)
1.59 + except OSError, e:
1.60 + print >>sys.stderr, "Fail to start deamon: %d (%s)" % (e.errno, e.strerror)
1.61 + sys.exit(1)
1.62 +
1.63 +# main deamon
1.64 +pd = os.path.join(__GMS_DATA_DIR__, "plugins", "transcoders")
1.65 +if os.path.exists (pd):
1.66 + load_plugins_transcoders(pd)
1.67 +
1.68 +pd = os.path.join("plugins", "transcoders");
1.69 +if os.path.exists (pd):
1.70 + load_plugins_transcoders(pd)
1.71 +
1.72 serve_forever()