def stopThreads(): global __INITIALIZED__ with INIT_LOCK: if __INITIALIZED__: logger.log(u'Stopping scrobbee threads', 'Shutdown') # Stop the threads. __INITIALIZED__ = False
def main(): """ Runs Scrobbee """ scrobbee.PROG_DIR = os.path.dirname(os.path.abspath(__file__)) scrobbee.DATA_DIR = scrobbee.PROG_DIR scrobbee.CONFIG_SPEC = os.path.join(scrobbee.PROG_DIR, "configspec.ini") threading.currentThread().name = "MAIN" parser = argparse.ArgumentParser(description="Scrobble what's playing on the Boxee Box.") parser.add_argument('-q', '--quiet', action='store_true', dest="QUIET", help="disables console output and quiets Scrobbee") parser.add_argument('--nolaunch', action='store_true', dest="NOLAUNCH", help="makes sure the browser doesn't launch on startup") parser.add_argument('-p', '--port', dest="PORT", type=int, help="defines the port on which Scrobbee will run") parser.add_argument('-d', '--daemon', dest="DAEMON", help="daemonizes Scrobbee so it keeps running in the background until close explicitly") parser.add_argument('--datadir', dest="DATADIR", type=os.path.abspath, help="determins the location where the Scrobbee data (config file, database, PID file ...) is stored") parser.add_argument('--config', dest="CONFIG_FILE", type=os.path.abspath, help="determines the location of the config file. Can be a filename or a directory. In the latter case, the config file will be named config.ini") parser.add_argument('--pidfile', dest="PIDFILE", type=os.path.abspath, help="determines the location of the PID file") args = parser.parse_args(namespace=scrobbee) # Check the arguments if (scrobbee.DAEMON): if (sys.platform == "win32"): print "Daemonize not supported under Windows, starting normally" scrobbee.DAEMON = False else: scrobbee.QUIET = True if not scrobbee.PIDFILE is None: # if the pidfile already exists, sickbeard may still be running, so exit if os.path.exists(scrobbee.PIDFILE): sys.exit("PID file " + scrobbee.PIDFILE + " already exists. Exiting.") if scrobbee.DAEMON: try: file(scrobbee.PIDFILE, 'w').write("pid\n") #Move this together with the other file checking except IOError, e: raise SystemExit("Unable to write PID file: %s [%d]" % (e.strerror, e.errno)) else: scrobbee.PIDFILE = None logger.log(u"Not running in daemon mode. PID file creation disabled.")
# Make the child a session-leader by detaching from the terminal try: pid = os.fork() if pid != 0: sys.exit(0) except OSError, e: raise RuntimeError("2st fork failed: %s [%d]" % (e.strerror, e.errno)) dev_null = file('/dev/null', 'r') os.dup2(dev_null.fileno(), sys.stdin.fileno()) if scrobbee.CREATEPID: pid = str(os.getpid()) logger.log(u"Writing PID " + pid + " to " + str(scrobbee.PIDFILE)) file(scrobbee.PIDFILE, 'w').write("%s\n" % pid) def main(): """ Runs Scrobbee """ scrobbee.PROG_DIR = os.path.dirname(os.path.abspath(__file__)) scrobbee.DATA_DIR = scrobbee.PROG_DIR scrobbee.CONFIG_SPEC = os.path.join(scrobbee.PROG_DIR, "configspec.ini") threading.currentThread().name = "MAIN" parser = argparse.ArgumentParser(description="Scrobble what's playing on the Boxee Box.") parser.add_argument('-q', '--quiet', action='store_true', dest="QUIET", help="disables console output and quiets Scrobbee") parser.add_argument('--nolaunch', action='store_true', dest="NOLAUNCH", help="makes sure the browser doesn't launch on startup") parser.add_argument('-p', '--port', dest="PORT", type=int, help="defines the port on which Scrobbee will run")