Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

background-service.md

123 lines6.4 KB

1# Running T3 Code in the Background
2​
3On Linux and macOS, T3 Code can run as a background service for your user, so it is ready without
4keeping a terminal open.
5​
6## Manage the Service
7​
8Install it with the latest T3 Code release:
9​
10```sh
11npx t3@latest service install
12```
13​
14Check whether it is installed. On Linux this also checks whether the service is running, enabled
15at startup, and allowed to keep running after logout:
16​
17```sh
18npx t3@latest service status
19```
20​
21Update or repair it:
22​
23```sh
24npx t3@latest service update
25```
26​
27The service uses the same T3 Code version as the CLI you run. To install a nightly or an exact
28version, use that version of the CLI:
29​
30```sh
31npx t3@nightly service update
32npx t3@1.2.3 service update
33```
34​
35The install and update commands refuse to replace a newer service with an older version. Setup
36through T3 Connect leaves a newer service unchanged. To downgrade, select the exact older version
37and pass `--allow-downgrade`:
38​
39```sh
40npx t3@1.2.3 service update --allow-downgrade
41```
42​
43Stop it and remove it from startup:
44​
45```sh
46npx t3@latest service uninstall
47```
48​
49Updating restarts T3 Code briefly. Let active agent work and terminal commands finish first.
50If a remote update is already in progress, wait for it to finish before retrying a local update.
51​
52The service runs a small stable launcher. Exact T3 Code versions are installed separately, so a
53failed remote candidate can return to the previous version without rewriting the service
54definition. The launcher snapshots the database before a remote candidate starts, so database
55updates roll back with the server version. An older launcher may require one local
56`service update` before this is available.
57​
58## Platform Support
59​
60**Linux** uses a systemd user unit at `~/.config/systemd/user/t3code.service`. The service starts
61when the machine boots and keeps running after you log out (lingering is enabled during install).
62Setup checks the systemd user manager and enables lingering before installing a runtime or stopping
63an existing service. If that requires administrator permission, setup stops with a recovery command.
64​
65**macOS** uses a launch agent at `~/Library/LaunchAgents/com.t3tools.t3code.service.plist`. It
66starts when you log in, not when the Mac boots, and it stops when you log out; macOS has no
67equivalent of Linux lingering for user agents. For a Mac that should stay reachable unattended,
68turn on automatic login (System Settings → Users & Groups; unavailable while FileVault is on) and
69keep the Mac from sleeping.
70​
71A few more macOS notes:
72​
73- Installing over SSH needs someone logged in at the Mac's screen to start the agent right away.
74 Without that, the install command reports an error at the final start step, but the agent is
75 fully installed and starts at the next login.
76- macOS may show privacy prompts for protected folders such as Desktop, Documents, or Downloads,
77 attributed to a bare `node` process, or deny access without a prompt. If agent work fails to
78 read those folders, grant Full Disk Access to the node binary listed in the launch agent's
79 `ProgramArguments`.
80- The agent appears under System Settings → General → Login Items. If it was switched off there,
81 or disabled with `launchctl disable`, macOS will not start it at login until you switch it back
82 on.
83​
84**Windows** is not supported yet.
85​
86## Using It with T3 Connect
87​
88T3 Connect may offer to install the service during setup so the host stays reachable in the
89background. This is only an onboarding shortcut: the service and T3 Connect are managed separately.
90​
91Signing out of T3 Connect does not remove the service. Use `t3 service uninstall` when you no longer
92want T3 Code to start in the background.
93​
94## Troubleshooting
95​
96Run `t3 service status` on the server machine. An installed version alone does not mean the service
97is running or will survive logout. Linux status reports these problems:
98​
99| Code | What it means | Recovery |
100| -------------------------- | -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
101| `linger-disabled` | The service stops after your last login session ends and does not start at boot. | Run `sudo loginctl enable-linger "$(id -un)"`, then retry setup as your normal user. |
102| `linger-unavailable` | T3 Code could not verify the logout setting. | Run `loginctl show-user "$(id -un)" --property=Linger` and check that systemd-logind is available. |
103| `user-manager-unavailable` | T3 Code cannot reach your systemd user manager. | Run `systemctl --user status` in a login session for the service user. Install your distribution's systemd user-session support if needed. |
104| `service-disabled` | The service is not enabled to start automatically. | Run the repair command shown by `t3 service status`. |
105| `service-stopped` | The service is installed but is not running. | Read the service log and `systemctl --user status t3code.service`, then run the displayed repair command. |
106​
107For an SSH host, run the administrator command in an interactive terminal so sudo can prompt for
108your password:
109​
110```sh
111ssh -t your-server 'sudo loginctl enable-linger "$(id -un)"'
112```
113​
114Run only the `loginctl` command with sudo. Running `t3` with sudo creates a separate installation and
115Connect identity for root. If an administrator is unavailable, run `t3 serve` in a terminal and
116keep that session open.
117​
118The repair command shown by status uses the CLI version, or the installed service version if that
119is newer. An older stable CLI therefore does not recommend downgrading a nightly installation.
120Setup leaves an existing service running if the user-manager or lingering check fails.
121​
122`t3 service status` prints the log path. The adjacent `server.trace.ndjson` file contains detailed
123server traces. For failures after authorization, see [T3 Connect troubleshooting](./remote-access.md#t3-connect-troubleshooting).