diff --git a/install.sh b/install.sh index 17c559e..6817aef 100755 --- a/install.sh +++ b/install.sh @@ -534,10 +534,14 @@ install_service_linux() { mkdir -p "$unit_dir" local template="$INSTALL_DIR/templates/maestro-relay.service" [ -f "$template" ] || { warn "Service template missing at $template"; return; } + local node_bin; node_bin="$(command -v node)" + local node_dir; node_dir="$(dirname "$node_bin")" sed \ -e "s|@INSTALL_DIR@|$INSTALL_DIR|g" \ -e "s|@CONFIG_DIR@|$CONFIG_DIR|g" \ - -e "s|@NODE_BIN@|$(command -v node)|g" \ + -e "s|@NODE_BIN@|$node_bin|g" \ + -e "s|@NODE_DIR@|$node_dir|g" \ + -e "s|@HOME@|$HOME|g" \ "$template" > "$unit_dir/maestro-relay.service" # Disable+remove a legacy maestro-discord unit if present so we don't leave # two competing user services running on upgrade. @@ -563,10 +567,14 @@ install_service_macos() { mkdir -p "$INSTALL_DIR/logs" local template="$INSTALL_DIR/templates/sh.maestro.relay.plist" [ -f "$template" ] || { warn "Plist template missing at $template"; return; } + local node_bin; node_bin="$(command -v node)" + local node_dir; node_dir="$(dirname "$node_bin")" sed \ -e "s|@INSTALL_DIR@|$INSTALL_DIR|g" \ -e "s|@CONFIG_DIR@|$CONFIG_DIR|g" \ - -e "s|@NODE_BIN@|$(command -v node)|g" \ + -e "s|@NODE_BIN@|$node_bin|g" \ + -e "s|@NODE_DIR@|$node_dir|g" \ + -e "s|@HOME@|$HOME|g" \ "$template" > "$plist_dir/sh.maestro.relay.plist" # Unload+remove a legacy launchd plist if present. if [ -f "$plist_dir/sh.maestro.discord.plist" ]; then diff --git a/templates/maestro-relay.service b/templates/maestro-relay.service index d503a62..77bda90 100644 --- a/templates/maestro-relay.service +++ b/templates/maestro-relay.service @@ -9,6 +9,7 @@ StartLimitBurst=5 Type=simple WorkingDirectory=@INSTALL_DIR@ EnvironmentFile=@CONFIG_DIR@/.env +Environment=PATH=@HOME@/.local/bin:@NODE_DIR@:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ExecStart=@NODE_BIN@ @INSTALL_DIR@/dist/index.js Restart=on-failure RestartSec=5 diff --git a/templates/sh.maestro.relay.plist b/templates/sh.maestro.relay.plist index f436629..a8f1f3a 100644 --- a/templates/sh.maestro.relay.plist +++ b/templates/sh.maestro.relay.plist @@ -10,7 +10,7 @@ /bin/bash -c - set -a; . "@CONFIG_DIR@/.env"; set +a; export PATH="/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin${PATH:+:$PATH}"; exec "@NODE_BIN@" "@INSTALL_DIR@/dist/index.js" + set -a; . "@CONFIG_DIR@/.env"; set +a; export PATH="@HOME@/.local/bin:@NODE_DIR@:/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin${PATH:+:$PATH}"; exec "@NODE_BIN@" "@INSTALL_DIR@/dist/index.js" RunAtLoad