如何使用 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.
相关推荐
星源~5 小时前
tree 命令集成到 Git Bash:可视化目录结构的指南
git·单片机·物联网·嵌入式·项目开发
糖果罐子♡17 小时前
MQTT 入门指南(一)
物联网·mqtt·嵌入式·通信协议
linweidong2 天前
物联网MQTT协议与实践:从零到精通的硬核指南
物联网·mqtt·websocket·嵌入式·iot·tdengine·工业物联网
kyle~2 天前
ROS2---话题重映射
机器人·嵌入式·ros·控制·电控
切糕师学AI12 天前
半导体行业中的专用标准产品ASSP是什么?
arm开发·嵌入式硬件·嵌入式·计算机体系结构
想躺在地上晒成地瓜干12 天前
树莓派超全系列教程文档--(66)rpicam-apps可用选项介绍之视频选项
树莓派·摄像头·raspberrypi·树莓派教程·拍视频
飞凌嵌入式12 天前
基于飞凌RK3576核心板的国产智能割草机器人设计方案
人工智能·机器人·嵌入式
凉、介13 天前
CPU Cache 的映射与寻址
linux·arm开发·数据库·redis·缓存·嵌入式
华清远见成都中心14 天前
Linux嵌入式和单片机嵌入式的区别?
linux·运维·单片机·嵌入式
Jason_zhao_MR14 天前
多协议物联网关的方案测试-基于米尔全志T536开发板
arm开发·嵌入式硬件·mcu·物联网·嵌入式