centos中compton的启动脚本与服务单元位置
- 在 centos 上,compton 通常没有统一的“默认启动脚本”。常见做法是通过 systemd 服务单元或桌面会话的自动启动来运行。systemd 的服务单元文件可能位于以下路径(按优先级从低到高):/usr/lib/systemd/system/compton.service、/lib/systemd/system/compton.service、/etc/systemd/system/compton.service;用户级会话单元则位于 $home/.config/systemd/user/compton.service 等目录。若使用包管理器安装,服务文件通常由包提供并位于系统级目录;若未提供,则需要自建。使用 systemctl status compton 或 systemctl show compton 可查看实际加载的单元文件路径与状态。
如何快速确认本机使用的启动方式
- 检查是否存在并启用 systemd 服务:运行 systemctl --user is-active compton(用户级)或 sudo systemctl is-active compton(系统级);若已启用,可用 systemctl status compton 查看“loaded”的实际单元文件路径。若未使用 systemd,常见的替代方式包括:在桌面会话的自动启动目录(如 ~/.config/autostart/compton.desktop)中配置;或在显示管理器(如 gdm)的初始化脚本(如 /etc/gdm/init/default)中追加启动命令。
没有现成脚本时的两种最简自建方式
-
使用 systemd 用户服务(推荐,适用于登录即自动启动):创建文件 ~/.config/systemd/user/compton.service,内容示例:
[unit]
description=compton compositor
after=graphical-session.target
[service]
execstart=/usr/bin/compton --config ~/.config/compton.conf
restart=on-failure
[install]
wantedby=graphical-session.target
然后执行:systemctl --user daemon-reload && systemctl --user enable --now compton。若需系统级服务,可将相同内容放到 /etc/systemd/system/compton.service,并以 root 执行 systemctl daemon-reload && systemctl enable --now compton。
-
使用桌面会话自动启动:创建文件 ~/.config/autostart/compton.desktop,内容示例:
[desktop entry]
type=application
exec=compton --config ~/.config/compton.conf
hidden=false
nogui=true
name=compton
x-gnome-autostart-enabled=true
重新登录会话后生效。
配置文件与运行命令的常见位置
- 配置文件:常见位置为 /etc/compton.conf(系统级)或 ~/.config/compton.conf(用户级)。若需自定义,建议将 /etc/compton.conf 复制到 ~/.config/compton.conf 后再编辑。运行命令示例:compton --config /etc/compton.conf 或 compton --config ~/.config/compton.conf。