您的位置:首页 > 娱乐 > 明星 > ubuntu20.04设置文件开机自启动

ubuntu20.04设置文件开机自启动

2025/2/24 15:15:19 来源:https://blog.csdn.net/m0_52765390/article/details/139452894  浏览:    关键词:ubuntu20.04设置文件开机自启动

硬件:树霉派4B
系统:ubuntu20.04

在ubuntu20.04上经常需要运行 ./BluetoothServerParse_L.c ,比较繁琐,想要设置开机自启动,让树霉派4B在接上电源之后就自动运行该程序。使用systemd服务,设置步骤如下:

(1)在/etc/systemd/system/下创建一个systemd服务文件,例如BluetoothServerParse_L.service。
当遇到权限不够时,就用root用户,即使用sudo。

(2)打开BluetoothServerParse_L.service,并编辑该文件,内容大致如下:

[Unit]  
Description=Your Service Description  
After=multi-user.target  [Service]  
ExecStart=/path/to/your/BluetoothServerParse_L  
Restart=on-failure  [Install]  
WantedBy=multi-user.target

将/path/to/your/BluetoothServerParse_L替换为你的脚本或程序的完整路径。

根据BluetoothServerParse_L实际路径,我在BluetoothServerParse_L.service中添加的内容如下:

[Unit]  
Description=Bluetooth Server Parse Service  
After=network.target  [Service]  
ExecStart=/home/ubuntu/ccy/glove_car_bt/ros_udp_udp-main/src/udp_udp/C/BluetoothServerParse_L  
Restart=on-failure  [Install]  
WantedBy=multi-user.target

保存、关闭文件。

(3)重新加载systemd守护进程以应用更改

sudo systemctl daemon-reload

(4)启用并启动服务

sudo systemctl enable BluetoothServerParse_L.service  
sudo systemctl start BluetoothServerParse_L.service

在这里插入图片描述(5)查看服务的状态

sudo systemctl status BluetoothServerParse_L.service

在这里插入图片描述服务已经成功启动,并且状态为 active (running)。
主进程 ID(Main PID)是 9249,并且它正在执行 /home/ubuntu/ccy/glove_car_bt/ros_udp_udp-main/src/udp_udp/C/BluetoothServerParse_L

经过以上步骤,自启动文件就设置成功了。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com