我正在尝试使用 init.d 脚本在 Ubuntu 上自动启动 Hudson。该脚本在手动调用时工作正常(即使用 ./hudson start),并且在 rc2-rc5 中有 update-rc.d-生成的符号链接,但它不会在重新启动时启动。有谁知道是什么导致它不起作用?脚本如下(hudson.log 日志文件在启动时创建,但不包含任何输出):
#!/bin/sh
### BEGIN INIT INFO
# Provides: hudson
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Hudson at boot
# Description: Start the Hudson CI server at boot
### END INIT INFO
CTL=/home/jcss-dev/hudson.war
LOGFILE=/home/jcss-dev/hudson.log
case "$1" in
start)
pid=`/bin/ps -Af | /bin/grep "hudson.war" | /bin/grep -v /bin/grep | /usr/bin/awk '{print $2}'`
if [ "$pid" = "" ]; then
echo -n "Starting Hudson... "
su - the-user-account-name -c "/usr/bin/java -jar $CTL > $LOGFILE 2>&1 &"
else
echo -n "Hudson is already running"
fi
;;
stop)
pid=`/bin/ps -Af | /bin/grep "hudson.war" | /bin/grep -v /bin/grep | /usr/bin/awk '{print $2}'`
if [ "$pid" != "" ]; then
echo -n "Stopping Hudson... "
kill -9 $pid
else
echo "Hudson is not running"
fi
;;
status)
pid=`/bin/ps -Af | /bin/grep "hudson.war" | /bin/grep -v /bin/grep | /usr/bin/awk '{print $2}'`
if [ "$pid" != "" ]; then
echo -n "Hudson is running"
else
echo -n "Hudson is not running"
fi
;;
*)
echo "Usage $0 start|stop|status"
exit 1
;;
esac
exit 0