如何使用 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.
相关推荐
带土12 小时前
6. exec函数族和守护进程
嵌入式
Freak嵌入式20 小时前
MicroPython对接大模型:uopenai + 火山方舟实现文字聊天和图片理解
ide·驱动开发·ai·llm·嵌入式·micropython·upypi
凉、介1 天前
从设备树到驱动源码:揭秘嵌入式 Linux 中 MMC 子系统的统一与差异
linux·驱动开发·笔记·学习·嵌入式·sd·emmc
CinzWS2 天前
A53电源管理(下):DVFS与热管理的硬件实现——ARM芯片的“冷静艺术“
arm开发·嵌入式·芯片验证·原型验证·a53
CinzWS2 天前
QSPI协议 - 超越XIP:在内存映射、四线模式与DMA协同中压榨极致性能
嵌入式·qspi·芯片验证
FreakStudio2 天前
MicroPython对接大模型:uopenai + 火山方舟实现文字聊天和图片理解
python·单片机·ai·嵌入式·面向对象·电子diy
Sss_Ass2 天前
跟着老师不迷路系列---跟着李述铜老师学习汇编语言之基本汇编程序符号绑定语句
学习·嵌入式·汇编语言·李述铜·符号绑定语句
Z文的博客2 天前
SLCAN工程搭建与实现教程(下)
stm32·单片机·嵌入式·can
Jason_zhao_MR2 天前
STM32MP135F安全芯引入!米尔MYD-YF13X系统、安全、功能三重升级
stm32·嵌入式硬件·安全·嵌入式
LN花开富贵3 天前
【ROS】鱼香ROS2学习笔记二
linux·笔记·python·学习·嵌入式