linux中让一个sh脚本开机运行通过编写service实现。

2024-06-12  本文已影响0人  吉凶以情迁

模仿开源源码写了一个mjpgstream-service.service发现可以用,第一次因为资源busy不得不重启释放资源了。
主要是想让我的设备开机启动就跑摄像头流,这样就可以进行相机查看。

[Unit]
Description=mjpg-streamer Daemon
Documentation=https://github.com/jacksonliam/mjpg-streamer
After=network.target network-online.target
Wants=network-online.target
Requires=network.target

[Service]
Type=notify
User=daemon
Group=daemon
WorkingDirectory=/opt/mjpg-streamer/mjpg-streamer-experimental/
ExecStart=/opt/mjpg-streamer/mjpg-streamer-experimental/start.sh
StandardOutput=null
StandardError=journal
Environment=PYTHONUNBUFFERED=1
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target

然后创建快捷方式到systemd



sudo ln -s /opt/startup/mjpgstream-service.service /etc/systemd/system/mjpgstream-service.service

sudo systemctl daemon-reload

# tell system that it can start our script at system startup during boot
sudo systemctl enable mjpgstream-service.service

# start the script running
sudo systemctl start mjpgstream-service.service

# check to make sure all is ok with the start up
sudo systemctl status mjpgstream-service.service

干掉服务

,其实等同于删掉/etc/systemd/system/mjpgstream-service.service
输入

sudo systemctl unmask mjpgstream-service.service

如果启动提示service is masked
可能因为里面的内容不正确,我第一次是因为是空的。

查看错误

sudo journalctl -u robotcar.service -e

权限不够问题 i2c

 sudo usermod -aG i2c daemon

或者提升root组

image.png
上一篇下一篇

猜你喜欢

热点阅读