Пример #1
0
    def add_mount(self, device, fs_type, options):

        log = logger.get_logger('systemctl')

        mount_template_file = join(self.platform_config.config_dir(), 'mount',
                                   'mount.template')
        mount_definition = Template(open(
            mount_template_file, 'r').read()).substitute({
                'what':
                device,
                'where':
                self.platform_config.get_external_disk_dir(),
                # 'type': fs_type,
                'type':
                'auto',
                'options':
                options
            })

        mount_filename = dir_to_systemd_mount_filename(
            self.platform_config.get_external_disk_dir())
        with open(self.__systemd_file(mount_filename), 'w') as f:
            f.write(mount_definition)

        log.info('enabling {0}'.format(mount_filename))
        check_output('systemctl enable {0} 2>&1'.format(mount_filename),
                     shell=True)
        self.__start(mount_filename)
Пример #2
0
    def __init__(self):
        if not logger.factory_instance:
            logger.init(logging.DEBUG, True)

        self.log = logger.get_logger('{0}_installer'.format(APP_NAME))
        self.app_dir = paths.get_app_dir(APP_NAME)
        self.app_data_dir = paths.get_data_dir(APP_NAME)
Пример #3
0
    def __init__(self):
        if not logger.factory_instance:
            logger.init(logging.DEBUG, True)

        self.log = logger.get_logger('{0}_installer'.format(APP_NAME))
        self.app_dir = paths.get_app_dir(APP_NAME)
        self.common_dir = paths.get_data_dir(APP_NAME)
        self.snap_data_dir = os.environ['SNAP_DATA']
Пример #4
0
    def __init__(self):
        if not logger.factory_instance:
            logger.init(logging.DEBUG, True)

        self.log = logger.get_logger('installer')
        self.templates_path = join(config.INSTALL_DIR, 'config.templates')
        self.config_dir = join(config.DATA_DIR, 'config')
        self.data_dir = config.DATA_DIR
Пример #5
0
 def __init__(self, platform_config, event_trigger, lsblk, path_checker,
              systemctl):
     self.platform_config = platform_config
     self.systemctl = systemctl
     self.event_trigger = event_trigger
     self.lsblk = lsblk
     self.path_checker = path_checker
     self.log = logger.get_logger('hardware')
Пример #6
0
 def __init__(self, platform_config, user_platform_config, info, nginx,
              certbot_generator):
     self.info = info
     self.log = get_logger('certificate_generator')
     self.platform_config = platform_config
     self.user_platform_config = user_platform_config
     self.nginx = nginx
     self.openssl_bin = platform_config.openssl()
     self.certbot_generator = certbot_generator
 def __init__(self, platform_config, user_platform_config, info, snap):
     self.info = info
     self.log = get_logger('certbot')
     self.platform_config = platform_config
     self.user_platform_config = user_platform_config
     self.certbot_bin = '{0}/bin/certbot'.format(self.platform_config.app_dir())
     self.log_dir = self.platform_config.get_log_root()
     self.certbot_config_dir = join(self.platform_config.data_dir(), 'certbot')
     self.snap = snap
Пример #8
0
def _is_activated():
    log = get_logger('activated_check')
    platform_user_config = get_injector().user_platform_config
    activated = False
    try:
        activated = platform_user_config.is_activated()
    except Exception as e:
        log.error('unable to verify activation status, assume it is not activated, {0}'.format(str(e)))

    return activated
Пример #9
0
 def __init__(self, app_dir, data_dir, config_path, port):
     self.log = logger.get_logger('database')
     self.app_dir = app_dir
     self.config_path = config_path
     self.data_dir = data_dir
     self.postgresql_config = join(self.config_path, 'postgresql.conf')
     self.database_dir = join(self.data_dir, 'database')
     self.old_major_version_file = join(self.data_dir, 'db.major.version')
     self.new_major_version_file = join(self.app_dir, 'db.major.version')
     self.backup_file = join(self.data_dir, 'database.dump')
     self.database_host = '{0}:{1}'.format(self.database_dir, port)
Пример #10
0
    def __stop(self, service):
        log = logger.get_logger('systemctl')

        try:
            log.info('checking {0}'.format(service))
            result = check_output(
                'systemctl is-active {0} 2>&1'.format(service),
                shell=True).strip()
            log.info('stopping {0}'.format(service))
            check_output('systemctl stop {0} 2>&1'.format(service), shell=True)
        except CalledProcessError, e:
            result = e.output.strip()
Пример #11
0
    def __start(self, service):
        log = logger.get_logger('systemctl')

        try:
            log.info('starting {0}'.format(service))
            check_output('systemctl start {0} 2>&1'.format(service), shell=True)
        except CalledProcessError as e:
            log.error(e.output.decode())
            try:
                log.error(check_output('journalctl -u {0} 2>&1'.format(service), shell=True).decode())
            except CalledProcessError as e:
                log.error(e.output.decode())
            raise e
Пример #12
0
def run_hook_script(app_dir, action):
    app_event_script, add_location_to_sys_path = get_script_path(
        app_dir, action)
    log = logger.get_logger('events')
    if isfile(app_event_script):
        log.info('executing {0}'.format(app_event_script))
        try:
            run_script(app_event_script, add_location_to_sys_path)
        except CalledProcessError, e:
            log.error('error in script: {0}'.format(e.output))
            log.error(traceback.format_exc())
            if action == 'post-install':
                raise e
Пример #13
0
 def __init__(self, platform_config, user_platform_config, redirect_service,
              port_drill_factory, platform_cron, ldap_auth, event_trigger,
              tls, nginx):
     self.tls = tls
     self.platform_config = platform_config
     self.user_platform_config = user_platform_config
     self.redirect_service = redirect_service
     self.port_drill_factory = port_drill_factory
     self.auth = ldap_auth
     self.platform_cron = platform_cron
     self.event_trigger = event_trigger
     self.logger = logger.get_logger('Device')
     self.nginx = nginx
Пример #14
0
def redirect_if_activated(f):
    platform_user_config = get_injector().user_platform_config
    log = get_logger('redirect_if_activated')

    def new_func(*args, **kwargs):
        try:
            if platform_user_config.is_activated():
                return redirect('/')
        except Exception, e:
            log.error(
                'unable to verify activation status, assume it is not activated, {0}'
                .format(e.message))

        return make_response(f(*args, **kwargs))
Пример #15
0
    def __init__(self):
        if not logger.factory_instance:
            logger.init(logging.DEBUG, True)

        self.log = logger.get_logger('rocketchat')
        self.snap_dir = '/snap/rocketchat/current'
        self.data_dir = '/var/snap/rocketchat/current'
        self.common_dir = '/var/snap/rocketchat/common'
        self.app_url = urls.get_app_url(APP_NAME)
        self.install_file = join(self.common_dir, 'installed')
        self.database_dump = join(self.data_dir, 'database.dump.gzip')
        self.rocketchat_env_file_source = join(self.snap_dir, 'config', 'rocketchat.env')
        self.rocketchat_env_file_target = join(self.data_dir, 'config', 'rocketchat.env')
        self.version_new_file = join(self.snap_dir, 'nodejs', 'rocketchat.version')
        self.version_old_file = join(self.data_dir, 'rocketchat.version')
Пример #16
0
 def __init__(self, platform_config, user_platform_config, device, device_info, snap, hardware, redirect_service,
              log_aggregator, certbot_generator, port_mapper_factory, network, port_config):
     self.port_config = port_config
     self.hardware = hardware
     self.platform_config = platform_config
     self.log = logger.get_logger('rest.public')
     self.user_platform_config = user_platform_config
     self.device = device
     self.device_info = device_info
     self.snap = snap
     self.www_dir = self.platform_config.www_root_public()
     self.redirect_service = redirect_service
     self.log_aggregator = log_aggregator
     self.certbot_generator = certbot_generator
     self.port_mapper_factory = port_mapper_factory
     self.network=network
Пример #17
0
    def __init__(self):
        if not logger.factory_instance:
            logger.init(logging.DEBUG, True)

        self.log = logger.get_logger('{0}_installer'.format(APP_NAME))
        self.app_dir = paths.get_app_dir(APP_NAME)
        self.snap_common = os.environ['SNAP_COMMON']
        self.snap_data = join('/var/snap', APP_NAME, 'current')
        self.config_path = join(self.snap_data, 'config')
        self.openvpn_config_dir = join(self.snap_data, 'openvpn')
        self.openssl_bin = join(self.app_dir, 'openssl/bin/openssl')
        self.generate_keys_bin = join(self.app_dir, 'bin/generate-keys.sh')
        self.prefix_delegation_bin = join(self.app_dir,
                                          'bin/prefix_delegation.sh')
        self.prefix_delegation_link = join(
            self.app_dir, '/etc/dhcp/dhclient-exit-hooks.d/openvpn')
        self.device_domain_name = urls.get_device_domain_name()
Пример #18
0
    def add_service(self, app_id, service, include_socket=False, start=True):

        service = self.service_name(service)

        configs_root = join(self.platform_config.configs_root(), app_id)

        log = logger.get_logger('systemctl')

        shutil.copyfile(self.__app_service_file(configs_root, service), self.__systemd_service_file(service))

        if include_socket:
            shutil.copyfile(self.__app_socket_file(configs_root, service), self.__systemd_socket_file(service))

        log.info('enabling {0}'.format(service))
        check_output('systemctl enable {0} 2>&1'.format(service), shell=True)
        if start:
            self.__start('{0}.service'.format(service))
Пример #19
0
    def __init__(self):
        if not logger.factory_instance:
            logger.init(logging.DEBUG, True)

        self.log = logger.get_logger('nextcloud_installer')
        self.app_dir = paths.get_app_dir(APP_NAME)
        self.common_dir = paths.get_data_dir(APP_NAME)
        self.data_dir = join('/var/snap', APP_NAME, 'current')
        self.config_dir = join(self.data_dir, 'config')
        self.extra_apps_dir = join(self.data_dir, 'extra-apps')
        self.occ = OCConsole(join(self.app_dir, OCC_RUNNER_PATH))
        self.nextcloud_config_path = join(self.data_dir, 'nextcloud', 'config')
        self.nextcloud_config_file = join(self.nextcloud_config_path,
                                          'config.php')
        self.cron = Cron(CRON_USER)
        self.db = Database(self.app_dir, self.data_dir, self.config_dir,
                           PSQL_PORT)
        self.oc_config = OCConfig(join(self.app_dir, 'bin/nextcloud-config'))
Пример #20
0
 def __init__(self, config_dir=None):
     self.filename = join(config_dir, PORT_CONFIG_NAME)
     self.logger = logger.get_logger('insider_port_config')
Пример #21
0
 def __init__(self, platform_config, path_checker):
     self.platform_config = platform_config
     self.path_checker = path_checker
     self.log = logger.get_logger('lsblk')
Пример #22
0
 def __init__(self, config_db=USER_CONFIG_DB, old_config_file=USER_CONFIG_FILE_OLD):
     self.config_db = config_db
     self.old_config_file = old_config_file
     self.log = logger.get_logger('PlatformUserConfig')
Пример #23
0
 def __init__(self, nat_pmp_port_mapper, upnp_port_mapper):
     self.nat_pmp_port_mapper = nat_pmp_port_mapper
     self.upnp_port_mapper = upnp_port_mapper
     self.log = logger.get_logger('port_mapper_factory')
Пример #24
0
 def __init__(self, platform_config, info):
     self.info = info
     self.platform_config = platform_config
     self.logger = logger.get_logger('Snap')
Пример #25
0
def check_http_error(response):
    log = logger.get_logger('util')
    if not response.status_code == 200:
        log.error(response.text)
        error = convertible.from_json(response.text)
        raise PassthroughJsonError(error.message, response.text)
Пример #26
0
 def __init__(self, cron_user):
     self.cron_cmd = '/usr/bin/snap run nextcloud.cron'
     self.cron_user = cron_user
     self.log = logger.get_logger('cron')
Пример #27
0
 def __init__(self, port_config, port_mapper, port_prober):
     self.port_prober = port_prober
     self.logger = logger.get_logger('PortDrill')
     self.port_config = port_config
     self.port_mapper = port_mapper
Пример #28
0
 def __init__(self):
     self.logger = logger.get_logger('NonePortDrill')
Пример #29
0
 def __init__(self, platform_config):
     self.platform_config = platform_config
     self.log = logger.get_logger('systemctl')
Пример #30
0
 def __init__(self, manual_public_ip, manual_certificate_port, manual_access_port):
     self.manual_certificate_port = manual_certificate_port
     self.manual_access_port = manual_access_port
     self.manual_public_ip = manual_public_ip
     self.logger = logger.get_logger('ManualPortMapper')