Systemd 与 D-Bus 集成
Ghostty 内置对 D-Bus 激活和 `systemd` 服务的支持, 可按需启动并即时创建新窗口。
如果正确安装1,Ghostty 会附带若干 systemd 单元。 通过这些 systemd 单元运行 Ghostty 是推荐的方式。Ghostty 的 systemd 集成提供的两个最重要的好处是:即时启动2和集中 日志记录。
如果你的系统带 systemd,并且你通过系统包或
如文档所述 安装了 Ghostty,那么 Ghostty 应该
直接可用。除非你想理解这一切如何工作或
需要排障,否则无须阅读本文档。
Important
Ghostty 不需要 systemd 即可运行。你可以在任何没有 systemd 的系统上直接运行
ghostty二进制,Ghostty 依然正常 工作。但你会失去本页文档所提到的 好处。
Important
在配置文件中使用
class可能干扰systemd单元文件 或 D-Bus 激活的正常操作。我们建议从配置 文件中移除它们,只在需要时通过命令行显式使用。
可以配置 Ghostty 在登录时于后台启动,使将来创建新窗口的
请求极其快速。这通过 systemd 启用
Ghostty 用户服务来完成:
systemctl enable --user app-com.mitchellh.ghostty.service
这会把你的系统配置为登录时启动 Ghostty,但不创建任何窗口。 任何启动延迟都会被登录后系统完成其余一切设置所需的时间 "隐藏"掉。
在配置中添加一些配置项可以进一步改善体验:
quit-after-last-window-closed = true
quit-after-last-window-closed-delay = 5m
这个配置会让 Ghostty 在最后一个窗口关闭五分钟 后退出,从而在你一段时间未使用 Ghostty 时节省内存。
quit-after-last-window-closed = false
这个配置会让 Ghostty 一直保持运行,使新窗口的 创建始终快速。
你可以让 Ghostty 重新加载其配置(从脚本或 CLI), 使用这条命令:
systemctl reload --user app-com.mitchellh.ghostty.service
背后它只是向主 Ghostty 进程发送一个 SIGUSR2,但
systemd 负责跟踪主 Ghostty 进程。用
ps 或类似工具来脚本化这并不太可靠。
新窗口可以用不带参数的 ghostty CLI 创建。
不过,如果你正在使用 systemd 与 D-Bus 集成,
改用 ghostty +new-window 会快得多。
+new-window 命令会直接使用 D-Bus 创建新窗口。
如果 Ghostty 不在运行,D-Bus 激活单元会启动 Ghostty。
这比直接运行 ghostty 快得多,因为直接运行必须
加载配置、检查环境、初始化 GTK 等
才能得出同样的结论。
ghostty +new-window
即使 Ghostty 尚未运行,这依然会创建新窗口, 因为 D-Bus 激活会导致 Ghostty 被启动。
这条命令对 i3、Hyprland 或 River 等 窗口管理器尤其有用。
下面是在 Hyprland 中把 super+return 绑定为
打开新 Ghostty 窗口的一个示例。该配置
通常放在 ~/.config/hypr/hyprland.conf:
bind = SUPER, return, exec, ghostty +new-window
在带 systemd 和 D-Bus 的系统上,Ghostty 默认
通过 D-Bus 激活来启动。
应用启动器并不直接执行 Ghostty,而是向 D-Bus
会话代理发送信号,请求它打开一个
Ghostty 窗口。D-Bus 会话代理知道
Ghostty 是否在运行,因为 Ghostty 会
注册一个特定的总线名称(com.mitchellh.ghostty)。
如果有程序注册了这个总线名称,就假定
是 Ghostty。
从这一点起,行为取决于 Ghostty 是否已经在运行。
这一过程确保:只有当有活动窗口、或 Ghostty 被配置为保持运行(默认不是)时,GTK (或任何其他初始化)造成的启动延迟才会 被承担一次。
如果 Ghostty 已经在运行,代理会 直接向 Ghostty 发送一个 D-Bus 信号,请求 创建新窗口。Ghostty 监听该信号并 打开一个新窗口。这非常快,非常省。
如果 Ghostty 没有运行,D-Bus 会话代理会
请求 systemd 以用户服务的方式
启动 Ghostty,然后在 Ghostty 启动后
向它发送 D-Bus 信号,请求
创建新窗口。
本"其他"部分收集较不关键 或不常使用的信息。这些信息可能仍然 极其有用(因此记录在此),但不是 常常被用到。
通过 systemd 运行时 Ghostty 发出的日志可以使用
journalctl 查看:
journalctl -a -f --user -u app-com.mitchellh.ghostty.service
以下命令会显示 Ghostty 的状态:
systemctl status --user app-com.mitchellh.ghostty.service
它应产生类似如下的输出:
● app-com.mitchellh.ghostty.service - Ghostty
Loaded: loaded (/home/mitchellh/.local/share/systemd/user/app-com.mitchellh.ghostty.service; disabled; preset: enabled)
Active: active (running) since Fri 2025-07-11 14:05:42 PDT; 24h ago
Invocation: 42b48b0aa1bf4134a030e38acb04b8dd
Main PID: 2525 (ghostty)
Tasks: 0 (limit: 71639)
Memory: 81.4M (peak: 107.9M)
CPU: 98ms
CGroup: /user.slice/user-1000.slice/user@1000.service/app.slice/app-com.mitchellh.ghostty.service
‣ 2525 /home/mitchellh/.local/bin/ghostty --launched-from=systemd
Jul 11 14:05:42 beach ghostty[2525]: info(gtk): cgroup isolation enabled base=/user.slice/user-1000.slice/user@1000.service/app.slice/app-ghostty-transient-2525.scope
Jul 11 14:05:42 beach systemd[2268]: Started Ghostty.
Jul 11 14:05:42 beach ghostty[2525]: info(gtk): received new window action
Jul 11 14:05:42 beach ghostty[2525]: info(opengl): loaded OpenGL 4.6
Jul 11 14:05:42 beach ghostty[2525]: info(io_exec): found Ghostty resources dir: /home/mitchellh/.local/share/ghostty
Ghostty 的 systemd 用户服务可以通过运行
以下命令停止:
systemctl stop --user app-com.mitchellh.ghostty.service
Caution
这会优雅地停止 Ghostty,但 Ghostty 会关闭全部 窗口并终止其中正在运行 的进程,_ 不请求确认 _。这 可能导致数据 或状态 丢失。
正确安装1时,Ghostty 会附带 若干用于启动 Ghostty 的配置文件。
如果以用户身份安装(例如在
$HOME/.local),会创建以下文件:
$PREFIX/share/applications/com.mitchellh.ghostty.desktop
$PREFIX/share/dbus-1/services/com.mitchellh.ghostty.service
$PREFIX/share/systemd/user/app-com.mitchellh.ghostty.service
如果以系统包安装,会创建以下文件:
$PREFIX/share/applications/com.mitchellh.ghostty.desktop
$PREFIX/share/dbus-1/services/com.mitchellh.ghostty.service
$PREFIX/lib/systemd/user/app-com.mitchellh.ghostty.service
Warning
如果这些文件未安装到正确的位置,或配置不 正确,Ghostty 可能无法启动。如果 它们已安装到正确的位置且 Ghostty 依然 不启动,请注销并重新登录。如果 仍然不行,随后尝试重启系统。这 很少是必要的,但依据系统配置 可能发生。
如果安装的是 Ghostty 的开发构建(Debug
模式),本页上的路径需要略微变更:
systemctl enable --user app-com.mitchellh.ghostty-debug.service
systemctl stop --user app-com.mitchellh.ghostty-debug.service
systemctl reload --user app-com.mitchellh.ghostty-debug.service
journalctl -a -f --user -u app-com.mitchellh.ghostty-debug.service
ghostty +new-window --class=com.mitchellh.ghostty-debug.service
这些是以用户身份安装时控制器启动 Ghostty 调试版本启动需要的文件:
$PREFIX/share/applications/com.mitchellh.ghostty-debug.desktop
$PREFIX/share/dbus-1/services/com.mitchellh.ghostty-debug.service
$PREFIX/share/systemd/user/app-com.mitchellh.ghostty-debug.service
如果以系统包安装,这些文件位于以下 位置:
$PREFIX/share/applications/com.mitchellh.ghostty-debug.desktop
$PREFIX/share/dbus-1/services/com.mitchellh.ghostty-debug.service
$PREFIX/lib/systemd/user/app-com.mitchellh.ghostty-debug.service