在 CentOS 上让 cmatrix 开机自动运行,常见有几种方式,取决于你想要的“自启场景”:
适合你登录系统后自动跑 cmatrix
编辑用户 bash 配置:
vi ~/.bashrc
在末尾添加:
if [ -t 1 ]; then
cmatrix
fi
-t 1判断是否是终端,避免非交互环境报错
保存退出,重新登录即可。
适合服务器启动后直接显示 cmatrix(终端)
vi /etc/systemd/system/cmatrix.service
[Unit]
Description=cmatrix autostart
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/cmatrix
StandardInput=tty
TTYPath=/dev/tty1
Restart=always
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable cmatrix
systemctl start cmatrix
会占用 tty1,可用
Ctrl+Alt+F2切换
修改 tty 登录后直接运行:
vi /etc/systemd/system/getty@tty1.service.d/cmatrix.conf
[Service]
ExecStart=
ExecStart=-/usr/bin/cmatrix
然后:
systemctl daemon-reload
systemctl restart getty@tty1
which cmatrix
没有就装:
yum install epel-release -y
yum install cmatrix -y
如果你能说明:
我可以给你最合适的一种方案。