要实现Linux cmatrix的自动化运行,您可以将其添加到系统的启动脚本中。以下是在不同系统上实现自动化的方法:
对于Systemd(大多数现代Linux发行版):
cmatrix.service
的新文件,例如:sudo nano /etc/systemd/system/cmatrix.service
[Unit]
Description=Conway's Matrix (cmatrix) terminal animation
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/cmatrix -b
Restart=on-failure
[Install]
WantedBy=multi-user.target
这将创建一个名为cmatrix.service的新Systemd服务,该服务将在网络启动后运行。
保存并关闭文件。
重新加载Systemd守护程序以识别新服务:
sudo systemctl daemon-reload
sudo systemctl enable cmatrix.service
sudo systemctl start cmatrix.service
对于SysVinit(较旧的Linux发行版):
/etc/init.d/cmatrix
的新文件,例如:sudo nano /etc/init.d/cmatrix
#!/bin/sh
### BEGIN INIT INFO
# Provides: cmatrix
# Required-Start: $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Start Conway's Matrix (cmatrix) terminal animation at boot time
# Description:
### END INIT INFO
case "$1" in
start)
/usr/bin/cmatrix -b
;;
stop)
# No stop action needed for cmatrix
;;
*)
echo "Usage: /etc/init.d/cmatrix {start|stop}"
exit 1
;;
esac
exit 0
这将创建一个名为cmatrix的新SysVinit脚本,该脚本将在系统启动时运行。
保存并关闭文件。
使脚本可执行:
sudo chmod +x /etc/init.d/cmatrix
sudo update-rc.d cmatrix defaults
现在,无论您使用的是哪种系统,cmatrix都将在系统启动时自动运行。如果您想要停止cmatrix服务,可以使用以下命令:
对于Systemd:
sudo systemctl stop cmatrix.service
对于SysVinit:
sudo /etc/init.d/cmatrix stop