Linux添加开机自启动服务

1.创建服务文件yourService.service,ExecStart为自己的程序绝对路径

  [Unit]
  Description=Hello Service
  [Service]
  Type=simple
  ExecStart=/usr/bin/hello.sh
  SuccessExitStatus=2
  [Install]
  WantedBy=multi-user.target

2.复制yourService.service到/lib/systemd/system/目录

3.重载服务项目

systemctl daemon-reload

4.开机自启动设置

systemctl enable yourService.service

5.启动服务

service yourService start