示例#1
0
def first_run():
    log = logging.getLogger("openmolar_server")
    conf = OMServerConfig()
    if not conf.is_installed:
        log.warning("First run of openmolar_server")
        from lib_openmolar.server.misc.installer import Installer
        installer = Installer()
        installer.install()
    else:
        conf.update()
示例#2
0
    def start(self):
        '''
        start the server
        '''
        LOGGER.info("starting OMServer Process")
        config = OMServerConfig()
        loc = config.location
        port = config.port
        key = config.private_key
        cert = config.pub_key
        if not (os.path.isfile(key) and os.path.isfile(cert)):
            raise IOError, "certificate '%s' and/or key '%s' not found" % (
                cert, key)
        try:
            self.server = VerifyingServerSSL((loc, port), key, cert)
        except socket.error:
            LOGGER.error('Unable to start the server.' +
                         (' Port %d is in use' % port) +
                         ' (Perhaps openmolar server is already running?)')
            return

        if loc == "":
            readable_loc = "on all interfaces"
        else:
            readable_loc = loc
        LOGGER.info("listening for ssl connections %s port %d" %
                    (readable_loc, port))
        LOGGER.debug("using cert %s" % cert)
        LOGGER.debug("using key %s" % key)

        # daemonise the process and write to /var/run
        self.start_(stderr=logger.LOCATION)

        self.server.register_instance(PermissionDispatcher())
        for manager, hash in config.managers:
            self.server.add_user(manager, hash)

        server_thread = threading.Thread(target=self.server.serve_forever)
        server_thread.start()
示例#3
0
 def __init__(self):
     self.config = OMServerConfig()
     DBFunctions.__init__(self)
示例#4
0
 def __init__(self):
     self.config = OMServerConfig()
示例#5
0
class Installer(object):
    '''
    A class to "install" the server application,
    creates a master user with random password,
    creates a master database,
    sets out the directory structure.
    '''
    def __init__(self):
        self.config = OMServerConfig()

    @property
    def chk_install(self):
        return self.config.is_installed

    def check_current(self):
        '''
        update the config file if neccessary
        '''
        if not self.config.is_current:
            self.config.update()

    def make_dirs(self):
        for dir in (self.config.conf_dir, LOGDIR):
            try:
                print "making directory", dir
                os.makedirs(dir)
            except OSError as exc:
                if exc.errno == 13:
                    print("You do not have permission to create %s" % dir)
                    print("Are you Root?")
                    sys.exit(0)

    def write_config(self):
        '''
        write the config file for openmolar
        '''
        self.config.new_config()
        self.config.write()

    def init_master_user(self):
        '''
        initialises the user "openmolar"
        '''

        for script in ("openmolar-init-master-user",
                       "openmolar-alter-master-user"):

            LOGGER.info("calling script %s" % script)

            p = subprocess.Popen([script], stdout=subprocess.PIPE)

            while True:
                line = p.stdout.readline()
                if not line:
                    break
                LOGGER.info(line)

    def init_master_db(self):
        '''
        initialises the openmolar_master database
        '''
        LOGGER.info("calling script openmolar-init-master-db")

        p = subprocess.Popen(["openmolar-init-master-db"],
                             stdout=subprocess.PIPE)

        while True:
            line = p.stdout.readline()
            if not line:
                break
            LOGGER.debug(line)

    def install(self):
        '''
        this should normally only be called on the very first running of the
        server application
        '''
        self.make_dirs()
        self.write_config()
        self.init_master_user()
        self.init_master_db()
示例#6
0
 def __init__(self):
     self.config = OMServerConfig()
示例#7
0
class Installer(object):
    '''
    A class to "install" the server application,
    creates a master user with random password,
    creates a master database,
    sets out the directory structure.
    '''
    def __init__(self):
        self.config = OMServerConfig()

    @property
    def chk_install(self):
        return self.config.is_installed

    def check_current(self):
        '''
        update the config file if neccessary
        '''
        if not self.config.is_current:
            self.config.update()

    def make_dirs(self):
        for dir in (self.config.conf_dir, LOGDIR):
            try:
                print "making directory", dir
                os.makedirs(dir)
            except OSError as exc:
                if exc.errno == 13:
                    print ("You do not have permission to create %s"% dir)
                    print ("Are you Root?")
                    sys.exit(0)

    def write_config(self):
        '''
        write the config file for openmolar
        '''
        self.config.new_config()
        self.config.write()

    def init_master_user(self):
        '''
        initialises the user "openmolar"
        '''

        for script in (
        "openmolar-init-master-user",
        "openmolar-alter-master-user"
        ):

            LOGGER.info("calling script %s"% script)

            p = subprocess.Popen([script],
                stdout=subprocess.PIPE )

            while True:
                line = p.stdout.readline()
                if not line:
                    break
                LOGGER.info(line)

    def init_master_db(self):
        '''
        initialises the openmolar_master database
        '''
        LOGGER.info("calling script openmolar-init-master-db")

        p = subprocess.Popen(["openmolar-init-master-db"],
            stdout=subprocess.PIPE )

        while True:
            line = p.stdout.readline()
            if not line:
                break
            LOGGER.debug(line)

    def install(self):
        '''
        this should normally only be called on the very first running of the
        server application
        '''
        self.make_dirs()
        self.write_config()
        self.init_master_user()
        self.init_master_db()