def setup(self, name='simple', data='test', config=None, env='local'): helper.setenv(data=data) self.path = os.path.join(helper.PROJECT_PATH, name) self.env = env if config is None: config = {'path': self.path} return Config(config, env=env)
def main(_args): env_org = join(dir_scr, "_org", '.env') env_file = join(dir_scr, '.env') if _args.reset or not isfile(env_file): print("[info] init .env file.") shutil.copyfile(env_org, env_file) params = fn.getenv(env_file) fn.setparams( params, [ 'TZ', 'DOMAIN', 'PORT_EXTERNAL', # 'PORT_EXTERNAL2', 'MEM', ]) fn.setenv(params, env_file) for k, v in params.items(): print(f"{k}={v}")
def main(_args): print("----- redis env setting start.") env_org = join(dir_scr, "_org", '.env') env_file = join(dir_scr, '.env') nconf_org = join(dir_scr, "_org", 'default.conf') nconf_dst = join(dir_scr, "nginx", 'default.conf') netrc_org = join(dir_scr, "_org", '.netrc') netrc_dst = join(dir_scr, "django", '.netrc') if _args.reset or not isfile(env_file): print("[info] init .env file.") shutil.copyfile(env_org, env_file) params = fn.getenv(env_file) fn.setparams(params, [ 'TZ', 'APP_NAME', 'APP_DOMAIN', 'APP_PORT', ]) if fn.input_yn("get app source from git? (y/*) :"): fn.setparams(params, [ 'GIT_USER', 'GIT_TOKEN', 'GIT_REPO', 'GIT_BRANCH', ]) if fn.input_yn("use mysql databases? (y/*) :"): fn.setparams(params, [ 'MYSQL_MASTER_HOST', 'MYSQL_MASTER_PORT', 'MYSQL_SLAVE_HOST', 'MYSQL_SLAVE_PORT', 'MYSQL_ROOT_PASSWORD', 'MYSQL_USER_PASSWORD', ]) if fn.input_yn("use redis caches? (y/*) :"): fn.setparams(params, [ 'REDIS_MASTER_HOST', 'REDIS_MASTER_PORT', 'REDIS_MASTER_PASSWORD', ]) fn.setenv(params, env_file) fn.update_file(params, nconf_org, "___", nconf_dst) # netrcファイル作成 if params['GIT_REPO'] != "": # URLをパースする params['GIT_DOMAIN'] = urlparse(params['GIT_REPO']).netloc.replace( "www.", "") fn.update_file(params, netrc_org, "___", netrc_dst) for k, v in params.items(): print(f"{k}={v}")
def setUp(self): helper.setenv() def execl(*args): self.args = args utils.os.execl = execl self.p = helper.project()
def setUp(self): helper.setenv() def execl(*args): self.args = args utils.os.execl = execl self.old_stdout = sys.stdout self.old_stderr = sys.stderr self.stdout = sys.stdout = StringIO() self.stderr = sys.stderr = StringIO()
def main(_args): print("----- redis env setting start.") env_org = join(dir_scr, "_org", '.env') env_file = join(dir_scr, '.env') nconf_org = join(dir_scr, "_org", 'default.conf') nconf_dst = join(dir_scr, "nginx", 'default.conf') netrc_org = join(dir_scr, "_org", '.netrc') netrc_dst = join(dir_scr, "php", '.netrc') if _args.reset or not isfile(env_file): print("[info] init .env file.") shutil.copyfile(env_org, env_file) params = fn.getenv(env_file) req_keys = [ 'TZ', 'APP_NAME', 'APP_DOMAIN', 'APP_PORT', 'PORT_INTERNAL', ] _input = input("get app source from git. ok? (y/*) :").lower() if _input in ["y", "yes"]: req_keys.append('GIT_USER') req_keys.append('GIT_TOKEN') req_keys.append('GIT_REPO') req_keys.append('GIT_BRANCH') else: req_keys.append('LARAVEL_VER') fn.setparams(params, req_keys) fn.setenv(params, env_file) fn.update_file(params, nconf_org, "___", nconf_dst) if params['GIT_REPO'] != "": # URLをパースする params['GIT_DOMAIN'] = urlparse(params['GIT_REPO']).netloc.replace( "www.", "") fn.update_file(params, netrc_org, "___", netrc_dst) for k, v in params.items(): print(f"{k}={v}")
def main(_args): print("----- redis env setting start.") env_org = join(dir_scr, "_org", '.env') env_file = join(dir_scr, '.env') if _args.reset or not isfile(env_file): print("[info] init .env file.") shutil.copyfile(env_org, env_file) params = fn.getenv(env_file) fn.setparams(params, [ 'PORT_EXTERNAL', 'MEM', 'MEM_DB', ]) fn.setenv(params, env_file)
def main(_args): print("----- redis env setting start.") env_file = join(dir_scr, '.env') env_org = join(dir_scr, "_org", '.env') if not isfile(env_file): shutil.copyfile(env_org, env_file) params = fn.getenv(env_file) if _args.node == 'master': if params['MASTER_PASS'] == "": params['MASTER_PASS'] = fn.randstr(30) req_keys = [ 'TZ', 'MASTER_PORT', 'MASTER_PASS', 'MEM', ] fn.setparams(params, req_keys) if params['SLAVE_PASS'] == "": params['SLAVE_PASS'] = params['MASTER_PASS'] if params['SLAVE_PORT'] == params['MASTER_PORT']: params['SLAVE_PORT'] = str(int(params['MASTER_PORT']) + 1) params['MASTER_HOST'] = fn.local_ip() elif _args.node == 'slave': if params['SLAVE_PASS'] == "": params['SLAVE_PASS'] = fn.randstr(30) req_keys = [ 'TZ', 'SLAVE_PORT', 'SLAVE_PASS', 'MASTER_HOST', 'MASTER_PORT', 'MASTER_PASS', 'MEM', ] fn.setparams(params, req_keys) params['SLAVE_HOST'] = fn.local_ip() params['NODE'] = _args.node fn.setenv(params, env_file) for k, v in params.items(): print(f"{k}={v}")
def setUp(self): helper.setenv()
def main(_args): print("----- mysql setting start.") env_dst = join(dir_scr, '.env') env_org = join(dir_scr, "_org", '.env') if not isfile(env_dst): shutil.copyfile(env_org, env_dst) params = fn.getenv(env_dst) if params['MYSQL_ROOT_PASSWORD'] == "": params['MYSQL_ROOT_PASSWORD'] = fn.randstr(30) if params['MYSQL_REP_PASSWORD'] == "": params['MYSQL_REP_PASSWORD'] = fn.randstr(30) if params['MYSQL_USER_PASSWORD'] == "": params['MYSQL_USER_PASSWORD'] = fn.randstr(30) req_keys = [ 'TZ', 'MYSQL_ROOT_PASSWORD', 'MYSQL_REP_PASSWORD', 'MYSQL_USER_PASSWORD', 'MEM', ] if _args.node == 'master': req_keys.append('MASTER_PORT') req_keys.append('MASTER_SERVER_ID') params['MASTER_HOST'] = fn.local_ip() elif _args.node == 'slave': req_keys.append('SLAVE_PORT') req_keys.append('SLAVE_SERVER_ID') req_keys.append('MASTER_HOST') req_keys.append('MASTER_PORT') fn.setparams(params, req_keys) params['NODE'] = _args.node fn.setenv(params, env_dst) # confのコピー for ref in ["master", "slave"]: conf_org = join(dir_scr, '_org', 'conf', ref, 'rep.cnf') dir_conf = join(dir_scr, 'mnt', 'conf', ref) if not isdir(dir_conf): os.makedirs(dir_conf) fn.update_file(params, conf_org, '___', join(dir_conf, 'rep.cnf')) # fn.chmodr(dir_conf, 0o644) # fn.chownr(dir_conf, "root", "root") # mysqlのログイン用ファイルコピー users = ["root", "rep", "user"] dir_opt_org = join(dir_scr, '_org', 'opt') dir_opt = join(dir_scr, 'mnt', 'common', 'opt') if not isdir(dir_opt): os.makedirs(dir_opt) for user in users: opt_org = join(dir_opt_org, f".opt{user}") opt_dst = join(dir_opt, f".opt{user}") fn.update_file(params, opt_org, '___', opt_dst) # fn.chmodr(dir_opt, 0o644) # fn.chownr(dir_opt, "root", "root") for k,v in params.items(): print(f"{k}={v}")
def main(_args): """ initialize container """ env_dst = join(dir_scr, "..", '.env') envs = fn.getenv(env_dst) node = envs["NODE"] if not _args.node is None: node = _args.node if node == "": print(f"[error] node type not set.") sys.exit() container = f"node-mysql-{node}" dk_cmd = f"docker exec -it {container}" mysql_cmd = f"{dk_cmd} mysql {envs['OPTROOT']}" master_host = f"{envs['MASTER_HOST']} : {envs['MASTER_PORT']}" if node == "slave": # デタッチ処理 if fn.input_yn(f"\ndetach from master[ {master_host} ]. ok? (y/*) :"): print(f"\n---------- detach from [ {master_host} ] start") cmds = [ f"{mysql_cmd} -e 'STOP SLAVE'", f"{mysql_cmd} -e 'RESET SLAVE'", ] for line in rp.cmdrun(_cmd=cmds, _encode="utf8"): sys.stdout.write(line) # リストア対象の指定 dir_dump = abspath(join(dir_base, "vol", node, "dump")) print("\n----- dump directories") for ref in os.listdir(dir_dump): if isdir(join(dir_dump, ref)): print(ref) _input = input("\nrequire restore target dump directry. (empty to skip):") dir_dump_ref = join(dir_dump, _input) if _input != "": if not isdir(dir_dump_ref): print("[error] restore target none.") sys.exit() path_dump = f"/tmp/dump/{_input}/bin.dump" path_dump_ref = join(dir_dump_ref, "bin.dump") # リストア処理 print(f"\n---------- restore to {container} start") cmds = [ f"{mysql_cmd} -e 'SET PERSIST innodb_flush_log_at_trx_commit = 0'", f"{mysql_cmd} -e 'SET PERSIST sync_binlog = 0'", ] for line in rp.cmdrun(_cmd=cmds): sys.stdout.write(line) cmds = [f"{dk_cmd} bash -c 'mysql {envs['OPTROOT']} < {path_dump}'"] for line in rp.cmdrun(_cmd=cmds, _encode="utf8"): sys.stdout.write(line) cmds = [ f"{mysql_cmd} -e 'SET PERSIST innodb_flush_log_at_trx_commit = 1'", f"{mysql_cmd} -e 'SET PERSIST sync_binlog = 1'", ] for line in rp.cmdrun(_cmd=cmds): sys.stdout.write(line) path_status = join(dir_dump_ref, "status.txt") status_cmd = "" with open(path_status) as f: status_cmd = f.read() spl_status = status_cmd.split(" ") for st in spl_status: if "MASTER_LOG_FILE" in st: envs['REP_FILE'] = st.replace(",", "") if "MASTER_LOG_POS" in st: envs['REP_POS'] = st.replace(",", "") fn.setenv(envs, env_dst) print(f"\n---------- restore to {container} end") # アタッチ処理 if node == "slave": if fn.input_yn(f"\nattach to master[ {master_host} ]. ok? (y/*) :"): print(f"\n---------- attach to [ {master_host} ] start") cmd = f"{mysql_cmd} -e \"\ CHANGE MASTER TO \ {envs['REP_FILE']}, \ {envs['REP_POS']}, \ MASTER_HOST='{envs['MASTER_HOST']}', \ MASTER_PORT={envs['MASTER_PORT']}, \ MASTER_USER='******', \ MASTER_PASSWORD='******'MYSQL_REP_PASSWORD']}';\ \"" for line in rp.cmdrun(_cmd=[cmd], _encode="utf8"): sys.stdout.write(line) cmds = [ f"{dk_cmd} bash -c \"mysql {envs['OPTROOT']} -e 'START SLAVE;'\"", ] for line in rp.cmdrun(_cmd=cmds, _encode="utf8"): sys.stdout.write(line)