尧图网站建设 尧图网络
  • 首页
  • 关于我们
  • 服务项目
  • 案例展示
  • 建站流程
  • 资讯中心
  • 联系我们
首页/资讯中心/详情

system自启动

system自启动
📅 发布时间:2026/6/18 15:48:30

system自启动

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
BindsTo=containerd.service
After=network-online.target containerd.service
Wants=network-online.target
Requires=docker.socket[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock \--data-root={{docker_data_root}}
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes# kill only the docker process, not all processes in the cgroup
KillMode=process[Install]
WantedBy=multi-user.target

  

---

### ✅ 配置说明

```ini
StartLimitBurst=3
StartLimitInterval=60s
```

- **StartLimitBurst=3**:在 `StartLimitInterval` 时间内,最多允许服务启动失败 3 次。
- **StartLimitInterval=60s**:在 60 秒内统计启动失败次数。

如果在这 60 秒内服务启动失败达到 3 次,systemd 将**停止尝试重启该服务**,并标记为失败状态。

---

### ⚠️ 版本兼容性说明

你注释里提到的版本变动是正确的:

| systemd 版本 | 变动说明 |
|--------------|----------|
| **229** | `StartLimitBurst` 和 `StartLimitInterval` 从 `[Service]` 段**移动**到了 `[Unit]` 段。 |
| **230** | `StartLimitInterval` 被重命名为 `StartLimitIntervalSec`,但旧名仍然兼容。 |

---

### ✅ 建议写法(兼容旧版本)

为了兼容 systemd 229 及更早版本,**建议将这些选项放在 `[Unit]` 段**,并使用旧名称:

```ini
[Unit]
Description=My Service
StartLimitBurst=3
StartLimitInterval=60s

[Service]
ExecStart=/usr/bin/my-service
Restart=on-failure
```

---

### ❌ 不推荐的做法

- 不要把 `StartLimit*` 选项放在 `[Service]` 段,除非你必须支持 systemd < 229(非常罕见)。
- 不要混用 `StartLimitInterval` 和 `StartLimitIntervalSec`,虽然兼容,但会造成混淆。

---

### ✅ 现代写法(systemd 230+)

如果你**只支持 systemd 230 及以上版本**,可以写成:

```ini
[Unit]
StartLimitBurst=3
StartLimitIntervalSec=60s
```

---

### ✅ 检查 systemd 版本

你可以用以下命令查看当前系统的 systemd 版本:

```bash
systemctl --version
```

---

### ✅ 总结

| 目标 | 建议写法 |
|------|----------|
| 最大兼容性(229+) | 放在 `[Unit]` 段,使用 `StartLimitBurst=` 和 `StartLimitInterval=` |
| 现代系统(230+) | 使用 `StartLimitIntervalSec=` 替代 `StartLimitInterval=` |

---

如果你有具体的 unit 文件或想知道某个系统是否兼容,我可以帮你检查。

相关新闻

  • 2025.11.13博客
  • [CSP-S 2025] 社团招新 club
  • 【排查实录】Web 页面能打开,服务器能通接口,客户端却访问失败?原因全在这! - 实践

最新新闻

  • STM8L15x开发板实测DS18B20温度采集工程(IAR环境,含完整驱动与调试脚本)
  • kafka源码-@KafkaListener消费端的poll调用逻辑
  • 3分钟学会:Windows上最轻量的安卓APK安装工具完全指南
  • OA与CMS系统漏洞挖掘:从权限边界突破到实战提权
  • TC820双斜积分ADC:从原理到3位半数字电压表设计实战
  • 豆包智能感从何而来:五层能力涌现机制解析

日新闻

  • 5分钟掌握Python进化算法:Geatpy高性能优化工具完全指南
  • Microchip 24AA044 EEPROM选型与应用全指南:从参数解析到实战编程
  • 华为的鸿蒙到底有多牛?为什么称作遥遥领先?

周新闻

  • 3步解锁iOS设备:applera1n激活锁绕过完全指南
  • 39 2026 人工智能证书终极盘点,普通人选 AI 证书可以从这些方向入手
  • Redis 暴露公网有多危险?从端口检查到补救步骤

月新闻

  • 【总结】入门篇:50句话让你记住架构核心概念
  • WeChatMsg技术方案解析:实现Mac微信数据自主管理的完整解决方案
  • WeChatMsg:革新性微信数据备份方案,打造你的专属数字记忆库

关于尧图

  • 公司简介
  • 团队介绍
  • 企业文化
  • 荣誉资质

服务项目

  • 定制开发
  • 电商建站
  • UI 设计
  • 运维服务

快速链接

  • 案例展示
  • 建站流程
  • 常见问题
  • 资讯中心

联系方式

  • 📍北京市朝阳区互联网产业园 A 座 10 层
  • 📞400-888-8888
  • ✉️contact@rkmt.cn
  • 🕐周一至周日 9:00-21:00

© 2024 北京尧图网络科技有限公司 版权所有 | 京 ICP 备 XXXXXXXX 号