我正在尝试使用init.d脚本在启动时自动在Ubuntu上启动Hudson。手动调用时脚本工作正常(即使用./hudson启动),并且在rc2-rc5中有update-rc.d生成的sym-links,但它在重启时不启动。有谁知道可能导致它不起作用的原因?该脚本如下(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
答案 0 :(得分:1)
如果手动运行,意味着脚本没有问题...... 确保你在/etc/init.d文件夹中复制/移动它并检查rc [2345] .d dirs中的链接文件。
也许这个问题应该在serverfault.com
答案 1 :(得分:0)
你有没有把它添加到rc ??
sudo update-rc.d hudson.sh defaults
对我有用......
答案 2 :(得分:0)
冒着问一个基本的问题的风险,我假设你的脚本的开始部分的su命令有“jcss-dev”代替“the-user-account-name”?