如何使用 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.
相关推荐
飞凌嵌入式15 小时前
飞凌嵌入式i.MX8M Mini核心板已支持Linux6.1
嵌入式硬件·嵌入式·飞凌嵌入式
JaneZJW19 小时前
江科大STM32入门——读写备份寄存器(BKP)&实时时钟(RTC)笔记整理
笔记·stm32·单片机·嵌入式·rtc·bkp
国产化创客2 天前
国产OS移植工业物联网OPC-UA协议
物联网·嵌入式·通信协议
国产化创客2 天前
RK3399开发板Linux实时性改造
linux·物联网·嵌入式·实时操作系统
国产化创客3 天前
嵌入式系统Linux实时化(一)Linux实时化技术路径
物联网·嵌入式·实时操作系统·xenomai
Bull-man3 天前
LS1046+XILINX XDMA PCIE调通
linux·arm开发·fpga开发·嵌入式
JaneZJW5 天前
江科大STM32入门——UART通信笔记总结
笔记·stm32·单片机·嵌入式
YunB西风英5 天前
(STM32笔记)十二、DMA的基础知识与用法 第三部分
笔记·stm32·单片机·嵌入式硬件·dma·嵌入式
JaneZJW6 天前
江科大STM32入门——IIC通信笔记总结
c语言·笔记·stm32·单片机·嵌入式硬件·嵌入式·iic
JaneZJW6 天前
江科大STM32入门——SPI通信笔记总结
笔记·stm32·单片机·嵌入式硬件·嵌入式·spi