Fer*_*ite 3 bash centos startup
我需要在Centos(5.9)启动时启动Java应用程序.
我试图在启动时在Centos上启动一个简单的脚本(名为"lanzar.sh"):
#!/bin/sh
cd /home/someuser/Desktop/Dist
java -jar SomeApp.jar
Run Code Online (Sandbox Code Playgroud)
我将"/ bin/sh /home/someuser/Desktop/Dist/lanzar.sh"行附加到/etc/rc.d/rc.local.但java应用程序无法启动.我有:
我的rc.loca看起来像:
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
#
#Some comment
#Some comment
#Some comment
touch /var/lock/subsys/local
/bin/sh /home/fernando/Desktop/Dist/lanzar.sh
Run Code Online (Sandbox Code Playgroud)
注意:我之前已经知道类似的问题,但在测试了我通过谷歌搜索找到的许多答案后没有成功,我不得不自己问这个问题.
我强烈建议您浏览/etc/init.d服务器/etc/rc3.d目录和目录.查看文件名如何与目录中/etc/rc3.d的名称符号链接/etc/init.d.请注意/etc/rc3.d所有文件的开头Sxx或Kxx wherexx是否00为99.之间的数字.
我要告诉你的是正式的错误.这些启动脚本今天比我描述的更复杂,但它是正在发生的事情的基本轮廓.
在标准的Unix和Linux中,启动脚本通常存储在/etc/init.d,然后链接到代表服务器的Init状态的/etc/rcX.d目录.(是的,我正在链接到SCO Unix页面,但它们都非常相似).X
请注意,Init State 3以多用户模式运行,并且所有后台进程都已启动.这就是我告诉你要看的原因/etc/rc3.d.
当服务器进入init状态时,它将S按字母顺序运行所有脚本.它使用start后面的参数运行每个脚本.所以,S01xxxx之前S03xxx开始之前的开始S99xxxxx.
当服务器退出该init状态时,它将K按字母顺序运行所有脚本,并将stop参数传递给它们.
现在,Centos,Redhat和Fedora设置为您处理了很多这样的事情.您可以指定依赖的服务,并指出启动和关闭顺序.但是,没有任何东西阻止您修改启动脚本并创建自己的链接.
顺便说一下,谈论启动和关闭的Java程序...... Jenkins是一个Java程序,它以与程序非常相似的方式启动.这是/etc/init.d我从Jenkins网站上下载的脚本:
#!/bin/bash
#
# Startup script for Jenkins
#
# chkconfig: - 84 16
# description: Jenkins CI server
# Source function library.
. /etc/rc.d/init.d/functions
[ -z "$JAVA_HOME" -a -x /etc/profile.d/java.sh ] && . /etc/profile.d/java.sh
JENKINS_HOME=/var/jenkins
WAR="$JENKINS_HOME/jenkins.war"
LOG="/var/log/jenkins.log"
LOCK="/var/lock/subsys/jenkins"
export JENKINS_HOME
RETVAL=0
pid_of_jenkins() {
pgrep -f "java.*jenkins"
}
start() {
[ -e "$LOG" ] && cnt=`wc -l "$LOG" | awk '{ print $1 }'` || cnt=1
echo -n $"Starting jenkins: "
cd "$JENKINS_HOME"
nohup java -jar "$WAR" --httpPort=-1 --ajp13Port=8010 --prefix=/jenkins >> "$LOG" 2>&1 &
while { pid_of_jenkins > /dev/null ; } &&
! { tail +$cnt "$LOG" | grep -q 'Winstone Servlet Engine .* running' ; } ; do
sleep 1
done
pid_of_jenkins > /dev/null
RETVAL=$?
[ $RETVAL = 0 ] && success $"$STRING" || failure $"$STRING"
echo
[ $RETVAL = 0 ] && touch "$LOCK"
}
stop() {
echo -n "Stopping jenkins: "
pid=`pid_of_jenkins`
[ -n "$pid" ] && kill $pid
RETVAL=$?
cnt=10
while [ $RETVAL = 0 -a $cnt -gt 0 ] &&
{ pid_of_jenkins > /dev/null ; } ; do
sleep 1
((cnt--))
done
[ $RETVAL = 0 ] && rm -f "$LOCK"
[ $RETVAL = 0 ] && success $"$STRING" || failure $"$STRING"
echo
}
status() {
pid=`pid_of_jenkins`
if [ -n "$pid" ]; then
echo "jenkins (pid $pid) is running..."
return 0
fi
if [ -f "$LOCK" ]; then
echo $"${base} dead but subsys locked"
return 2
fi
echo "jenkins is stopped"
return 3
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit $RETVAL
Run Code Online (Sandbox Code Playgroud)
它会给你一些工作.