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

background-service.md

150 lines7.5 KB

1# Running T3 Code in the background
2​
3On Linux and macOS, T3 Code can run as a service for your user so you do not need
4to keep a terminal open.
5​
6## Manage the service
7​
8Install the `t3` CLI first ([Install T3 Code](./install.md#command-line)), then
9run these commands on the machine that will host T3 Code:
10​
11| Task | Command |
12| ------------------------------- | ---------------------- |
13| Install and start | `t3 service install` |
14| Inspect status and log location | `t3 service status` |
15| Move to a newer release | `t3 update` |
16| Restart | `t3 service restart` |
17| Stop and remove from startup | `t3 service uninstall` |
18​
19Uninstalling the service leaves your projects, threads, and settings intact.
20Running `t3 service install` again repairs a service that `t3 service status`
21reports as broken.
22​
23`t3 update` downloads the newest release on your channel and switches `t3`
24and the service to it. Restarting interrupts running agent turns, terminals,
25and remote clients, so it asks first; answer no and the service keeps running
26the old version until you run `t3 service restart`. Pass `--yes` from a
27script. A server you started by hand is left running; stop and start it again
28to pick up the new version. Wait for any remote update already in progress
29before updating; to match a remote client's version, follow
30[Updating T3 Code](./updating.md).
31​
32Pass an exact version (`t3 update 0.0.42`) to pin one, `--channel nightly` to
33switch trains, or `--allow-downgrade` to move backwards. `preview` is a
34maintainers' test train: its builds can be broken and are never offered as
35updates, so the installer and `t3 update` ask for confirmation before
36installing one.
37​
38`t3 uninstall` removes the background service, the `t3` launcher, and the
39downloaded versions after showing you the list and asking once. Your projects,
40threads, and settings under `~/.t3/userdata` are kept, along with `service.env`
41under T3 home. Pass `--yes` from a script.
42​
43## Configure the service environment
44​
45Put custom environment variables in `service.env` under the service's T3 home
46directory, normally `~/.t3/service.env`. This file survives service installation
47and updates. For example:
48​
49```dotenv
50T3CODE_PORT=3773
51T3CODE_HOST=127.0.0.1
52```
53​
54Use `KEY=VALUE` entries, quoting values that contain spaces or `#`. Values are
55literal: shell commands and variable expansion are not evaluated. Entries
56override the inherited service environment, except for `PATH`, `T3CODE_HOME`,
57`T3_BOOT_SERVICE_UNIT`, and `T3_SERVICE_LAUNCHER_CONTEXT` (including case variants).
58​
59Run `t3 service restart` after changing the file. Changes apply when the service
60starts again; switching the server version alone keeps the current values.
61For a service installed before env-file support, run `t3 service install` once
62with an up-to-date CLI.
63A missing file is ignored; other read failures stop service startup.
64If the file contains credentials, restrict access to that file with `chmod 600`
65(for the default T3 home, `chmod 600 ~/.t3/service.env`).
66​
67## Platform support
68​
69Linux needs systemd user services. Setup enables lingering so T3 Code starts at
70boot and keeps running after logout. If this needs administrator permission,
71setup prints a recovery command before changing the service.
72​
73macOS starts the service when you log in and stops it when you log out. Keep the
74Mac logged in and awake for unattended remote access. Installing over SSH while
75nobody is logged in at the Mac's screen can fail at the final start step; the
76service is still installed and will start at the next login.
77​
78Windows background services are not supported.
79​
80T3 Connect can offer service installation during setup, but the two are managed
81separately. Signing out of T3 Connect does not stop or uninstall the service.
82​
83## Troubleshooting
84​
85Start with `t3 service status` on the host. It prints the log path and, on Linux,
86checks whether the installed service is running, enabled, and allowed to survive
87logout.
88​
89If it stops when your SSH session closes, check for `linger-disabled`. An
90administrator can enable lingering with:
91​
92```sh
93sudo loginctl enable-linger "$(id -un)"
94```
95​
96Over SSH, allow sudo to prompt:
97​
98```sh
99ssh -t your-server 'sudo loginctl enable-linger "$(id -un)"'
100```
101​
102Then retry service setup as your normal user. Run only the `loginctl` command
103with sudo; running T3 Code as root creates a separate installation and Connect
104identity. Without administrator access, run `t3 serve` in a terminal and keep
105that session open.
106​
107| Status problem | Next step |
108| --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
109| `linger-unavailable` | Run `loginctl show-user "$(id -un)" --property=Linger` and check that systemd-logind is available. |
110| `user-manager-unavailable` | Run `systemctl --user status` in a login session for the service user; check your distribution's systemd user-session support. |
111| `service-disabled` or `service-stopped` | Read the log and `systemctl --user status t3code.service`, then use the repair command printed by T3 Code. |
112| `restart-pending` | A newer version is installed but the service still runs the previous one. Run `t3 service restart`. |
113​
114On macOS, check **System Settings → General → Login Items** if the service no
115longer starts at login. If agent work cannot access Desktop, Documents, or
116Downloads, it may need Full Disk Access for the `t3` executable listed in
117`ProgramArguments` in
118`~/Library/LaunchAgents/com.t3tools.t3code.service.plist`.
119​
120For failures after signing in to T3 Connect, see
121[connection troubleshooting](./t3-connect-troubleshooting.md).
122​
123## Reclaim database space
124​
125T3 Code removes superseded internal history on its own while it runs; your
126conversations are kept. Databases created before this shrank automatically
127still hold the freed space on disk until a one-time offline repair returns it
128and turns on automatic shrinking. Settings > Storage (web and desktop) or
129Settings > Maintenance (mobile) suggests the repair when at least 1 GiB can be
130reclaimed.
131​
132Run `t3 doctor` on the machine that hosts the environment. It reports the
133database size and the space it can reclaim, then asks which repairs to run;
134pass `--fix` to run the recommended ones without a prompt (for scripts), or
135`--dry-run` to only report. An installed background service for the same data
136directory is stopped for the repair and started again afterwards, also when
137the repair fails. Quit a server you started by hand, or the desktop app, first:
138the repair refuses to touch a database that is in use. Use `--base-dir` for a
139different data directory.
140​
141The repair can take several minutes on a large database. It rebuilds the
142database through a temporary copy, so it needs free space of about the
143database's size twice over: once in the system temporary directory (`TMPDIR`
144or `/tmp` on Linux and macOS) and once next to the database for its
145write-ahead log.
146​
147If you upgraded from a version before 0.1.0, its database (`state.sqlite`) is
148still kept next to the current one so you can roll back. `t3 doctor` offers to
149delete it, but never selects that repair for you and `--fix` skips it: once it
150is gone, a version before 0.1.0 starts with no threads or settings.