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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

m0_52765390

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值