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 wait_for_unicorn(delay=2, retries=20): config = Config(environ["SNAP_COMMON"]) retry = 0 while retry < retries: unicorn_url = 'http://localhost:{0}'.format(config.unicorn_port()) try: response = requests.get(unicorn_url, allow_redirects=False) print('response.status_code: {0}'.format(response.status_code)) if response.status_code == 302: return True except Exception, e: print(e.message) print('unable to {0}'.format(unicorn_url)) retry += 1 time.sleep(delay)
def install(self): linux.fix_locale() linux.useradd(USER_NAME) self.log.info(fs.chownpath(self.app.get_install_dir(), USER_NAME, recursive=True)) app_data_dir = self.app.get_data_dir() database_path = '{0}/database'.format(app_data_dir) variables = { 'app_dir': self.app_dir, 'app_data_dir': app_data_dir, 'db_psql_path': database_path, 'db_psql_port': PSQL_PORT, 'db_name': DB_NAME, 'db_user': DB_USER, 'db_password': DB_PASS } templates_path = join(self.app_dir, 'config.templates') config_path = join(app_data_dir, 'config') gen.generate_files(templates_path, config_path, variables) fs.makepath(join(app_data_dir, 'config')) fs.makepath(join(app_data_dir, 'redis')) fs.makepath(join(app_data_dir, 'log')) fs.makepath(join(app_data_dir, 'nginx')) fs.chownpath(app_data_dir, USER_NAME, recursive=True) self.log.info("setup systemd") user_config = UserConfig(app_data_dir) is_first_time = not user_config.is_activated() if is_first_time: database_init(self.log, self.app_dir, app_data_dir, database_path, USER_NAME) self.app.add_service(SYSTEMD_POSTGRESQL) config = Config(app_data_dir) symlink(join(config_path, 'diaspora', 'diaspora.yml'), join(self.app_dir, 'diaspora', 'config', 'diaspora.yml')) symlink(join(config_path, 'diaspora', 'database.yml'), join(self.app_dir, 'diaspora', 'config', 'database.yml')) self.update_configuraiton(config) if is_first_time: self.initialize(app_data_dir, config) self.log.info(fs.chownpath(self.app_dir, USER_NAME, recursive=True)) self.app.add_service(SYSTEMD_REDIS) self.app.add_service(SYSTEMD_SIDEKIQ) self.app.add_service(SYSTEMD_UNICORN) self.app.add_service(SYSTEMD_NGINX_NAME) self.app.init_storage(USER_NAME)
def __init__(self): self.log = logger.get_logger('diaspora.installer') self.config = Config() self.app = api.get_app_setup(APP_NAME)
class DiasporaInstaller: def __init__(self): self.log = logger.get_logger('diaspora.installer') self.config = Config() self.app = api.get_app_setup(APP_NAME) def install(self): linux.fix_locale() linux.useradd(USER_NAME) self.log.info(fs.chownpath(self.app.get_install_dir(), USER_NAME, recursive=True)) app_data_dir = self.app.get_data_dir() fs.makepath(join(app_data_dir, 'config')) fs.makepath(join(app_data_dir, 'postgresql')) fs.makepath(join(app_data_dir, 'redis')) fs.makepath(join(app_data_dir, 'log')) fs.makepath(join(app_data_dir, 'nginx')) fs.chownpath(app_data_dir, USER_NAME, recursive=True) print("setup systemd") self.app.add_service(SYSTEMD_POSTGRESQL) self.update_configuraiton() if not UserConfig().is_installed(): self.initialize() #self.recompile_assets() self.log.info(fs.chownpath(self.config.install_path(), USER_NAME, recursive=True)) self.app.add_service(SYSTEMD_REDIS) self.app.add_service(SYSTEMD_SIDEKIQ) self.app.add_service(SYSTEMD_UNICORN) self.app.add_service(SYSTEMD_NGINX_NAME) self.app.init_storage(USER_NAME) self.app.register_web(self.config.port()) def remove(self): self.app.unregister_web() self.app.remove_service(SYSTEMD_NGINX_NAME) self.app.remove_service(SYSTEMD_UNICORN) self.app.remove_service(SYSTEMD_SIDEKIQ) self.app.remove_service(SYSTEMD_REDIS) self.app.remove_service(SYSTEMD_POSTGRESQL) if isdir(self.config.install_path()): shutil.rmtree(self.config.install_path()) def initialize(self): print("initialization") postgres.execute("ALTER USER {0} WITH PASSWORD '{0}';".format(self.config.app_name()), database="postgres") self.environment() print(check_output(self.config.rake_db_cmd(), shell=True, cwd=self.config.diaspora_dir())) UserConfig().set_activated(True) def environment(self): environ['RAILS_ENV'] = self.config.rails_env() environ['DB'] = self.config.db() environ['GEM_HOME'] = self.config.gem_home() environ['PATH'] = self.config.path() def update_domain(self): self.update_configuraiton() self.recompile_assets() #def recompile_assets(self): # self.environment() # print(check_output(self.config.rake_assets(), shell=True, cwd=self.config.diaspora_dir())) def update_configuraiton(self): url = self.app.app_url() config = yaml.load(open(self.config.diaspora_config())) config['configuration']['environment']['url'] = url config['configuration']['environment']['assets']['host'] = url yaml.dump(config, open(self.config.diaspora_config(), 'w'))
#!/opt/app/platform/python/bin/python from os import environ, listdir from os.path import dirname, join, abspath, isdir from subprocess import check_output import sys app_path = abspath(join(dirname(__file__), '..', '..', 'diaspora')) lib_path = join(app_path, 'lib') libs = [join(lib_path, item) for item in listdir(lib_path) if isdir(join(lib_path, item))] map(sys.path.append, libs) from diaspora.config import Config config = Config() environ['RAILS_ENV'] = config.rails_env() environ['DB'] = config.db() environ['GEM_HOME'] = config.gem_home() environ['PATH'] = config.path() environ['LD_LIBRARY_PATH'] = config.ld_library_path() print(check_output(config.unicorn_cmd(), shell=True, cwd=config.diaspora_dir()))
#!/opt/app/platform/python/bin/python from os import environ, listdir from os.path import dirname, join, abspath, isdir from subprocess import check_output import sys app_path = abspath(join(dirname(__file__), '..', '..', 'diaspora')) lib_path = join(app_path, 'lib') libs = [ join(lib_path, item) for item in listdir(lib_path) if isdir(join(lib_path, item)) ] map(sys.path.append, libs) from diaspora.config import Config config = Config(environ['SNAP_COMMON']) environ['RAILS_ENV'] = config.rails_env() environ['DB'] = config.db() environ['GEM_HOME'] = config.gem_home() environ['PATH'] = config.path() environ['LD_LIBRARY_PATH'] = config.ld_library_path() print(check_output(config.unicorn_cmd(), shell=True, cwd=config.diaspora_dir()))