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:
Eric Callahan 2022-08-30 10:08:06 -04:00 committed by Eric Callahan
parent c3cd24b3bf
commit 41ea45a486
6 changed files with 25 additions and 28 deletions

View File

@ -238,7 +238,6 @@ class MoonrakerApp:
path: Optional[str] = config.get(option, None, deprecate=True)
app_args = self.server.get_app_args()
data_path = app_args["data_path"]
alias = app_args["alias"]
certs_path = pathlib.Path(data_path).joinpath("certs")
if not certs_path.exists():
try:
@ -246,7 +245,7 @@ class MoonrakerApp:
except Exception:
pass
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:
return item
item = pathlib.Path(path).expanduser().resolve()

View File

@ -82,7 +82,6 @@ class MoonrakerDatabase:
dep_path = config.get("database_path", None, deprecate=True)
db_path = pathlib.Path(app_args["data_path"]).joinpath("database")
if (
app_args["is_default_alias"] and
app_args["is_default_data_path"] and
not (dep_path is None and db_path.exists())
):

View File

@ -69,6 +69,9 @@ class FileManager:
db_path = db.get_database_path()
self.add_reserved_path("database", db_path, 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.inotify_handler = INotifyHandler(config, self,
self.gcode_metadata)

View File

@ -1184,7 +1184,6 @@ class InstallValidator:
app_args = self.server.get_app_args()
self.data_path = pathlib.Path(app_args["data_path"])
self._update_backup_path()
self.alias = app_args["alias"]
self.data_path_valid = True
self._sudo_requested = False
self.announcement_id = ""
@ -1269,13 +1268,15 @@ class InstallValidator:
"Unable to retrieve service unit name. Service file "
"must be updated manually."
)
if unit != self.alias and self.alias == "moonraker":
# alias differs from unit name, current alias is set to default
self.alias = unit
if unit != "moonraker":
# Not using he default unit name
if app_args["is_default_data_path"]:
# Using default datapath, switch to alias based path to
# avoid conflict
new_dp = pathlib.Path(f"~/{unit}_data").expanduser().resolve()
# No datapath set, create a new, unique data path
df = f"~/{unit}_data"
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):
raise ValidationError(
f"Cannot resolve data path for custom unit '{unit}', "
@ -1308,8 +1309,11 @@ class InstallValidator:
).joinpath(f"{unit}-tmp.svc")
src_path = pathlib.Path(MOONRAKER_PATH)
# Create local environment file
env_file = src_path.joinpath(f"{unit}.env")
cmd_args = f"-a {unit} -d {self.data_path}"
sysd_data = self.data_path.joinpath("systemd")
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"])
fm: FileManager = self.server.lookup_component("file_manager")
cfg_path = fm.get_directory("config")
@ -1347,7 +1351,7 @@ class InstallValidator:
)
try:
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:
raise
except Exception:
@ -1492,7 +1496,7 @@ class InstallValidator:
# Link individual files
secrets_path = self.config["secrets"].get("secrets_path", 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)
cfg_source.remove_option("secrets", "secrets_path")
certs_path = self.data_path.joinpath("certs")
@ -1500,12 +1504,12 @@ class InstallValidator:
certs_path.mkdir()
ssl_cert = server_cfg.get("ssl_certificate_path", 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)
cfg_source.remove_option("server", "ssl_certificate_path")
ssl_key = server_cfg.get("ssl_key_path", 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)
cfg_source.remove_option("server", "ssl_key_path")
except Exception:

View File

@ -24,9 +24,8 @@ class Secrets:
self.secrets_file: Optional[pathlib.Path] = None
path: Optional[str] = config.get("secrets_path", None, deprecate=True)
app_args = server.get_app_args()
alias = app_args["alias"]
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:
fpath = pathlib.Path(path).expanduser().resolve()
self.type = "invalid"

View File

@ -438,8 +438,7 @@ class Server:
def main(cmd_line_args: argparse.Namespace) -> None:
startup_warnings: List[str] = []
alias: str = cmd_line_args.alias or "moonraker"
dp: str = cmd_line_args.datapath or f"~/{alias}_data"
dp: str = cmd_line_args.datapath or "~/printer_data"
data_path = pathlib.Path(dp).expanduser().resolve()
if not data_path.exists():
try:
@ -451,11 +450,9 @@ def main(cmd_line_args: argparse.Namespace) -> None:
if cmd_line_args.configfile is not None:
cfg_file: str = cmd_line_args.configfile
else:
cfg_file = str(data_path.joinpath(f"config/{alias}.conf"))
cfg_file = str(data_path.joinpath("config/moonraker.conf"))
app_args = {
"alias": alias,
"data_path": str(data_path),
"is_default_alias": cmd_line_args.alias is None,
"is_default_data_path": cmd_line_args.datapath is None,
"config_file": cfg_file,
"startup_warnings": startup_warnings
@ -469,7 +466,7 @@ def main(cmd_line_args: argparse.Namespace) -> None:
app_args["log_file"] = os.path.normpath(
os.path.expanduser(cmd_line_args.logfile))
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["python_version"] = sys.version.replace("\n", " ")
ql, file_logger, warning = utils.setup_logging(app_args)
@ -537,10 +534,6 @@ if __name__ == '__main__':
# Parse start arguments
parser = argparse.ArgumentParser(
description="Moonraker - Klipper API Server")
parser.add_argument(
"-a", "--alias", default=None, metavar="<alias>",
help="Alternate name of instance"
)
parser.add_argument(
"-d", "--datapath", default=None,
metavar='<data path>',