2.4. 使用 OSTree 系统的 systemd 自动化集成过程


重要

您必须包含蓝图文件中使用 systemd 的 OSTree 系统的整个 自动恢复过程

作为用例,请考虑以下示例情况,其中您要为使用 systemd 的 OSTree 系统自动化自动 恢复过程

流程

  1. 使用以下示例创建蓝图文件:

    [[customizations.files]]
    path = "/usr/lib/systemd/system/microshift.service.d/10-auto-recovery.conf"
    data = """
    [Unit]
    OnFailure=microshift-auto-recovery.service
    """
    
    [[customizations.files]]
    path = "/usr/lib/systemd/system/microshift-auto-recovery.service"
    data = """
    [Unit]
    Description=MicroShift auto-recovery
    
    [Service]
    Type=oneshot
    ExecStart=/usr/bin/microshift-auto-recovery
    
    [Install]
    WantedBy=multi-user.target
    """
    
    [[customizations.files]]
    path = "/usr/bin/microshift-auto-recovery"
    mode = "0755"
    data = """
    #!/usr/bin/env bash
    set -xeuo pipefail
    
    # If greenboot uses a non-default file for clearing boot_counter, use boot_success instead.
    if grep -q  "/boot/grubenv" /usr/libexec/greenboot/greenboot-grub2-set-success; then
        if grub2-editenv - list | grep -q ^boot_success=0; then
            echo "Greenboot didn't decide the system is healthy after staging a new deployment."
            echo "Quitting to not interfere with the process"
            exit 0
        fi
    else
        if grub2-editenv - list | grep -q ^boot_counter=; then
            echo "Greenboot didn't decide the system is healthy after staging a new deployment."
            echo "Quitting to not interfere with the process"
            exit 0
        fi
    fi
    
    /usr/bin/microshift restore --auto-recovery /var/lib/microshift-auto-recovery
    /usr/bin/systemctl reset-failed microshift
    /usr/bin/systemctl start microshift
    
    echo "DONE"
    """
    Copy to Clipboard Toggle word wrap
  2. 有关后续步骤,请参阅准备镜像构建
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部