in mysqloperator/init_main.py [0:0]
def main(argv):
# const - when there is an argument without value
# default - when there is no argument at all
# nargs = "?" - zero or one arguments
# nargs = "+" - one or more arguments, returns a list()
# nargs = 8 - 8 arguments will be consumed
# nargs = 1 - 1 argument will be consumed, returns a list with one element
parser = argparse.ArgumentParser(description = "MySQL InnoDB Cluster Instance Sidecar Container")
parser.add_argument('--logging-level', type = int, nargs="?", default = logging.INFO, help = "Logging Level")
parser.add_argument('--pod-name', type = str, nargs=1, default=None, help = "Pod Name")
parser.add_argument('--pod-namespace', type = str, nargs=1, default=None, help = "Pod Namespace")
parser.add_argument('--datadir', type = str, default = "/var/lib/mysql", help = "Path do data directory")
args = parser.parse_args(argv)
datadir = args.datadir
mysqlsh.globals.shell.options.useWizards = False
logging.basicConfig(level=args.logging_level,
format='%(asctime)s - [%(levelname)s] [%(name)s] %(message)s',
datefmt="%Y-%m-%dT%H:%M:%S")
logger = logging.getLogger("initmysql")
name = args.pod_name[0] # nargs returns a list
namespace = args.pod_namespace[0] # nargs returns a list
logger.info(f"Configuring mysql pod {namespace}/{name}, datadir={datadir}")
utils.log_banner(__file__, logger)
if logger.level == logging.DEBUG:
logger.debug(f"Initial contents of {datadir}:")
subprocess.run(["ls", "-l", datadir])
logger.debug("Initial contents of /mnt:")
subprocess.run(["ls", "-lR", "/mnt"])
try:
pod = MySQLPod.read(name, namespace)
cluster = pod.get_cluster()
init_conf(datadir, pod, cluster, logger)
init_meb_restore(pod, cluster, logger)
except Exception as e:
import traceback
traceback.print_exc()
logger.critical(f"Unhandled exception while bootstrapping MySQL: {e}")
# TODO post event to the Pod and the Cluster object if this is the seed
return 1
# TODO support for restoring from clone snapshot or MEB goes in here
return 0