def start(args):
    try:
        stop()
    except:
        pass

    try:
        os.unlink(MS_PIDFILE)
    except:
        pass
    
    startup_script = textwrap.dedent("""\
    from codebay.l2tpmanagementserver import runserver
    runserver._run_server()
    """)

    cmd = [constants.CMD_START_STOP_DAEMON,
           '--start',
           '--verbose',
           '--exec', '/usr/bin/python',
           '--pidfile', MS_PIDFILE,
           '--background',
           '--make-pidfile',
           '--',  # start python options
           '-c',  # execute script from args
           startup_script]

    runcommand.run(cmd, retval=runcommand.FAIL)
Exemple #2
0
 def _start_bind(self):
     if not _check_marker():
         _log.warning('no marker, not starting bind')
         return
     
     # XXX: error handling
     runcommand.run(['/etc/init.d/bind9', 'start'])
Exemple #3
0
def start(args):
    try:
        stop()
    except:
        pass

    try:
        os.unlink(WEBSERVER_PIDFILE)
    except:
        pass

    startup_script = textwrap.dedent("""\
    from codebay.l2tpproductweb import runserver
    runserver._run_server()
    """)

    cmd = [
        constants.CMD_START_STOP_DAEMON,
        '--start',
        '--verbose',
        #           '--exec', '/usr/bin/python',
        '--exec',
        '/usr/bin/python2.4',  # XXX: python 2.4 for now
        '--pidfile',
        WEBSERVER_PIDFILE,
        '--background',
        '--make-pidfile',
        '--',  # start python options
        '-c',  # execute script from args
        startup_script
    ]

    runcommand.run(cmd, retval=runcommand.FAIL)
Exemple #4
0
    def _start_bind(self):
        if not _check_marker():
            _log.warning("no marker, not starting bind")
            return

        # XXX: error handling
        runcommand.run(["/etc/init.d/bind9", "start"])
def start(args):
    try:
        stop()
    except:
        pass

    try:
        os.unlink(WEBSERVER_PIDFILE)
    except:
        pass

    startup_script = textwrap.dedent(
        """\
    from codebay.l2tpproductweb import runserver
    runserver._run_server()
    """
    )

    cmd = [
        constants.CMD_START_STOP_DAEMON,
        "--start",
        "--verbose",
        #           '--exec', '/usr/bin/python',
        "--exec",
        "/usr/bin/python2.4",  # XXX: python 2.4 for now
        "--pidfile",
        WEBSERVER_PIDFILE,
        "--background",
        "--make-pidfile",
        "--",  # start python options
        "-c",  # execute script from args
        startup_script,
    ]

    runcommand.run(cmd, retval=runcommand.FAIL)
Exemple #6
0
    def _stop_bind(self):
        if not _check_marker():
            _log.warning('no marker, not stopping bind')
            return

        # XXX: error handling
        runcommand.run(['/etc/init.d/bind9', 'stop'])
        runcommand.run(['/usr/bin/killall', '-9', 'named'])
Exemple #7
0
    def _stop_bind(self):
        if not _check_marker():
            _log.warning("no marker, not stopping bind")
            return

        # XXX: error handling
        runcommand.run(["/etc/init.d/bind9", "stop"])
        runcommand.run(["/usr/bin/killall", "-9", "named"])
def stop(args):
    cmd = [constants.CMD_START_STOP_DAEMON, "--stop", "--verbose", "--signal", "TERM", "--pidfile", WEBSERVER_PIDFILE]

    runcommand.run(cmd, retval=runcommand.FAIL)

    try:
        os.unlink(WEBSERVER_PIDFILE)
    except:
        pass
Exemple #9
0
def stop(args):
    cmd = [
        constants.CMD_START_STOP_DAEMON, '--stop', '--verbose', '--signal',
        'TERM', '--pidfile', WEBSERVER_PIDFILE
    ]

    runcommand.run(cmd, retval=runcommand.FAIL)

    try:
        os.unlink(WEBSERVER_PIDFILE)
    except:
        pass
def stop(args):
    cmd = [constants.CMD_START_STOP_DAEMON,
           '--stop',
           '--verbose',
           '--signal', 'TERM',
           '--pidfile', MS_PIDFILE]

    runcommand.run(cmd, retval=runcommand.FAIL)

    try:
        os.unlink(MS_PIDFILE)
    except:
        pass
def write_backup_file():
    import datetime

    # FIXME: add more files/directories to backup
    # input_files = [msconstants.CONNECTION_INFO_FILE, msconstants.DEMO_LICENSE_DIRECTORY, msconstants.REPOSITORY_KEYS_FILE]
    input_files = [msconstants.DEMO_LICENSE_DIRECTORY]

    n = datetime.datetime.utcnow()
    tmpfile = '/tmp/management-server-backup-%s%s%s-%s%s%s.tar.gz' % (n.year, n.month, n.day, n.hour, n.minute, n.second)

    runcommand.run(['/bin/rm', '-f', tmpfile], retval=runcommand.FAIL)
    runcommand.run(['/bin/tar', 'czf', tmpfile] + input_files, retval=runcommand.FAIL)

    return tmpfile
Exemple #12
0
def write_backup_file():
    import datetime

    # FIXME: add more files/directories to backup
    # input_files = [msconstants.CONNECTION_INFO_FILE, msconstants.DEMO_LICENSE_DIRECTORY, msconstants.REPOSITORY_KEYS_FILE]
    input_files = [msconstants.DEMO_LICENSE_DIRECTORY]

    n = datetime.datetime.utcnow()
    tmpfile = '/tmp/management-server-backup-%s%s%s-%s%s%s.tar.gz' % (
        n.year, n.month, n.day, n.hour, n.minute, n.second)

    runcommand.run(['/bin/rm', '-f', tmpfile], retval=runcommand.FAIL)
    runcommand.run(['/bin/tar', 'czf', tmpfile] + input_files,
                   retval=runcommand.FAIL)

    return tmpfile
Exemple #13
0
def get_demo_license_info():
    my_re_time = re.compile('^grant-time=(.*?)$')
    my_re_addr = re.compile('^remote-address=(.*?)$')

    lst = []
    for i in os.listdir(msconstants.DEMO_LICENSE_DIRECTORY):
        f = None
        try:
            f = open(os.path.join(msconstants.DEMO_LICENSE_DIRECTORY, i), 'rb')
            ip = None
            gt = None
            for l in f.readlines():
                l = l.strip()
                m = my_re_addr.match(l)
                if m is not None:
                    ip = m.group(1)
                m = my_re_time.match(l)
                if m is not None:
                    gt = m.group(1)
            if gt is not None and ip is not None:
                lst.append((gt, ip))
        finally:
            if f is not None:
                f.close()
            f = None

    lst.sort()

    res = ''
    for (gt, ip) in lst:
        rv, stdout, stderr = runcommand.run(['/usr/bin/host', ip])
        stdout = stdout.strip()
        res += '%s: %s -> %s\n' % (gt, ip, stdout)
    return res
Exemple #14
0
def send_stats():
    # NB: sent from outside
    mail_address = '*****@*****.**'

    ret, stdout, stderr = runcommand.run(
        ['/usr/bin/mailx', '-s', 'management.vpnease.com stats', mail_address],
        stdin=get_stats())
Exemple #15
0
    def _bind_health_callback(self):
        self.bind_health_timer = None

        bind_health = True

        try:
            rv, stdout, stderr = runcommand.run(["/usr/bin/killall", "-0", "named"])
            if rv != 0:
                bind_health = False

            # XXX: could do better here, e.g. resolve all subdomains and see that
            # the results make some sense
        except:
            _log.exception("bind health check failed")

        if not bind_health:
            _log.warning("bind health check failed, restarting bind")
            try:
                self._stop_bind()
            except:
                _log.exception("bind stop failed")
            try:
                self._start_bind()
            except:
                _log.exception("bind start failed")
        else:
            _log.debug("bind health ok")

        self.bind_health_timer = reactor.callLater(self.bind_health_interval, self._bind_health_callback)
def get_demo_license_info():
    my_re_time = re.compile('^grant-time=(.*?)$')
    my_re_addr = re.compile('^remote-address=(.*?)$')

    lst = []
    for i in os.listdir(msconstants.DEMO_LICENSE_DIRECTORY):
        f = None
        try:
            f = open(os.path.join(msconstants.DEMO_LICENSE_DIRECTORY, i), 'rb')
            ip = None
            gt = None
            for l in f.readlines():
                l = l.strip()
                m = my_re_addr.match(l)
                if m is not None:
                    ip = m.group(1)
                m = my_re_time.match(l)
                if m is not None:
                    gt = m.group(1)
            if gt is not None and ip is not None:
                lst.append((gt, ip))
        finally:
            if f is not None:
                f.close()
            f = None

    lst.sort()

    res = ''
    for (gt, ip) in lst:
        rv, stdout, stderr = runcommand.run(['/usr/bin/host', ip])
        stdout = stdout.strip()
        res += '%s: %s -> %s\n' % (gt, ip, stdout)
    return res
Exemple #17
0
def run_command(args, executable=None, cwd=None, env=None, stdin=None, stdout=None, stderr=None, shell=False, preexec=None, retval=None, nologonerror=False, nologruntime=False):
    _log.debug("run_command: [%s], executable=%s, cwd=%s, env=%s, shell=%s, preexec=%s, retval=%s" % (str(args), str(executable), str(cwd), str(env), str(shell), str(preexec), str(retval)))

    for name, value in [['stdin', stdin], ['stdout', stdout], ['stderr', stderr]]:
        if value is None:
            _log.debug("%s:%s" % (name, str(value)))
        else:
            _log.debug("%s:\n%s" % (name, str(value)))

    def _log_result(msg, onlydebug=False, rv=None, out=None, err=None):
        m = msg
        if rv is not None:
            m += ':\n  retval: %s' % rv
        if out is not None:
            m += ':\n  stdout: %s' % out
        if err is not None:
            m += ':\n  stderr: %s' % err

        if not onlydebug:
            _log.error(m)
        else:
            _log.debug(m)

    try:
        start_time = datetime.datetime.utcnow()
        ret = runcommand.run(args, executable, cwd, env, stdin, stdout, stderr, shell, preexec, retval)
        if not nologruntime:
            _log_runtime(start_time, "run_command succeeded")
    except runcommand.RunException, e:
        _log_result(' ==> FAILED with RunException', onlydebug=nologonerror, rv=e.rv, out=e.stdout, err=e.stderr)
        if not nologruntime:
            _log_runtime(start_time, "run_command failed")
        raise
Exemple #18
0
    def _bind_health_callback(self):
        self.bind_health_timer = None

        bind_health = True

        try:
            rv, stdout, stderr = runcommand.run(['/usr/bin/killall', '-0', 'named'])
            if rv != 0:
                bind_health = False

            # XXX: could do better here, e.g. resolve all subdomains and see that
            # the results make some sense
        except:
            _log.exception('bind health check failed')

        if not bind_health:
            _log.warning('bind health check failed, restarting bind')
            try:
                self._stop_bind()
            except:
                _log.exception('bind stop failed')
            try:
                self._start_bind()
            except:
                _log.exception('bind start failed')
        else:
            _log.debug('bind health ok')
            
        self.bind_health_timer = reactor.callLater(self.bind_health_interval, self._bind_health_callback)
Exemple #19
0
def run_command(args, executable=None, cwd=None, env=None, stdin=None, stdout=None, stderr=None, shell=False, preexec=None, retval=None):
    _log.debug("run_command: [%s], executable=%s, cwd=%s, env=%s, shell=%s, preexec=%s, retval=%s" % (str(args), str(executable), str(cwd), str(env), str(shell), str(preexec), str(retval)))

    for name, value in [['stdin', stdin], ['stdout', stdout], ['stderr', stderr]]:
        if value is None:
            _log.debug("%s:%s" % (name, str(value)))
        else:
            _log.debug("%s:\n%s" % (name, str(value)))

    try:
        ret = runcommand.run(args, executable, cwd, env, stdin, stdout, stderr, shell, preexec, retval)
    except runcommand.RunException, e:
        _log.debug(' ==> FAILED with RunException:\nretval=%s\nstdout:%s\nstderr:%s\n' % (e.rv, e.stdout, e.stderr))
        raise
Exemple #20
0
def render_to_text(content, columns=76, ppc=8, ppl=8, strip_empty_lines=True, w3m=None):
    _w3m = w3m
    if _w3m is None:
        if os.path.exists(w3m_path):
            _w3m = w3m_path
    if _w3m is None:
        raise Exception('cannot find w3m and not supplied by user')

    rc, stdout, stderr = runcommand.run([_w3m, '-T', 'text/html', '-dump', '-cols', str(columns), '-ppc', str(ppc), '-ppl', str(ppl)], stdin=str(content), retval=runcommand.FAIL)

    if strip_empty_lines:
        res = stdout.split('\n')
        while len(res) > 0 and res[0] == '':
            del res[0]
        while len(res) > 0 and res[-1] == '':
            del res[-1]

        return '\n'.join(res) + '\n'
    else:
        return stdout
def send_stats():
    # NB: sent from outside
    mail_address = '*****@*****.**'

    ret, stdout, stderr = runcommand.run(['/usr/bin/mailx', '-s', 'management.vpnease.com stats', mail_address], stdin=get_stats())