我们有一个使用sysV的旧版本的Ubuntu(12.04)。 由于LTS耗尽,我们需要切换到16.04。
其中一个主要变化是从SysV到systemd的变化。 我们注意到当我们做这个改变的时候,我们所有执行了ssh root@thisismyhostname "shutdown -h now"都会挂起,之前它会启动closures,返回EXIT_SUCCESS并closures连接。 然而,systemd似乎仍然是开放的。 我find了解决办法,那就是我们需要安装并启用PAM,并且必须从shutdown -h now更改为systemctl poweroff这样systemd将在closures之前遍历连接并closures它们,这是我们想要的function。
现在发生的问题是大概1/20的时间,似乎有一个竞争条件发生在关机将获得足够的CPU使系统closures,这将导致SSH返回255(连接返回代码closures)而不是返回从SSH运行的关机命令的EXIT_SUCCESS。
我们(不幸的是)在调用shutdown的代码中有不止一个地方,而且我觉得要检查EXIT_SUCCESS或SSH的255是有点难解的办法。 有没有人知道一个办法让systemd的Ubuntu 16.04返回EXIT_SUCCESS后调用systemctl poweroff ?
考虑使用systemctl的能力,通过SSH发送自己的命令到远程主机。
从手册页:
-H, --host= Execute the operation remotely. Specify a hostname, or a username and hostname separated by "@", to connect to. The hostname may optionally be suffixed by a container name, separated by ":", which connects directly to a specific container on the specified host. This will use SSH to talk to the remote machine manager instance. Container names may be enumerated with machinectl -H HOST.
它的工作很像这样:
# ssh-copy-id -i ~/.ssh/id_ed25519.pub 172.25.50.100 ... # systemctl -H 172.25.50.100 status ● 172.25.50.100 State: degraded Jobs: 0 queued Failed: 1 units Since: Thu 2017-03-02 01:56:07 EST; 17h ago CGroup: / # systemctl -H 172.25.50.100 poweroff # echo $? 0