如何使用 systemd 文件实现自启动

使用 systemd 文件实现自启动

/etc/systemd/system/目录下创建新.service文件:

bash 复制代码
$ sudo touch /etc/systemd/system/vid_tcp.service
$ sudo chmod 777  /etc/systemd/system/vid_tcp.service
$ code  /etc/systemd/system/vid_tcp.service

修改文件内容如下。ExeStart是需要执行的脚本

bash 复制代码
[Unit]
Description=auto executing vid script

[Service]
ExeStart=/home/wc/send_g/vid_scripts/cam_tcp_stream.sh
Restart=always

[Install]
WantedBy=multi-user.target

而后使服务文件生效并启用:

bash 复制代码
$ sudo systemctl daemon-reload
$ sudo systemctl enable vid_tcp.service
Created symlink /etc/systemd/system/multi-user.target.wants/vid_tcp.service → /etc/systemd/system/vid_tcp.service.

注意大小写,比如WantedBy写成wantedBy可能会在使能时报错:

bash 复制代码
$ sudo systemctl enable vid_tcp.service
The unit files have no installation config (WantedBy=, RequiredBy=, Also=,
Alias= settings in the [Install] section, and DefaultInstance= for template
units). This means they are not meant to be enabled using systemctl.
 
Possible reasons for having this kind of units are:
• A unit may be statically enabled by being symlinked from another unit's
  .wants/ or .requires/ directory.
• A unit's purpose may be to act as a helper for some other unit which has
  a requirement dependency on it.
• A unit may be started when needed via activation (socket, path, timer,
  D-Bus, udev, scripted systemctl call, ...).
• In case of template units, the unit is meant to be enabled with some
  instance name specified.
相关推荐
MounRiver_Studio7 小时前
RISC-V IDE MRS2使用笔记(七):书签与笔记功能
ide·嵌入式·risc-v
切糕师学AI1 天前
ARM 架构中的 PRIMASK、FAULTMAST、BASEPRI 寄存器
arm开发·架构·嵌入式·寄存器
迷人的星空1 天前
嵌入式软件调试指南:一看就懂,上手就用
嵌入式
Hello_Embed2 天前
FreeRTOS 入门(二十六):队列创建与读写 API 实战解析
笔记·学习·操作系统·嵌入式·freertos
切糕师学AI2 天前
ARM架构程序状态寄存器(PSR)详解:从基础概念到现代实现
arm开发·架构·嵌入式·程序状态寄存器·psr
一枝小雨2 天前
单例模式简析:C语言实现单例模式
c语言·单例模式·嵌入式
才鲸嵌入式2 天前
STM32 USB协议栈源码分析
stm32·单片机·嵌入式·驱动·usb·硬件·phy
IAR爱亚系统3 天前
在IAR Embedded Workbench for Renesas RH850中开发和调试Renesas RH850 MCU
嵌入式·嵌入式软件开发·iar·汽车嵌入式
墨染倾城殇3 天前
车规级蓝牙模组BT3721V:汽车无钥匙进入系统解决方案
嵌入式·蓝牙模块·汽车电子·车规级蓝牙·飞易通
rechol3 天前
pendsv任务切换
嵌入式·freertos·任务切换