systemd开机自启动

  • Post author:
  • Post category:其他


1.首先可以先将代码内的相机.sh和imgProc.sh脚本拷贝到/usr/bin路径,并赋予可执行权限:

sudo cp cam_node.sh /usr/bin/cam_node.sh                      
sudo chmod +x /usr/bin/cam_node.sh
sudo cp imgProc.sh /usr/bin/imgProc.sh                      
sudo chmod +x /usr/bin/imgProc.sh

2.在/etc/systemd/system目录 创建cam_node.service和imgProc.service两个服务


sudo vi cam_node.service


gedit 文件名 //打开文件,编辑文件

2.1 cam_node.service

[Unit]
Description=cam_node 开机启动
Before=imgProc.service
[Service]
Type=simple
#User=cubot
ExecStart=/bin/bash /usr/bin/camDaHua_node.sh
ExecReload=/bin/bash /usr/bin/camDaHua_node.sh
#ExecStop=/home/cubot/Desktop/CUBOTVERSION_2020/VisionInfantry/Script/cam_node_kill.sh
Restart=always
TimeoutStartSec=2.5
RestartSec=2.5
PrivateTmp=false
[Install]
WantedBy=multi-user.target
#After=basic.target

2.2 imgProc.service

[Unit]
Description=imgProc 开机启动
After=cam_node.service
Requires=cam_node.service
  
[Service]
Type=simple
ExecStart=/bin/bash /usr/bin/imgProc.sh
ExecReload=/bin/bash /usr/bin/imgProc.sh
#ExecStop=/home/cubot/Desktop/CUBOTVERSION_2020/VisionInfantry/Script/vision_kill.sh
Restart=always
TimeoutStartSec=2.5
RestartSec=2.5
PrivateTmp=false
[Install]
WantedBy=multi-user.target

3.重新载入systemd服务,执行命令

sudo systemctl daemon-reload

4.一旦创建了service就可以用一下命令测试,启动cam_node.service服务:

sudo systemctl start cam_node
sudo systemctl start imgProc

5.查看服务状态

sudo systemctl status cam_node
sudo systemctl status imgProc

6.设置开机自启动

sudo systemctl enable cam_node
sudo systemctl enable imgProc



版权声明:本文为weixin_47994925原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。