![如何在关机前运行脚本以使用 systemd 离开域?](https://linux22.com/image/191492/%E5%A6%82%E4%BD%95%E5%9C%A8%E5%85%B3%E6%9C%BA%E5%89%8D%E8%BF%90%E8%A1%8C%E8%84%9A%E6%9C%AC%E4%BB%A5%E4%BD%BF%E7%94%A8%20systemd%20%E7%A6%BB%E5%BC%80%E5%9F%9F%EF%BC%9F.png)
在关闭之前,我想运行一个脚本,使实例在关闭时离开我们的域。
我有这个文件.service
:
[Unit]
Description=Service to remove domain join
After=network-online.target sssd.service realmd.service dbus.service dbus.socket
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/true
ExecStop=/tmp/autoDomainLeave.sh
[Install]
WantedBy=poweroff.target
我的脚本基本上从 AWS 机密存储中获取服务帐户详细信息,然后运行命令:
echo $Password | realm leave --verbose --user=$Username corpnetwork.net
我在脚本中添加了一些调试,这是我收到的错误消息:
realm: Couldn't connect to realm service:
Error calling StartServiceByName for org.freedesktop.realmd:
GDBus.Error:org.freedesktop.systemd1.ShuttingDown:
Refusing activation, D-Bus is shutting down.
我已阅读所有文档,但仍然无法使其正常工作;有人可以帮忙吗?