我有一个奇怪的现象,当我们从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
是什么给出了?
答案 0 :(得分: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