1 创建服务脚本
cd / lib/systemd/system/ 创建服务脚本 video_detect.service
[Unit]
Description=video_detect
After=network.target
[Service]
ExecStart=sh start.sh
[Install]
WantedBy=multi-user.target
2 设置脚本开机自启动
sudo systemctl enable video_detect.service
3 常用命令
重新加载service文件:systemctl daemon-reload
启动一个服务:systemctl start video_detect.service
关闭一个服务:systemctl stop video_detect.service
重启一个服务:systemctl restartvideo_detect.service
显示一个服务的状态:systemctl status video_detect.service
在开机时启用一个服务:systemctl enable video_detect.service
在开机时禁用一个服务:systemctl disable video_detect.service
查看服务是否开机启动:systemctl is-enabledvideo_detect.servicee
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed