diff -r 2b1824e138b1 -r 411a01dfcd21 gmyth-stream/server/0.3/gms.py --- a/gmyth-stream/server/0.3/gms.py Mon Aug 13 22:29:00 2007 +0100 +++ b/gmyth-stream/server/0.3/gms.py Wed Aug 22 14:57:53 2007 +0100 @@ -5,12 +5,18 @@ __license__ = "GPL" __version__ = "0.3" __thanks__ = "Gustavo Sverzut Barbieri" +__GMS_DATA_DIR__ = "/usr/share/gms/" import sys import os import mimetypes import logging as log + +if os.path.exists (__GMS_DATA_DIR__): + sys.path.append(__GMS_DATA_DIR__) + from lib.server import serve_forever, load_plugins_transcoders +from lib.utils import config mimetypes.init() log_level = log.INFO @@ -23,9 +29,46 @@ "\t%(message)s"), datefmt="%Y-%m-%d %H:%M:%S") -if not os.path.exists(".transcoded"): - os.mkdir(".transcoded") +if config.get_transcoded_location () is None: + print "Gms not configured" + exit (0) -pd = os.path.join("plugins", "transcoders") -load_plugins_transcoders(pd) +if not os.path.exists(config.get_transcoded_location()): + os.mkdir(config.get_transcoded_location()) + + +if "-d" in sys.argv: + #run with deamon + try: + pid = os.fork() + if pid > 0: + sys.exit(0) + except OSError, e: + print >>sys.stderr, "Fail to start deamon: %d (%s)" % (e.errno, e.strerror) + sys.exit(1) + + os.chdir("/") + os.setsid() + os.umask(0) + + try: + pid = os.fork() + if pid > 0: + fp = open ("/var/run/gms.pid", "w") + fp.write ("%d" % pid) + fp.close () + sys.exit(0) + except OSError, e: + print >>sys.stderr, "Fail to start deamon: %d (%s)" % (e.errno, e.strerror) + sys.exit(1) + +# main deamon +pd = os.path.join(__GMS_DATA_DIR__, "plugins", "transcoders") +if os.path.exists (pd): + load_plugins_transcoders(pd) + +pd = os.path.join("plugins", "transcoders"); +if os.path.exists (pd): + load_plugins_transcoders(pd) + serve_forever()