/lib/systemd/system目录下创建service文件

  • 01
cd /lib/systemd/system

vim test.service

  • 01
  • 02
  • 03
  • 04
  • 05
  • 06
  • 07
  • 08
  • 09
  • 10
  • 11
  • 12
  • 13
[Unit] Description=test After=network.target [Service] Type=forking ExecStart=/opt/test/test.sh ExecReload=/opt/test/reload.sh ExecStop=/opt/test/stop.sh PrivateTmp=true [Install] WantedBy=multi-user.target

刷新配置

  • 01
systemctl daemon-reload

设置开启自启

  • 01
systemctl enable test.service

查看是否设置成功

  • 01
systemctl is-enabled test.service

如果怕有问题,可以提前进行验证
验证方式就是自己手动试一下:systemctl start test.service