0

我有一个奇怪的现象,当我们从 SLES 11 迁移到 SLES 12 (SuSE Enterprise Linux) 时,一个长期存在的管理脚本开始或多或少地运行两次。/etc/rc.status我可以通过一个最小的示例将其归结为与之相关test.sh

#!/bin/bash
echo Sourcing rc.status
. /etc/rc.status
echo End of script

当它status作为参数运行时(我的脚本的一个常见用例)......

./test.sh status

...我观察到这个输出:

Sourcing rc.status
Sourcing rc.status
End of script
End of script

是什么赋予了?

4

1 回答 1

0

原来在 SLES/etc/rc.status文件中有一些诗歌:

user@host:~> diff rc.status.sles11 /etc/rc.status
34a35,92
> # Check if the service is used under systemd but not started with
> if test -z "$SYSTEMD_NO_WRAP" && /usr/bin/mountpoint -q /sys/fs/cgroup/systemd; then
>     if test $PPID -ne 1 -a $# -eq 1 ; then
>       _rc_base=
...

所以解决办法是SYSTEMD_NO_WRAP在采购前设置/etc/rc.status

#!/bin/bash
echo Sourcing rc.status
SYSTEMD_NO_WRAP=1
. /etc/rc.status
echo End of script

这给出了预期的行为:

Sourcing rc.status
End of script
于 2018-04-17T20:17:21.330 回答