Esempio n. 1
0
    def _listen(self, task_id):
        # task_ids start at zero, so we gobble up ports starting at the base port and work up
        port_no = int(config.get("api_base_port")) + task_id

        # Log according to configured directory and port # we're operating on
        log_file = "%s/rw_api_%s.log" % (config.get("api_log_dir"), port_no)
        if config.test_mode and os.path.exists(log_file):
            os.remove(log_file)
        log.init(log_file, config.get("log_level"))
        log.debug("start", "Server booting, port %s." % port_no)
        db.open()
        cache.open()

        for sid in config.station_ids:
            cache.update_local_cache_for_sid(sid)

        # If we're not in developer, remove development-related URLs
        if not config.get("developer_mode"):
            i = 0
            while (i < len(request_classes)):
                if request_classes[i][0].find("/test/") != -1:
                    request_classes.pop(i)
                    i = i - 1
                i = i + 1

        # Make sure all other errors get handled in an API-friendly way
        request_classes.append((r".*", api.web.Error404Handler))

        # Initialize the help (rather than it scan all URL handlers every time someone hits it)
        api.help.sectionize_requests()

        # Initialize playlist variables
        playlist.prepare_cooldown_algorithm(sid)

        # Fire ze missiles!
        app = tornado.web.Application(
            request_classes,
            debug=(config.test_mode or config.get("developer_mode")),
            template_path=os.path.join(os.path.dirname(__file__),
                                       "../templates"),
            static_path=os.path.join(os.path.dirname(__file__), "../static"),
            autoescape=None)
        http_server = tornado.httpserver.HTTPServer(app, xheaders=True)
        http_server.listen(port_no)

        if config.get("api_user") and config.get("api_group"):
            chuser.change_user(config.get("api_user"), config.get("api_group"))

        for request in request_classes:
            log.debug("start", "   Handler: %s" % str(request))
        log.info("start", "API server bootstrapped and ready to go.")
        self.ioloop = tornado.ioloop.IOLoop.instance()
        try:
            self.ioloop.start()
        finally:
            self.ioloop.stop()
            http_server.stop()
            db.close()
            log.info("stop", "Server has been shutdown.")
            log.close()
Esempio n. 2
0
def start():
	db.open()
	cache.open()
	if config.test_mode:
		playlist.remove_all_locks(1)

	app = tornado.web.Application([
		(r"/advance/([0-9]+)", AdvanceScheduleRequest),
		(r"/refresh/([0-9]+)", RefreshScheduleRequest)
		], debug=(config.test_mode or config.get("developer_mode")))

	server = tornado.httpserver.HTTPServer(app)
	server.listen(int(config.get("backend_port")), address='127.0.0.1')

	if config.get("backend_user") or config.get("backend_group"):
		chuser.change_user(config.get("backend_user"), config.get("backend_group"))

	pid = os.getpid()
	pidfile = open(config.get("backend_pid_file"), 'w')
	pidfile.write(str(pid))
	pidfile.close()

	schedule.load()

	log.debug("start", "Backend server bootstrapped, port %s, ready to go." % int(config.get("backend_port")))

	for sid in config.station_ids:
		playlist.prepare_cooldown_algorithm(sid)

	try:
		tornado.ioloop.IOLoop.instance().start()
	finally:
		db.close()
Esempio n. 3
0
    def _listen(self, task_id):
        # task_ids start at zero, so we gobble up ports starting at the base port and work up
        port_no = int(config.get("api_base_port")) + task_id

        # Log according to configured directory and port # we're operating on
        log_file = "%s/rw_api_%s.log" % (config.get("api_log_dir"), port_no)
        if config.test_mode and os.path.exists(log_file):
            os.remove(log_file)
        log.init(log_file, config.get("log_level"))
        log.debug("start", "Server booting, port %s." % port_no)
        db.open()
        cache.open()

        for sid in config.station_ids:
            cache.update_local_cache_for_sid(sid)

            # If we're not in developer, remove development-related URLs
        if not config.get("developer_mode"):
            i = 0
            while i < len(request_classes):
                if request_classes[i][0].find("/test/") != -1:
                    request_classes.pop(i)
                    i = i - 1
                i = i + 1

                # Make sure all other errors get handled in an API-friendly way
        request_classes.append((r".*", api.web.Error404Handler))

        # Initialize the help (rather than it scan all URL handlers every time someone hits it)
        api.help.sectionize_requests()

        # Initialize playlist variables
        playlist.prepare_cooldown_algorithm(sid)

        # Fire ze missiles!
        app = tornado.web.Application(
            request_classes,
            debug=(config.test_mode or config.get("developer_mode")),
            template_path=os.path.join(os.path.dirname(__file__), "../templates"),
            static_path=os.path.join(os.path.dirname(__file__), "../static"),
            autoescape=None,
        )
        http_server = tornado.httpserver.HTTPServer(app, xheaders=True)
        http_server.listen(port_no)

        if config.get("api_user") and config.get("api_group"):
            chuser.change_user(config.get("api_user"), config.get("api_group"))

        for request in request_classes:
            log.debug("start", "   Handler: %s" % str(request))
        log.info("start", "API server bootstrapped and ready to go.")
        self.ioloop = tornado.ioloop.IOLoop.instance()
        try:
            self.ioloop.start()
        finally:
            self.ioloop.stop()
            http_server.stop()
            db.close()
            log.info("stop", "Server has been shutdown.")
            log.close()
Esempio n. 4
0
def start():
    db.open()
    cache.open()
    if config.test_mode:
        playlist.remove_all_locks(1)

    app = tornado.web.Application(
        [(r"/advance/([0-9]+)", AdvanceScheduleRequest),
         (r"/refresh/([0-9]+)", RefreshScheduleRequest)],
        debug=(config.test_mode or config.get("developer_mode")))

    server = tornado.httpserver.HTTPServer(app)
    server.listen(int(config.get("backend_port")), address='127.0.0.1')

    if config.get("backend_user") or config.get("backend_group"):
        chuser.change_user(config.get("backend_user"),
                           config.get("backend_group"))

    pid = os.getpid()
    pidfile = open(config.get("backend_pid_file"), 'w')
    pidfile.write(str(pid))
    pidfile.close()

    schedule.load()

    log.debug(
        "start", "Backend server bootstrapped, port %s, ready to go." %
        int(config.get("backend_port")))

    for sid in config.station_ids:
        playlist.prepare_cooldown_algorithm(sid)

    try:
        tornado.ioloop.IOLoop.instance().start()
    finally:
        db.close()
Esempio n. 5
0
	def _listen(self, task_id):
		# task_ids start at zero, so we gobble up ports starting at the base port and work up
		port_no = int(config.get("api_base_port")) + task_id
		
		# Log according to configured directory and port # we're operating on
		log_file = "%s/rw_api_%s.log" % (config.get("api_log_dir"), port_no)
		if config.test_mode and os.path.exists(log_file):
			os.remove(log_file)
		log.init(log_file, config.get("log_level"))
		log.debug("start", "Server booting, port %s." % port_no)
		db.open()
		cache.open()
		
		for sid in config.station_ids:
			cache.update_local_cache_for_sid(sid)
		
		# Fire ze missiles!
		app = tornado.web.Application(request_classes, debug=config.get("debug_mode"), template_path=os.path.join(os.path.dirname(__file__), "../templates"))
		http_server = tornado.httpserver.HTTPServer(app, xheaders = True)
		http_server.listen(port_no)
		
		if config.get("api_user") and config.get("api_group"):
			chuser.change_user(config.get("api_user"), config.get("api_group"))
		
		for request in request_classes:
			log.debug("start", "   Handler: %s" % str(request))
		log.info("start", "Server bootstrapped and ready to go.")
		self.ioloop = tornado.ioloop.IOLoop.instance()
		try:
			self.ioloop.start()
		finally:
			self.ioloop.stop()
			http_server.stop()
			db.close()
			log.info("stop", "Server has been shutdown.")
			log.close()
Esempio n. 6
0
import httplib
import urllib
import argparse
import os.path
from libs import cache
from libs import config

parser = argparse.ArgumentParser(
    description="Fetches the next song from a Rainwave backend daemon.")
parser.add_argument("--dest", "-d", required=False, default="127.0.0.1")
parser.add_argument("--sid", "-s", required=False, default=1)
parser.add_argument("--config", "-c", required=False, default=None)
args = parser.parse_args()

config.load(args.config)
cache.open()

params = urllib.urlencode({"sid": args.sid})
try:
    conn = httplib.HTTPConnection(args.dest,
                                  config.get("backend_port"),
                                  timeout=10)
    conn.request("GET", "/advance/%s" % args.sid)
    result = conn.getresponse()
    if result.status == 200:
        print result.read()
    else:
        raise Exception("Backend HTTP Error %s" % result.status)
    cache.set_station(args.sid, "backend_ok", True)
    cache.set_station(args.sid, "backend_message", "OK")
    conn.close()
Esempio n. 7
0
import httplib
import urllib
import argparse
import os.path
from libs import cache
from libs import config

parser = argparse.ArgumentParser(description="Fetches the next song from a Rainwave backend daemon.")
parser.add_argument("--dest", "-d", required=False, default="127.0.0.1")
parser.add_argument("--sid", "-s", required=False, default=1)
parser.add_argument("--config", "-c", required=False, default=None)
args = parser.parse_args()

config.load(args.config)
cache.open()

params = urllib.urlencode({ "sid": args.sid })
try:
	conn = httplib.HTTPConnection(args.dest, config.get("backend_port"), timeout=10)
	conn.request("GET", "/advance/%s" % args.sid)
	result = conn.getresponse()
	if result.status == 200:
		print result.read()
	else:
		raise Exception("Backend HTTP Error %s" % result.status)
	cache.set_station(args.sid, "backend_ok", True)
	cache.set_station(args.sid, "backend_message", "OK")
	conn.close()
except Exception as e:
	cache.set_station(args.sid, "backend_ok", False)