Centos_脚本如何添加自启
1、创建文件
在/etc/systemd/system下创建一个Unit文件,
文件名为XXX.service
并且赋权赋权0777
2、文件内容
[Unit]
Description=Example systemd service.
[Service]
Type=simple
ExecStart=/root/test.sh
[Install]
WantedBy=multi-user.target
注意:脚本内含路径必须是全路径,不能是相对路径。
3、启动
首先重新载入,然后就可以启动脚本
重新载入 systemctl daemon-reload
启动脚本 systemctl start XXX.service
开机启动 systemctl enable XXX.service
关闭自启 systemctl disable XXX.service
查看状态 systemctl status XXX.service
停止脚本 systemctl stop XXX.service
重启脚本 systemctl restart XXX.service
Editing is enabled. Use the "Save changes" button below the editor to commit modifications to this file.