在 CentOS 上让 cmatrix(矩阵屏保效果)开机自动启动,取决于你使用的是 CentOS 6(SysVinit) 还是 CentOS 7/8(systemd),以及你希望它 在哪个环境启动(字符终端 / 图形界面)。
下面给你几种常见、实用的做法。
which cmatrix
如果没有:
yum install cmatrix -y
(CentOS 8 可用 dnf)
适合 服务器、无图形界面
mkdir -p ~/.config/systemd/user
vi ~/.config/systemd/user/cmatrix.service
内容:
[Unit]
Description=cmatrix auto start
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/cmatrix -s
Restart=on-failure
[Install]
WantedBy=default.target
systemctl --user enable cmatrix.service
⚠️ 注意:这种方式在你 登录后 才会启动。
如果你希望 系统启动后直接进入 cmatrix(像屏保):
vi /etc/systemd/system/cmatrix.service
[Unit]
Description=cmatrix on tty1
After=getty.target
[Service]
Type=simple
ExecStart=/usr/bin/cmatrix -s
StandardInput=tty
StandardOutput=tty
TTYPath=/dev/tty1
Restart=always
[Install]
WantedBy=multi-user.target
启用:
systemctl enable cmatrix.service
⚠️ 这会导致你 无法用 tty1 登录系统
vi /etc/init.d/cmatrix
#!/bin/bash
# chkconfig: 2345 99 01
# description: cmatrix auto start
case "$1" in
start)
/usr/bin/cmatrix -s
;;
stop)
pkill cmatrix
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac
exit 0
chmod +x /etc/init.d/cmatrix
chkconfig cmatrix on
mkdir -p ~/.config/autostart
vi ~/.config/autostart/cmatrix.desktop
[Desktop Entry]
Type=Application
Name=cmatrix
Exec=/usr/bin/cmatrix -s
Terminal=true
X-GNOME-Autostart-enabled=true
cmatrix -s # 屏保模式(按任意键退出)
cmatrix -b # 加粗
cmatrix -C red # 红色
如果你告诉我:
我可以帮你写 完全匹配你环境的配置。