1.cd /usr/lib/systemd/system/目录下新建demo.service
vi demo.service
[Unit]
Description=demo Service
[Service]
Type=simple
ExecStart=/bin/bash /home/test.sh
MemoryAccounting=true
MemoryLimit=200M
[Install]
WantedBy=multi-user.target
脚本文件示例如下:
vi /home/test.sh
#!/bin/bash
x=0
while [ True ];do
x=$x+1
done;
2.重载系统服务 systemctl daemon-reload
3.设置开机启动 systemctl enable demo
4.启动服务 systemctl start demo
5.查询服务状态 systemctl status demo
6.停止服务 systemctl stop demo
7.禁止开机启动 systemctl disable demo