Example #1
0
def start_htsql(port):
    logger.info("Starting htsql server")

    if db_settings.password:
        password = '******' + urllib.parse.quote_plus(db_settings.password)
    else:
        password = ''
    uri = 'pgsql://{}{}@{}:{}/{}'.format(db_settings.username, password,
                                         db_settings.address, db_settings.port,
                                         db_settings.dbname)

    config = library.get_resource_filename('stoqserver', 'htsql', 'config.yml')

    popen = Process([
        'htsql-ctl', 'server', '-C', config, uri, '--host', '127.0.0.1',
        '--port', port
    ])

    def _sigterm_handler(_signal, _stack_frame):
        popen.poll()
        if popen.returncode is None:
            popen.terminate()
        os._exit(0)

    signal.signal(signal.SIGINT, signal.SIG_IGN)
    signal.signal(signal.SIGTERM, _sigterm_handler)

    popen.wait()
Example #2
0
def start_htsql(port):
    config = get_config()
    if config.get('General', 'disable_htsql'):
        logger.info("Not starting htsql as requested in config file.")
        return

    logger.info("Starting htsql server")

    if db_settings.password:
        password = '******' + urllib.parse.quote_plus(db_settings.password)
    else:
        password = ''
    uri = 'pgsql://{}{}@{}:{}/{}'.format(
        db_settings.username, password,
        db_settings.address, db_settings.port, db_settings.dbname)

    config = library.get_resource_filename('stoqserver', 'htsql', 'config.yml')

    popen = Process(['htsql-ctl', 'server', '-C', config, uri,
                     '--host', '127.0.0.1', '--port', port])

    def _sigterm_handler(_signal, _stack_frame):
        popen.poll()
        if popen.returncode is None:
            popen.terminate()
        os._exit(0)
    signal.signal(signal.SIGINT, signal.SIG_IGN)
    signal.signal(signal.SIGTERM, _sigterm_handler)

    popen.wait()
Example #3
0
def start_rtc():
    logger.info("Starting webRTC")

    cwd = library.get_resource_filename('stoqserver', 'webrtc')
    retry = True
    while retry:
        retry = False
        popen = subprocess.Popen(
            ['bash', 'start.sh'], cwd=cwd)

        def _sigterm_handler(_signal, _stack_frame):
            popen.poll()
            if popen.returncode is None:
                popen.terminate()
            os._exit(0)
        signal.signal(signal.SIGINT, signal.SIG_IGN)
        signal.signal(signal.SIGTERM, _sigterm_handler)

        popen.wait()
        if popen.returncode == 11:
            logger.warning("libstdc++ too old, not running webRTC client. "
                           "A system upgrade may be required!")
            retry = False
        if popen.returncode == 10:
            logger.warning("Something failed when trying to start webrtc. "
                           "Retrying again in 10 minutes...")
            time.sleep(10 * 60)
            retry = True
        elif popen.returncode == 139:
            logger.warning("Segmentation fault caught on wrtc. Restarting...")
            time.sleep(1)
            retry = True
Example #4
0
    def _setup_twisted(self):
        root = resource.Resource()
        checker = _PasswordChecker()
        cf = BasicCredentialFactory(SERVER_NAME)

        # eggs
        eggs_path = library.get_resource_filename('stoqserver', 'eggs')
        root.putChild(
            'eggs',
            self._get_resource_wrapper(static.File(eggs_path), checker, cf))

        # conf
        root.putChild(
            'login',
            self._get_resource_wrapper(static.File(APP_CONF_FILE), checker, cf))

        # md5sum
        with tempfile.NamedTemporaryFile(delete=False) as f:
            for egg in SERVER_EGGS:
                egg_path = os.path.join(eggs_path, egg)
                if not os.path.exists(eggs_path):
                    continue

                f.write('%s:%s\n' % (egg, md5sum_for_filename(egg_path)))

        root.putChild('md5sum', static.File(f.name))

        site = server.Site(root)
        site.protocol = HTTPChannel

        reactor.listenTCP(SERVER_AVAHI_PORT, site)
def _run(cmd, *args):
    script = library.get_resource_filename('stoqserver', 'scripts',
                                           'duplicitybackup.py')
    p = Process(['python2', script, cmd] + list(args), stdout=PIPE, stderr=PIPE)
    threadit(_watch_fd, p.stdout)
    threadit(_watch_fd, p.stderr)
    p.wait()
    return p.returncode == 0
Example #6
0
def start_rtc():
    if not api.sysparam.get_bool('ONLINE_SERVICES'):
        logger.info("ONLINE_SERVICES not enabled. Not starting rtc...")
        return

    config = get_config()
    if config.get('General', 'disable_rtc'):
        logger.info("Not starting rtc as requested in config file.")
        return

    logger.info("Starting webRTC")

    cwd = library.get_resource_filename('stoqserver', 'webrtc')
    retry = True

    extra_args = []
    camera_urls = config.get('Camera', 'url') or None
    if camera_urls:
        extra_args.append('-c=' + ' '.join(set(camera_urls.split(' '))))

    xmlrpc_host = config.get('General', 'serveraddress') or '127.0.0.1'
    extra_args.append('-h={}'.format(xmlrpc_host))

    xmlrpc_port = config.get('General', 'serverport') or SERVER_XMLRPC_PORT
    extra_args.append('-p={}'.format(xmlrpc_port))

    while retry:
        retry = False
        popen = Process(['bash', 'start.sh'] + extra_args, cwd=cwd)

        def _sigterm_handler(_signal, _stack_frame):
            popen.poll()
            if popen.returncode is None:
                popen.terminate()
            os._exit(0)

        signal.signal(signal.SIGINT, signal.SIG_IGN)
        signal.signal(signal.SIGTERM, _sigterm_handler)

        popen.wait()
        if popen.returncode == 11:
            logger.warning("libstdc++ too old, not running webRTC client. "
                           "A system upgrade may be required!")
            retry = False
        elif popen.returncode == 10:
            logger.warning("Something failed when trying to start webrtc. "
                           "Retrying again in 10 minutes...")
            time.sleep(10 * 60)
            retry = True
        elif popen.returncode == 12:
            logger.warning("webrtc installation corrupted. Restarting it...")
            time.sleep(1)
            retry = True
        elif popen.returncode == 139:
            logger.warning("Segmentation fault caught on wrtc. Restarting...")
            time.sleep(1)
            retry = True
Example #7
0
def start_rtc():
    if not api.sysparam.get_bool('ONLINE_SERVICES'):
        logger.info("ONLINE_SERVICES not enabled. Not starting rtc...")
        return

    config = get_config()
    if config.get('General', 'disable_rtc'):
        logger.info("Not starting rtc as requested in config file.")
        return

    logger.info("Starting webRTC")

    cwd = library.get_resource_filename('stoqserver', 'webrtc')
    retry = True

    extra_args = []
    camera_urls = config.get('Camera', 'url') or None
    if camera_urls:
        extra_args.append('-c=' + ' '.join(set(camera_urls.split(' '))))

    xmlrpc_host = config.get('General', 'serveraddress') or '127.0.0.1'
    extra_args.append('-h={}'.format(xmlrpc_host))

    xmlrpc_port = config.get('General', 'serverport') or SERVER_XMLRPC_PORT
    extra_args.append('-p={}'.format(xmlrpc_port))

    while retry:
        retry = False
        popen = Process(
            ['bash', 'start.sh'] + extra_args, cwd=cwd)

        def _sigterm_handler(_signal, _stack_frame):
            popen.poll()
            if popen.returncode is None:
                popen.terminate()
            os._exit(0)
        signal.signal(signal.SIGINT, signal.SIG_IGN)
        signal.signal(signal.SIGTERM, _sigterm_handler)

        popen.wait()
        if popen.returncode == 11:
            logger.warning("libstdc++ too old, not running webRTC client. "
                           "A system upgrade may be required!")
            retry = False
        elif popen.returncode == 10:
            logger.warning("Something failed when trying to start webrtc. "
                           "Retrying again in 10 minutes...")
            time.sleep(10 * 60)
            retry = True
        elif popen.returncode == 12:
            logger.warning("webrtc installation corrupted. Restarting it...")
            time.sleep(1)
            retry = True
        elif popen.returncode == 139:
            logger.warning("Segmentation fault caught on wrtc. Restarting...")
            time.sleep(1)
            retry = True
Example #8
0
def _run(cmd, *args):
    script = library.get_resource_filename('stoqserver', 'scripts',
                                           'duplicitybackup.py')
    p = Process(['python2', script, cmd] + list(args),
                stdout=PIPE,
                stderr=PIPE)
    threadit(_watch_fd, p.stdout)
    threadit(_watch_fd, p.stderr)
    p.wait()
    return p.returncode == 0
Example #9
0
import tempfile

import avahi
from stoqlib.api import api
from stoqlib.domain.person import LoginUser
from stoqlib.exceptions import LoginError
from stoqlib.lib.configparser import get_config
from stoqlib.lib.fileutils import md5sum_for_filename

from stoqserver import library
from stoqserver.common import (AVAHI_DOMAIN, AVAHI_HOST, AVAHI_STYPE,
                               SERVER_NAME, SERVER_AVAHI_PORT, SERVER_EGGS,
                               APP_CONF_FILE)

_ = lambda s: s
_eggs_path = library.get_resource_filename('stoqserver', 'eggs')
_md5sum_path = None
logger = logging.getLogger(__name__)


# TODO: This is experimental and not used anywhere in production,
# which means that we can tweak it a lot without having to worry
# to break something.
class _RequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    def do_HEAD(self):
        self.send_response(200)
        self.send_header('Content-type', 'text/html')
        self.end_headers()

    def do_GET(self):
        auth = self.headers.getheader('Authorization')
Example #10
0
import tempfile

from stoqlib.api import api
from stoqlib.domain.person import LoginUser
from stoqlib.exceptions import LoginError
from stoqlib.lib.configparser import get_config
from stoqlib.lib.fileutils import md5sum_for_filename

from stoqserver import library
from stoqserver.common import (AVAHI_DOMAIN, AVAHI_HOST, AVAHI_STYPE,
                               SERVER_NAME, SERVER_AVAHI_PORT,
                               SERVER_EGGS, APP_CONF_FILE)

_ = lambda s: s
try:
    _eggs_path = library.get_resource_filename('stoqserver', 'eggs')
except KeyError:
    # FIXME: Windows
    _eggs_path = ''

_md5sum_path = None
logger = logging.getLogger(__name__)


# TODO: This is experimental and not used anywhere in production,
# which means that we can tweak it a lot without having to worry
# to break something.
class _RequestHandler(http.server.SimpleHTTPRequestHandler):

    def do_HEAD(self):
        self.send_response(200)