moonraker: remove alias option
Differentiate instances based on the data path provided. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
c3cd24b3bf
commit
41ea45a486
@ -238,7 +238,6 @@ class MoonrakerApp:
|
|||||||
path: Optional[str] = config.get(option, None, deprecate=True)
|
path: Optional[str] = config.get(option, None, deprecate=True)
|
||||||
app_args = self.server.get_app_args()
|
app_args = self.server.get_app_args()
|
||||||
data_path = app_args["data_path"]
|
data_path = app_args["data_path"]
|
||||||
alias = app_args["alias"]
|
|
||||||
certs_path = pathlib.Path(data_path).joinpath("certs")
|
certs_path = pathlib.Path(data_path).joinpath("certs")
|
||||||
if not certs_path.exists():
|
if not certs_path.exists():
|
||||||
try:
|
try:
|
||||||
@ -246,7 +245,7 @@ class MoonrakerApp:
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
ext = "key" if "key" in option else "cert"
|
ext = "key" if "key" in option else "cert"
|
||||||
item = certs_path.joinpath(f"{alias}.{ext}")
|
item = certs_path.joinpath(f"moonraker.{ext}")
|
||||||
if item.exists() or path is None:
|
if item.exists() or path is None:
|
||||||
return item
|
return item
|
||||||
item = pathlib.Path(path).expanduser().resolve()
|
item = pathlib.Path(path).expanduser().resolve()
|
||||||
|
@ -82,7 +82,6 @@ class MoonrakerDatabase:
|
|||||||
dep_path = config.get("database_path", None, deprecate=True)
|
dep_path = config.get("database_path", None, deprecate=True)
|
||||||
db_path = pathlib.Path(app_args["data_path"]).joinpath("database")
|
db_path = pathlib.Path(app_args["data_path"]).joinpath("database")
|
||||||
if (
|
if (
|
||||||
app_args["is_default_alias"] and
|
|
||||||
app_args["is_default_data_path"] and
|
app_args["is_default_data_path"] and
|
||||||
not (dep_path is None and db_path.exists())
|
not (dep_path is None and db_path.exists())
|
||||||
):
|
):
|
||||||
|
@ -69,6 +69,9 @@ class FileManager:
|
|||||||
db_path = db.get_database_path()
|
db_path = db.get_database_path()
|
||||||
self.add_reserved_path("database", db_path, False)
|
self.add_reserved_path("database", db_path, False)
|
||||||
self.add_reserved_path("certs", self.datapath.joinpath("certs"), False)
|
self.add_reserved_path("certs", self.datapath.joinpath("certs"), False)
|
||||||
|
self.add_reserved_path(
|
||||||
|
"systemd", self.datapath.joinpath("systemd"), False
|
||||||
|
)
|
||||||
self.gcode_metadata = MetadataStorage(config, db)
|
self.gcode_metadata = MetadataStorage(config, db)
|
||||||
self.inotify_handler = INotifyHandler(config, self,
|
self.inotify_handler = INotifyHandler(config, self,
|
||||||
self.gcode_metadata)
|
self.gcode_metadata)
|
||||||
|
@ -1184,7 +1184,6 @@ class InstallValidator:
|
|||||||
app_args = self.server.get_app_args()
|
app_args = self.server.get_app_args()
|
||||||
self.data_path = pathlib.Path(app_args["data_path"])
|
self.data_path = pathlib.Path(app_args["data_path"])
|
||||||
self._update_backup_path()
|
self._update_backup_path()
|
||||||
self.alias = app_args["alias"]
|
|
||||||
self.data_path_valid = True
|
self.data_path_valid = True
|
||||||
self._sudo_requested = False
|
self._sudo_requested = False
|
||||||
self.announcement_id = ""
|
self.announcement_id = ""
|
||||||
@ -1269,13 +1268,15 @@ class InstallValidator:
|
|||||||
"Unable to retrieve service unit name. Service file "
|
"Unable to retrieve service unit name. Service file "
|
||||||
"must be updated manually."
|
"must be updated manually."
|
||||||
)
|
)
|
||||||
if unit != self.alias and self.alias == "moonraker":
|
if unit != "moonraker":
|
||||||
# alias differs from unit name, current alias is set to default
|
# Not using he default unit name
|
||||||
self.alias = unit
|
|
||||||
if app_args["is_default_data_path"]:
|
if app_args["is_default_data_path"]:
|
||||||
# Using default datapath, switch to alias based path to
|
# No datapath set, create a new, unique data path
|
||||||
# avoid conflict
|
df = f"~/{unit}_data"
|
||||||
new_dp = pathlib.Path(f"~/{unit}_data").expanduser().resolve()
|
match = re.match(r"moonraker[-_]?(\d+)", unit)
|
||||||
|
if match is not None:
|
||||||
|
df = f"~/printer_{match.group(1)}_data"
|
||||||
|
new_dp = pathlib.Path(df).expanduser().resolve()
|
||||||
if new_dp.exists() and not self._check_path_bare(new_dp):
|
if new_dp.exists() and not self._check_path_bare(new_dp):
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
f"Cannot resolve data path for custom unit '{unit}', "
|
f"Cannot resolve data path for custom unit '{unit}', "
|
||||||
@ -1308,8 +1309,11 @@ class InstallValidator:
|
|||||||
).joinpath(f"{unit}-tmp.svc")
|
).joinpath(f"{unit}-tmp.svc")
|
||||||
src_path = pathlib.Path(MOONRAKER_PATH)
|
src_path = pathlib.Path(MOONRAKER_PATH)
|
||||||
# Create local environment file
|
# Create local environment file
|
||||||
env_file = src_path.joinpath(f"{unit}.env")
|
sysd_data = self.data_path.joinpath("systemd")
|
||||||
cmd_args = f"-a {unit} -d {self.data_path}"
|
if not sysd_data.exists():
|
||||||
|
sysd_data.mkdir()
|
||||||
|
env_file = sysd_data.joinpath("moonraker.env")
|
||||||
|
cmd_args = f"-d {self.data_path}"
|
||||||
cfg_file = pathlib.Path(app_args["config_file"])
|
cfg_file = pathlib.Path(app_args["config_file"])
|
||||||
fm: FileManager = self.server.lookup_component("file_manager")
|
fm: FileManager = self.server.lookup_component("file_manager")
|
||||||
cfg_path = fm.get_directory("config")
|
cfg_path = fm.get_directory("config")
|
||||||
@ -1347,7 +1351,7 @@ class InstallValidator:
|
|||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
await machine.exec_sudo_command(f"cp -f {tmp_svc} {svc_dest}")
|
await machine.exec_sudo_command(f"cp -f {tmp_svc} {svc_dest}")
|
||||||
await machine.exec_sudo_command(f"systemctl daemon-reload")
|
await machine.exec_sudo_command("systemctl daemon-reload")
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
raise
|
raise
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -1492,7 +1496,7 @@ class InstallValidator:
|
|||||||
# Link individual files
|
# Link individual files
|
||||||
secrets_path = self.config["secrets"].get("secrets_path", None)
|
secrets_path = self.config["secrets"].get("secrets_path", None)
|
||||||
if secrets_path is not None:
|
if secrets_path is not None:
|
||||||
secrets_dest = self.data_path.joinpath(f"{self.alias}.secrets")
|
secrets_dest = self.data_path.joinpath("moonraker.secrets")
|
||||||
self._link_data_file(secrets_dest, secrets_path)
|
self._link_data_file(secrets_dest, secrets_path)
|
||||||
cfg_source.remove_option("secrets", "secrets_path")
|
cfg_source.remove_option("secrets", "secrets_path")
|
||||||
certs_path = self.data_path.joinpath("certs")
|
certs_path = self.data_path.joinpath("certs")
|
||||||
@ -1500,12 +1504,12 @@ class InstallValidator:
|
|||||||
certs_path.mkdir()
|
certs_path.mkdir()
|
||||||
ssl_cert = server_cfg.get("ssl_certificate_path", None)
|
ssl_cert = server_cfg.get("ssl_certificate_path", None)
|
||||||
if ssl_cert is not None:
|
if ssl_cert is not None:
|
||||||
cert_dest = certs_path.joinpath(f"{self.alias}.cert")
|
cert_dest = certs_path.joinpath("moonraker.cert")
|
||||||
self._link_data_file(cert_dest, ssl_cert)
|
self._link_data_file(cert_dest, ssl_cert)
|
||||||
cfg_source.remove_option("server", "ssl_certificate_path")
|
cfg_source.remove_option("server", "ssl_certificate_path")
|
||||||
ssl_key = server_cfg.get("ssl_key_path", None)
|
ssl_key = server_cfg.get("ssl_key_path", None)
|
||||||
if ssl_key is not None:
|
if ssl_key is not None:
|
||||||
key_dest = certs_path.joinpath(f"{self.alias}.key")
|
key_dest = certs_path.joinpath("moonraker.key")
|
||||||
self._link_data_file(key_dest, ssl_key)
|
self._link_data_file(key_dest, ssl_key)
|
||||||
cfg_source.remove_option("server", "ssl_key_path")
|
cfg_source.remove_option("server", "ssl_key_path")
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -24,9 +24,8 @@ class Secrets:
|
|||||||
self.secrets_file: Optional[pathlib.Path] = None
|
self.secrets_file: Optional[pathlib.Path] = None
|
||||||
path: Optional[str] = config.get("secrets_path", None, deprecate=True)
|
path: Optional[str] = config.get("secrets_path", None, deprecate=True)
|
||||||
app_args = server.get_app_args()
|
app_args = server.get_app_args()
|
||||||
alias = app_args["alias"]
|
|
||||||
data_path = app_args["data_path"]
|
data_path = app_args["data_path"]
|
||||||
fpath = pathlib.Path(data_path).joinpath(f"{alias}.secrets")
|
fpath = pathlib.Path(data_path).joinpath("moonraker.secrets")
|
||||||
if not fpath.is_file() and path is not None:
|
if not fpath.is_file() and path is not None:
|
||||||
fpath = pathlib.Path(path).expanduser().resolve()
|
fpath = pathlib.Path(path).expanduser().resolve()
|
||||||
self.type = "invalid"
|
self.type = "invalid"
|
||||||
|
@ -438,8 +438,7 @@ class Server:
|
|||||||
|
|
||||||
def main(cmd_line_args: argparse.Namespace) -> None:
|
def main(cmd_line_args: argparse.Namespace) -> None:
|
||||||
startup_warnings: List[str] = []
|
startup_warnings: List[str] = []
|
||||||
alias: str = cmd_line_args.alias or "moonraker"
|
dp: str = cmd_line_args.datapath or "~/printer_data"
|
||||||
dp: str = cmd_line_args.datapath or f"~/{alias}_data"
|
|
||||||
data_path = pathlib.Path(dp).expanduser().resolve()
|
data_path = pathlib.Path(dp).expanduser().resolve()
|
||||||
if not data_path.exists():
|
if not data_path.exists():
|
||||||
try:
|
try:
|
||||||
@ -451,11 +450,9 @@ def main(cmd_line_args: argparse.Namespace) -> None:
|
|||||||
if cmd_line_args.configfile is not None:
|
if cmd_line_args.configfile is not None:
|
||||||
cfg_file: str = cmd_line_args.configfile
|
cfg_file: str = cmd_line_args.configfile
|
||||||
else:
|
else:
|
||||||
cfg_file = str(data_path.joinpath(f"config/{alias}.conf"))
|
cfg_file = str(data_path.joinpath("config/moonraker.conf"))
|
||||||
app_args = {
|
app_args = {
|
||||||
"alias": alias,
|
|
||||||
"data_path": str(data_path),
|
"data_path": str(data_path),
|
||||||
"is_default_alias": cmd_line_args.alias is None,
|
|
||||||
"is_default_data_path": cmd_line_args.datapath is None,
|
"is_default_data_path": cmd_line_args.datapath is None,
|
||||||
"config_file": cfg_file,
|
"config_file": cfg_file,
|
||||||
"startup_warnings": startup_warnings
|
"startup_warnings": startup_warnings
|
||||||
@ -469,7 +466,7 @@ def main(cmd_line_args: argparse.Namespace) -> None:
|
|||||||
app_args["log_file"] = os.path.normpath(
|
app_args["log_file"] = os.path.normpath(
|
||||||
os.path.expanduser(cmd_line_args.logfile))
|
os.path.expanduser(cmd_line_args.logfile))
|
||||||
else:
|
else:
|
||||||
app_args["log_file"] = str(data_path.joinpath(f"logs/{alias}.log"))
|
app_args["log_file"] = str(data_path.joinpath("logs/moonraker.log"))
|
||||||
app_args["software_version"] = version
|
app_args["software_version"] = version
|
||||||
app_args["python_version"] = sys.version.replace("\n", " ")
|
app_args["python_version"] = sys.version.replace("\n", " ")
|
||||||
ql, file_logger, warning = utils.setup_logging(app_args)
|
ql, file_logger, warning = utils.setup_logging(app_args)
|
||||||
@ -537,10 +534,6 @@ if __name__ == '__main__':
|
|||||||
# Parse start arguments
|
# Parse start arguments
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="Moonraker - Klipper API Server")
|
description="Moonraker - Klipper API Server")
|
||||||
parser.add_argument(
|
|
||||||
"-a", "--alias", default=None, metavar="<alias>",
|
|
||||||
help="Alternate name of instance"
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-d", "--datapath", default=None,
|
"-d", "--datapath", default=None,
|
||||||
metavar='<data path>',
|
metavar='<data path>',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user