Skip to content

fix: change clipboard service restart policy to always#252

Merged
18202781743 merged 1 commit into
linuxdeepin:masterfrom
18202781743:master
Mar 3, 2026
Merged

fix: change clipboard service restart policy to always#252
18202781743 merged 1 commit into
linuxdeepin:masterfrom
18202781743:master

Conversation

@18202781743
Copy link
Copy Markdown
Contributor

Changed the systemd service restart policy for dde-clipboard from "on-
failure" to "always" to ensure the clipboard service automatically
restarts even after being manually killed. Previously, when users killed
the clipboard process via killall command, the service would not restart
because it wasn't considered a failure condition by systemd.

Log: Fixed clipboard service not restarting after being manually killed

Influence:

  1. Test killing the dde-clipboard process manually and verify it
    restarts automatically
  2. Verify clipboard functionality continues working after service
    restart
  3. Test system startup to ensure clipboard service starts properly
  4. Monitor system resources to ensure continuous restart doesn't cause
    issues

fix: 修改剪贴板服务重启策略为始终重启

将 dde-clipboard 的 systemd 服务重启策略从 "on-failure" 改为 "always",
确保剪贴板服务在被手动终止后也能自动重启。之前当用户通过 killall 命令杀
死剪贴板进程时,由于 systemd 不认为这是故障条件,服务不会重新启动。

Log: 修复手动杀死剪贴板服务后无法自动重启的问题

Influence:

  1. 测试手动杀死 dde-clipboard 进程并验证其自动重启
  2. 验证剪贴板功能在服务重启后继续正常工作
  3. 测试系统启动时剪贴板服务是否正确启动
  4. 监控系统资源,确保持续重启不会导致问题

PMS: BUG-351483

Changed the systemd service restart policy for dde-clipboard from "on-
failure" to "always" to ensure the clipboard service automatically
restarts even after being manually killed. Previously, when users killed
the clipboard process via killall command, the service would not restart
because it wasn't considered a failure condition by systemd.

Log: Fixed clipboard service not restarting after being manually killed

Influence:
1. Test killing the dde-clipboard process manually and verify it
restarts automatically
2. Verify clipboard functionality continues working after service
restart
3. Test system startup to ensure clipboard service starts properly
4. Monitor system resources to ensure continuous restart doesn't cause
issues

fix: 修改剪贴板服务重启策略为始终重启

将 dde-clipboard 的 systemd 服务重启策略从 "on-failure" 改为 "always",
确保剪贴板服务在被手动终止后也能自动重启。之前当用户通过 killall 命令杀
死剪贴板进程时,由于 systemd 不认为这是故障条件,服务不会重新启动。

Log: 修复手动杀死剪贴板服务后无法自动重启的问题

Influence:
1. 测试手动杀死 dde-clipboard 进程并验证其自动重启
2. 验证剪贴板功能在服务重启后继续正常工作
3. 测试系统启动时剪贴板服务是否正确启动
4. 监控系统资源,确保持续重启不会导致问题

PMS: BUG-351483
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @18202781743, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这段代码修改是对 dde-clipboard 的 systemd 服务单元配置文件(.service.in)进行的审查。以下是从语法逻辑、代码质量、代码性能和代码安全四个维度进行的详细审查和改进意见:

1. 语法逻辑

  • 审查结果通过
  • 分析
    • Restart=always 是 systemd 配置文件中合法的指令值。
    • RestartSec=3s 的格式也是正确的。
    • 修改后的逻辑符合 systemd 的配置规范。

2. 代码质量

  • 审查结果需要改进
  • 分析
    • 当前逻辑:将 Restart=on-failure 改为 Restart=always 意味着无论服务是正常退出(退出码 0)还是异常退出(崩溃或非零退出码),systemd 都会无条件地重启该服务。
    • 潜在风险:如果 dde-clipboard 程序本身存在逻辑错误导致它启动后立即正常退出(例如检测到配置缺失主动退出),或者用户主动终止了该服务,Restart=always 会导致 systemd 无限循环地尝试重启该服务。这可能导致系统日志被刷屏,或者消耗不必要的 CPU 资源。
    • 建议
      • 通常情况下,对于用户态的桌面组件服务,on-failure 是更安全、更合理的选择。它仅在程序崩溃(非零退出码或被信号终止)时重启,而在程序正常退出(如用户注销、程序主动关闭)时保持停止状态。
      • 除非该程序被设计为必须作为一个守护进程永久运行(即使崩溃也要无限重启),否则不建议使用 always
      • 如果确实需要确保服务一直运行,建议在程序内部增加健壮性检查(例如启动前检查依赖),避免启动失败导致的无限重启风暴。

3. 代码性能

  • 审查结果无直接影响
  • 分析
    • Restart=always 本身不会改变程序运行时的性能。
    • 间接影响:如代码质量部分所述,如果因为配置错误导致服务不断重启,RestartSec=3s 的设置意味着每 3 秒启动一次进程,这会频繁消耗 CPU 和内存资源进行进程创建和销毁,导致系统性能下降。

4. 代码安全

  • 审查结果存在潜在风险
  • 分析
    • 重启风暴:如果服务存在漏洞导致启动即崩溃,Restart=always 会导致系统不断重启该进程。虽然 RestartSec=3s 提供了 3 秒的缓冲,但在某些攻击场景下(如利用特定输入导致服务崩溃),这可能被利用来进行简单的拒绝服务攻击,占用系统资源。
    • 状态丢失:如果服务是因为内部严重错误而主动退出,强制重启可能会导致数据损坏或状态不一致。
    • 建议:保持 on-failure 策略,或者结合 RestartPreventExitStatus 指令来定义哪些退出码是不应该重启的。

总结与改进建议

结论
不建议将 Restart 策略从 on-failure 修改为 alwayson-failure 更加符合桌面环境服务组件的常规行为逻辑,既能保证崩溃后的自动恢复,又能避免正常退出时的无谓重启。

改进建议

  1. 回滚修改:建议保持原有的 Restart=on-failure

    Restart=on-failure
  2. 如果必须使用 always(例如业务要求该服务绝对不能停),请务必确保程序内部逻辑足够健壮,能够处理所有的启动失败情况,避免无限循环。同时,可以考虑增加 StartLimitIntervalStartLimitBurst 来限制重启频率,防止重启风暴。

    示例配置(限制 10 分钟内最多重启 5 次):

    Restart=always
    RestartSec=3s
    StartLimitIntervalSec=600
    StartLimitBurst=5
  3. 精细化控制:如果程序有特定的退出码表示“不可恢复的错误”或“用户主动退出”,可以使用 RestartPreventExitStatus 来禁止在这些情况下重启。

    示例配置(退出码为 3 时不重启):

    Restart=on-failure
    RestartPreventExitStatus=3

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, wjyrich

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@18202781743 18202781743 merged commit f6d985c into linuxdeepin:master Mar 3, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants