if svcuser > "" and svcuser != curr_user: batcmd = "sudo su - " + svcuser + " -c '" + batcmd + "'" print(' ' + batcmd) err = os.system(batcmd) if err: msg = "ERROR: Unable to Initialize PG. see logfile: " + logfile fatal_error(msg) util.set_column('datadir', pgver, pg_data) util.set_column('svcuser', pgver, svcuser) util.set_column('logdir', pgver, pg_log) util.update_postgresql_conf(pgver, i_port, update_listen_addr=is_password) if is_password: pg_pass_file = util.remember_pgpassword(pg_password, str(i_port)) else: pg_pass_file = None util.write_pgenv_file(pg_home, pgver, pg_data, 'postgres', 'postgres', str(i_port), pg_pass_file) if is_password: src_dir = pg_home + os.sep + "init" + os.sep shutil.copy(src_dir + "pg_hba.conf", pg_data) os.remove(pgpass_file) if isJson:
jsonMsg['status'] = "error" jsonMsg['component'] = pgver jsonMsg['msg'] = msg print(json.dumps([jsonMsg])) else: print(msg) sys.exit(0) ## DATADIR, PORT , LOGDIR & SVCNAME ########################### if args.datadir > '': util.set_column("datadir", pgver, args.datadir) ## PORT ################################################ if args.port > 0: rc = util.update_postgresql_conf(pgver, args.port, False) if rc > 0: sys.exit(rc) if args.logdir > '': util.set_column("logdir", pgver, args.logdir) else: ## DATA ############################################### data_root = os.path.join(MY_HOME, "data") if not os.path.isdir(data_root): os.mkdir(data_root) ## LOGS ############################################### data_root_logs = os.path.join(data_root, "logs") if not os.path.isdir(data_root_logs): os.mkdir(data_root_logs)