2.3. 使用 RPM 系统的 systemd 自动化集成过程
注意
当 microshift.service 进入失败状态时,systemd 将启动 microshift-auto-recovery.service 单元。这个单元执行 自动恢复恢复过程 并重启 MicroShift。
作为用例,请考虑以下示例情况,其中您要为使用 systemd 的 RPM 系统自动化自动 恢复过程。
流程
运行以下命令,为
microshift.service创建目录:$ sudo mkdir -p /usr/lib/systemd/system/microshift.service.d当
microshift.service失败时,指示systemd运行microshift-auto-recovery.service,请运行以下命令来创建10-auto-recovery.conf文件:$ sudo tee /usr/lib/systemd/system/microshift.service.d/10-auto-recovery.conf > /dev/null <<'EOF' [Unit] OnFailure=microshift-auto-recovery.service EOF运行以下命令来创建
microshift-auto-recovery.service文件:$ sudo tee /usr/lib/systemd/system/microshift-auto-recovery.service > /dev/null <<'EOF' [Unit] Description=MicroShift auto-recovery [Service] Type=oneshot ExecStart=/usr/bin/microshift-auto-recovery [Install] WantedBy=multi-user.target EOF运行以下命令来创建
microshift-auto-recovery脚本:$ sudo tee /usr/bin/microshift-auto-recovery > /dev/null <<'EOF' #!/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 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" EOF运行以下命令使脚本可执行:
$ sudo chmod +x /usr/bin/microshift-auto-recovery运行以下命令来重新载入系统配置:
$ sudo systemctl daemon-reload