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 = api.get_app_setup(APP_NAME) self.database_path = join(self.app.get_data_dir(), 'database') self.occ = OCConsole(join(self.app.get_install_dir(), OCC_RUNNER_PATH))
def __stop(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()
def __init__(self, platform_config, user_platform_config, device, device_info, sam, hardware, redirect_service, log_aggregator): 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.sam = sam self.www_dir = self.platform_config.www_root() self.redirect_service = redirect_service self.log_aggregator = log_aggregator
def execute(sql, database=None): log = logger.get_logger('diaspora_postgres') config = Config() if not database: database = config.db_name() log.info("executing: {0}".format(sql)) log.info(check_output('{0} -U {1} -h {2} -d {3} -c "{4}"'.format( config.psql(), config.db_user(), config.db_socket(), database, sql), shell=True))
def __start(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, e: try: log.error(check_output('systemctl status {0}'.format(service), shell=True)) log.error(check_output('journalctl | grep {0}'.format(service), shell=True)) except CalledProcessError, e: log.error(e.output)
def __init__(self, config_file): self.log = logger.get_logger('PlatformUserConfig') self.parser = ConfigParser() self.filename = config_file if not isfile(self.filename): self.parser.add_section('platform') self.__save() else: self.parser.read(self.filename) if not self.parser.has_section('platform'): self.parser.add_section('platform')
def __init__(self): self.log = logger.get_logger('mail_installer') self.app_dir = paths.get_app_dir(APP_NAME) self.app_data_dir = paths.get_data_dir(APP_NAME) self.app_url = urls.get_app_url(APP_NAME) self.app_domain_name = urls.get_app_domain_name(APP_NAME) self.platform_data_dir = paths.get_data_dir('platform') self.device_domain_name = urls.get_device_domain_name() self.database_path = '{0}/database'.format(self.app_data_dir) self.config_path = join(self.app_data_dir, 'config') self.config = Config(self.config_path) self.user_config = UserConfig(self.app_data_dir)
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, e: try: log.error( check_output('journalctl -u {0}'.format(service), shell=True)) except CalledProcessError, e: log.error(e.output)
def __trigger_app_event(self, apps_root, event_script): log = logger.get_logger('events') for app in self.sam.installed_all_apps(): app_id = app.app.id app_event_script = join(apps_root, app_id, 'bin', event_script) if path.isfile(app_event_script): log.info('executing {0}'.format(app_event_script)) try: run_script(app_event_script) except: log.error('error in script') log.error(traceback.format_exc()) else: log.info('{0} not found'.format(app_event_script))
def __init__(self, config, applications, repo_versions, installed_versions): self.config = config self.apps_dir = config.apps_dir() self.applications = applications self.repo_versions = repo_versions self.installed_versions = installed_versions self.logger = logger.get_logger('sam.manager') self.release_filename = join(self.config.status_dir(), 'release') sam_temp_dir = self.config.temp_dir() if not isdir(sam_temp_dir): makedirs(sam_temp_dir) images_dir = self.config.images_dir() if not isdir(images_dir): makedirs(images_dir)
def __init__(self, platform_config, user_platform_config, info, sam): 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.sam = sam self.certbot_certificate_file = '{0}/certbot/live/{1}/fullchain.pem'.format( self.platform_config.data_dir(), self.info.domain()) self.certbot_key_file = '{0}/certbot/keys/0000_key-certbot.pem'.format( self.platform_config.data_dir(), self.info.domain())
def add_service(app_id, service, include_socket=False, start=True): config = PlatformConfig() app_dir = join(config.apps_root(), app_id) log = logger.get_logger('systemctl') shutil.copyfile(__app_service_file(app_dir, service), __systemd_service_file(service)) if include_socket: shutil.copyfile(__app_socket_file(app_dir, service), __systemd_socket_file(service)) log.info('enabling {0}'.format(service)) check_output('systemctl enable {0} 2>&1'.format(service), shell=True) if start: start_service(service)
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))
def __init__(self, platform_config, user_platform_config, device, device_info, sam, 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.sam = sam 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 self.resize_script = self.platform_config.get_boot_extend_script()
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)
def add_mount(device, fs_type, options): log = logger.get_logger('systemctl') config = PlatformConfig() mount_template_file = join(config.config_dir(), 'mount', 'mount.template') mount_definition = Template(open(mount_template_file, 'r').read()).substitute({ 'what': device, 'where': config.get_external_disk_dir(), # 'type': fs_type, 'type': 'auto', 'options': options}) config = PlatformConfig() mount_filename = __dir_to_systemd_mount_filename(config.get_external_disk_dir()) with open(__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) __start(mount_filename)
def __init__(self): self.log = logger.get_logger('diaspora') self.app_dir = paths.get_app_dir(APP_NAME) self.app_data_dir = paths.get_data_dir(APP_NAME) self.app_url = urls.get_app_url(APP_NAME) self.app_domain_name = urls.get_app_domain_name(APP_NAME) self.platform_app_dir = paths.get_app_dir('platform') self.platform_data_dir = paths.get_data_dir('platform') self.device_domain_name = urls.get_device_domain_name() self.rails_env = 'production' self.gem_home = '{0}/ruby'.format(self.app_dir) self.path = '{0}/ruby/bin:{0}/nodejs/bin:{0}/ImageMagick/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'.format( self.app_dir) self.ld_library_path = '{0}/ruby/lib:{0}/ImageMagick/lib:{0}/postgresql/lib'.format( self.app_dir) self.rake_db_cmd = '{0}/bin/update_db'.format(self.app_dir) self.diaspora_dir = '{0}/diaspora'.format(self.app_dir) self.psql_bin = '{0}/postgresql/bin/psql'.format(self.app_dir) self.diaspora_config = '{0}/config/diaspora/diaspora.yml'.format( self.app_data_dir) self.database_path = '{0}/database'.format(self.app_data_dir) self.database_socket = '{0}/.s.PGSQL.{1}'.format( self.database_path, PSQL_PORT) self.database_path_escaped = self.database_path.replace("/", "%2F") self.database_url = "postgresql://*****:*****@{0}:{1}/diaspora?encoding=unicode".format( self.database_path_escaped, PSQL_PORT) self.diaspora_gemfile = '{0}/Gemfile'.format(self.diaspora_dir) environ['RAILS_ENV'] = self.rails_env environ['DB'] = DB_TYPE environ['GEM_HOME'] = self.gem_home environ['PATH'] = self.path environ['LD_LIBRARY_PATH'] = self.ld_library_path environ['DIASPORA_CONFIG_DIR'] = '{0}/config/diaspora'.format( self.app_data_dir) environ['DATABASE_URL'] = self.database_url environ['BUNDLE_GEMFILE'] = self.diaspora_gemfile
def __init__(self, platform_config, path_checker): self.platform_config = platform_config self.path_checker = path_checker self.log = logger.get_logger('lsblk')
def __init__(self, platform_config): self.platform_config = platform_config self.log = logger.get_logger('path_checker')
def __init__(self, platform_config, systemctl, device_info): self.systemctl = systemctl self.config = platform_config self.device_info = device_info self.log = logger.get_logger('nginx')
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
def __init__(self, upnp, fail_attempts=50): self.fail_attempts = fail_attempts self.logger = logger.get_logger('UpnpPortMapper') self.upnp_client = UpnpClient(upnp)
def __init__(self, platform_config): self.platform_config = platform_config self.cron = CronTab(user=self.platform_config.cron_user()) self.log = logger.get_logger('cron')
def reload_service(service): log = logger.get_logger('systemctl') log.info('reloading {0}'.format(service)) check_output('systemctl reload {0} 2>&1'.format(service), shell=True)
def __init__(self, manual_public_ip, manual_public_web_port): self.manual_public_web_port = manual_public_web_port self.manual_public_ip = manual_public_ip self.logger = logger.get_logger('ManualPortMapper')
def execute(self, sql): log = logger.get_logger('owncloud_postgres') log.info("executing: {0}".format(sql)) log.info(check_output('{0} -U {1} -d {2} -c "{3}"'.format(self.psql, self.user, self.database, sql), shell=True))
def __init__(self, platform_config): self.config = platform_config self.log = logger.get_logger('nginx')
shutil.rmtree(to_dir) for dir_name, subdirs, files in os.walk(from_dir): for filename in files: from_path = join(dir_name, filename) from_rel_path = relpath(from_path, from_dir) to_path = join(to_dir, from_rel_path) generate_file_jinja(from_path, to_path, variables, variable_tags) def makepath(path): if not isdir(path): makedirs(path) logger.init(logging.DEBUG, console=True, line_format='%(message)s') log = logger.get_logger('files') install_dir = os.environ['SNAP'] app_data = os.environ['SNAP_COMMON'] templates_path = join(install_dir, 'config.templates') config_dir = join(app_data, 'config') variables = { 'app_dir': install_dir, 'app_data': app_data } generate_files(templates_path, config_dir, variables) data_dirs = [ join(app_data, 'log'), join(app_data, 'nginx'),
def __init__(self, config_dir=None): self.filename = join(config_dir, PORT_CONFIG_NAME) self.logger = logger.get_logger('insider_port_config')
def __init__(self, redirect_api_url, update_token): self.redirect_api_url = redirect_api_url self.update_token = update_token self.logger = logger.get_logger('PortProber')
def __init__(self, platform_config, systemctl): self.systemctl = systemctl self.config = platform_config self.log = logger.get_logger('nginx')
def __init__(self): self.log = logger.get_logger('owncloud_installer') self.app = api.get_app_setup(APP_NAME)
def __init__(self, platform_config): self.platform_config = platform_config self.log = logger.get_logger('udev') self.from_path = join(self.platform_config.config_dir(), 'udev', udev_file_name) self.to_path = join(udev_dir, udev_file_name)
def __init__(self, user_platform_config, versions): self.versions = versions self.user_platform_config = user_platform_config self.logger = logger.get_logger('RedirectService')
def __init__(self, port): self.log = logger.get_logger('owncloud.setup.finish') self.port = port self.index_url = 'http://localhost:{}/index.php'.format(port)
def __init__(self): self.logger = logger.get_logger('NatPmpPortMapper')
def __init__(self, upnp): self.logger = logger.get_logger('UpnpClient') self.upnp = upnp self.initialized = False
def __init__(self): self.logger = logger.get_logger('NonePortDrill')
def __init__(self): self.log = logger.get_logger('diaspora.installer') self.app = api.get_app_setup(APP_NAME) self.device_domain_name = self.app.device_domain_name() self.app_domain_name = self.app.app_domain_name() self.app_dir = self.app.get_install_dir()
def __init__(self, platform_config, event_trigger, lsblk, path_checker): self.platform_config = platform_config self.event_trigger = event_trigger self.lsblk = lsblk self.path_checker = path_checker self.log = logger.get_logger('hardware')
def run(self, args): log = logger.get_logger('owncloud.occ') output = check_output('{0} {1}'.format(self.occ_runner_path, args), shell=True).strip() if output: log.info(output) return output
def __init__(self, platform_config): self.platform_config = platform_config self.log = logger.get_logger('systemctl')
def __init__(self, browser_config): self.log = logger.get_logger('browser') self.browser_config = browser_config self.www_root = self.browser_config.www_root()
def __init__(self, user_platform_config, version_func): self.user_platform_config = user_platform_config self.version_func = version_func self.logger = logger.get_logger('RedirectService')
def __init__(self, config_file): self.log = logger.get_logger('PlatformUserConfig') self.parser = ConfigParser() self.filename = config_file
def __init__(self, platform_config, info): self.info = info self.platform_config = platform_config self.logger = logger.get_logger('Snap')
def __init__(self): self.log = logger.get_logger('installer')
def __init__(self): self.log = logger.get_logger('diaspora.installer') self.config = Config() self.app = api.get_app_setup(APP_NAME)