Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions packages/ssh/src/tunnel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,16 @@ const runArchiveRunner = Effect.fn("test.runArchiveRunner")(
);

describe("ssh tunnel scripts", () => {
it.live.each(["launchd", "systemd", "none"] as const)(
const serviceManagers = [
"launchd",
"systemd",
"systemd-unavailable",
"systemd-unavailable-xdg",
"systemd-unavailable-relative-xdg",
"systemd-unavailable-login-xdg",
"none",
] as const;
it.live.each(serviceManagers)(
"respects %s service ownership when the server is stopped",
(manager) =>
Effect.gen(function* () {
Expand Down Expand Up @@ -175,12 +184,27 @@ esac
yield* fs.makeDirectory(agents, { recursive: true });
yield* fs.writeFileString(`${agents}/com.t3tools.t3code.service.plist`, "installed");
}
const xdgConfigHome =
manager === "systemd-unavailable-xdg" || manager === "systemd-unavailable-login-xdg"
? `${root}/custom config`
: manager === "systemd-unavailable-relative-xdg"
? "relative-config"
: undefined;
if (manager.startsWith("systemd-unavailable")) {
const units = `${manager === "systemd-unavailable-xdg" ? xdgConfigHome : `${root}/.config`}/systemd/user`;
yield* fs.makeDirectory(units, { recursive: true });
yield* fs.writeFileString(`${units}/t3code.service`, "installed");
}
const ssh = ChildProcessSpawner.make((command) => {
if (command._tag !== "StandardCommand") return Effect.die("Expected SSH command");
return spawner.spawn(
ChildProcess.make("sh", ["-s", "--", "test-peer"], {
...command.options,
env: { HOME: root, PATH: `${bin}:/usr/bin:/bin` },
env: {
HOME: root,
PATH: `${bin}:/usr/bin:/bin`,
...(xdgConfigHome === undefined ? {} : { XDG_CONFIG_HOME: xdgConfigHome }),
},
extendEnv: false,
}),
);
Expand Down
9 changes: 8 additions & 1 deletion packages/ssh/src/tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,14 @@ if [ -z "$REMOTE_PORT" ]; then
fi
;;
Linux)
if command -v systemctl >/dev/null 2>&1 && systemctl --user cat t3code.service >/dev/null 2>&1; then
SERVICE_UNIT="systemd/user/t3code.service"
SERVICE_CONFIG_HOME="$HOME/.config"
case "\${XDG_CONFIG_HOME:-}" in
/*) SERVICE_CONFIG_HOME="$XDG_CONFIG_HOME" ;;
esac
# The SSH login may have a different XDG home and no connection to the user manager.
if [ -f "$SERVICE_CONFIG_HOME/$SERVICE_UNIT" ] || [ -f "$HOME/.config/$SERVICE_UNIT" ] ||
{ command -v systemctl >/dev/null 2>&1 && systemctl --user cat t3code.service >/dev/null 2>&1; }; then
SERVICE_INSTALLED=1
fi
;;
Expand Down
Loading