我有 systemd 服务,比如 xyzWarmup.service。
这是服务文件
[Unit]
Description=Xyz agent.
After=fooAfter.service
Before=fooBefore1.service
Before=fooBefore2.service
[Service]
# During boot the xyz.sh script reads input from /dev/console. If the user
# hits <ESC>, it will skip waiting for xyz and abc to startup.
Type=oneshot
StandardInput=tty
StandardOutput=tty
ExecStart=/usr/bin/xyz.sh start
RemainAfterExit=True
ExecStop=/usr/bin/xyz.sh stop
[Install]
WantedBy=multi-user.target
以下是xyz.sh的部分。
#! /bin/bash
#
### BEGIN INIT INFO
# Required-Stop: Post
### END INIT INFO
XYZ=/usr/bin/Xyz
prog="Xyz"
lockfile=/var/lock/subsys/$prog
msg="Completing initialization"
start() {
# Run wfw in background
ulimit -c 0
# wfw has a default timeout of 10 minutes - just pick a large value
wfw -t 3600 xyz abc >/dev/null 2>&1 &
PID=$!
# Display the message here after spawning wfw so Esc can work
echo -n $"$msg (press ESC to skip): " > /dev/console
while [ 1 ]; do
read -s -r -d "" -N 1 -t 0.2 CHAR || true
if [ "$CHAR" = $'\x1B' ]; then
kill -9 $PID 2>/dev/null
# fall through to wait for process to exit
fi
STATE="`ps -p $PID -o state=`"
if [ "$STATE" = "" ]; then
# has exited
wait $PID 2>/dev/null
if [ $? -eq 0 ]; then
echo "[ OK ]"
echo
exit 0
else
echo "[ FAILED ]"
echo "This is failure"
exit 1
fi
fi
done
}
在代码“if [ "$STATE" = "" ];”中的这一行之后,我看不到任何回显消息。当此脚本在启动期间运行时,我只看到来自脚本的以下消息
Completing initialization (press ESC to skip):
我在屏幕上没有看到“[ OK ]”或“[ FAILED ]”。
当我在 Fedora14 中将此脚本用作 initscript 时,我曾经看到过这些消息。有一次,我转向了 systemd。我开始看到这个问题。
systemd 版本为:systemd-201-2.fc18.9.i686 和 systemd.default_standard_output=tty
请帮忙。