如何使用 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.
相关推荐
左手厨刀右手茼蒿2 天前
PCIe设备驱动开发:从枚举到DMA传输的完整链路
linux·嵌入式·系统内核
济6172 天前
I.MX6U Linux 驱动开发篇---零基础必看!中断实验(按键中断 + 定时器消抖 + 设备树配置实战教程)--- Ubuntu20.04
linux·驱动开发·嵌入式·嵌入式linux驱动开发
凉、介2 天前
Linux 设备驱动匹配机制
linux·笔记·单片机·学习·操作系统·嵌入式
凉、介3 天前
Virtio 系列(一):框架概览
笔记·学习·嵌入式·虚拟化·virtio
charlie1145141913 天前
RK3506B: buildroot:出一份正规的最小 rootfs
开发语言·嵌入式·开源项目·rk3506b
piaoyiren3 天前
串口指令控制8路LED音乐流水灯程序
51单片机·嵌入式·普中
青衫嵌入式4 天前
懂了汽车,就懂了 C 语言面向对象编程
嵌入式
华清远见IT开放实验室4 天前
从嵌入式到具身智能:嵌入式AI机器狗FS_D2,一站式打通高校嵌入式+AI+机器人教学全链路
人工智能·ai·嵌入式·实验室·具身智能·高校
piaoyiren4 天前
STC8 6 位数字密码锁程序功能
51单片机·嵌入式·普中
dddwjzx5 天前
嵌入式Linux C应用编程入门——高级I/O
linux·嵌入式