如何使用 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.
相关推荐
比老马还六1 天前
Bipes-Blockly项目二次开发/Coze智能体(十)
前端·嵌入式
ForTime3 天前
HAL库大雷预警!STM32 HAL库CAN启动超时解决办法
嵌入式
大辉狼_音频架构3 天前
Vol. NXP SOF Arch
嵌入式
用户805533698035 天前
主线 U-Boot 上 RK3506:和闭源 rkbin 拔河的三个隐性契约
linux·嵌入式
荣--8 天前
在 strip 二进制 + 基址随机化的栈里做崩溃去重 —— 三阶段算法与一行 Crash Flag
嵌入式·崩溃分析·栈指纹·去重算法
释然小师弟8 天前
Android开发十年:反思与回顾
android·后端·嵌入式
FreakStudio9 天前
W55MH32L-EVB 上手测评:硬件 TCP/IP 加持的以太网单片机,MicroPython 零门槛开发
python·单片机·嵌入式·大学生·面向对象·并行计算·电子diy·电子计算机
bush414 天前
嵌入式linux学习记录十四、术语
linux·嵌入式
国产化创客14 天前
ESP32 CameraWebServer 原生摄像头项目全解析
物联网·开源·嵌入式·实时音视频·智能硬件
goldenrolan14 天前
学习型红外控制系统稳定性挂测工装专项总结
软件测试·python·stm32·嵌入式·红外