如何使用 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.
相关推荐
PinoLio15 小时前
鲁班猫烧录镜像win10平台
嵌入式·鲁班猫
不脱发的程序猿21 小时前
使用Python高效对比多个相似的CAN DBC数据
python·单片机·嵌入式硬件·嵌入式
无垠的广袤21 小时前
【工业树莓派 CM0 NANO 单板计算机】YOLO26 部署方案
linux·python·opencv·yolo·树莓派·目标识别
皮蛋sol周1 天前
嵌入式学习数据结构(二)双向链表 内核链表
linux·数据结构·学习·嵌入式·arm·双向链表
cui__OaO1 天前
Linux驱动--基于驱动设备分离的按键中断驱动
linux·运维·服务器·嵌入式
Hello_Embed2 天前
RS485 双串口通信 + LCD 实时显示(DMA+IDLE 空闲中断版)
笔记·单片机·学习·操作系统·嵌入式·freertos
Hello_Embed2 天前
RS485 双串口通信 + LCD 实时显示(中断版)
c语言·笔记·单片机·学习·操作系统·嵌入式
要做朋鱼燕2 天前
【AES加密专题】3.工具函数的编写(1)
笔记·密码学·嵌入式·aes
风痕天际3 天前
ESP32-S3开发教程三:蜂鸣器与FreeRTOS多任务协同
单片机·嵌入式·freertos·esp32s3
kida_yuan4 天前
【Linux】在树莓派上搭建自建 Git 服务(基于 GitLab)- 实战笔记与运维清单
运维·gitlab·树莓派