在 CentOS 中让 cmatrix 开机自启,常见有几种方式,取决于你使用的是 CentOS 6(init) 还是 CentOS 7/8(systemd)。下面分别说明。
which cmatrix
如果没有:
yum install cmatrix -y
⚠️ 注意:cmatrix 是终端程序,不能在无登录环境下直接显示,通常需要 getty 或 tty 登录后运行。
创建服务文件:
vim /etc/systemd/system/cmatrix.service
内容如下:
[Unit]
Description=CMatrix on tty1
After=getty.target
[Service]
Type=simple
ExecStart=/usr/bin/cmatrix
StandardInput=tty
StandardOutput=tty
TTYPath=/dev/tty1
Restart=always
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable cmatrix.service
重启后,在 tty1(Ctrl+Alt+F1) 会自动运行 cmatrix。
vim /etc/init.d/cmatrix
内容:
#!/bin/bash
# chkconfig: 2345 99 01
# description: cmatrix autostart
case "$1" in
start)
/usr/bin/cmatrix &
;;
stop)
pkill cmatrix
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac
exit 0
chmod +x /etc/init.d/cmatrix
chkconfig cmatrix on
如果你只是想 登录后自动跑 cmatrix(不严格算“开机”):
echo "cmatrix" >> ~/.bashrc
或
echo "cmatrix" >> ~/.profile
如果你能告诉我:
我可以给你更精确的方案。