bash - Launch Java application at startup on Centos -
i need launch java application on centos (5.9) startup.
i trying start simple script (named "lanzar.sh") on centos @ boot time:
#!/bin/sh cd /home/someuser/desktop/dist java -jar someapp.jar
i append line "/bin/sh /home/someuser/desktop/dist/lanzar.sh" /etc/rc.d/rc.local. java application not start. have:
- granted 755 rights /etc/rc.d/rc.local file
- write content of "lanzar.sh" /etc/rc.d/rc.local. separated semicolon, , in different lines.
- changing "lanzar.sh" of location.
- other things, taken other threads did not work me.
my rc.loca looks like:
#!/bin/sh # # script executed *after* other init scripts. # can put own initialization stuff in here if don't # want 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
note: know similar questions have been asked before, after testing many of answers have found googling no success, had ask myself.
i highly recommend explore /etc/init.d
directory of server , /etc/rc3.d
directory. see how names of files in /etc/rc3.d
symbolically linked names in /etc/init.d
directory. notice how files in /etc/rc3.d
start sxx
or kxxwhere
xx number between 00
99
.
what tell officially wrong. these startup scripts way more complicated today describe, it's basic outline of what's going on.
in standard unix , linux, startup scripts stored in /etc/init.d
, linked /etc/rcx.d
directory x
stood called init states of server. (yes, i'm linking sco unix page, pretty similar).
note init state 3 running in multi-user mode , daemons started. why telling in /etc/rc3.d
.
when server enters init state, runs of script starting s
in alphabetical order. runs each script parameter start
after it. so, s01xxxx
starts before s03xxx
starts before s99xxxxx
.
when server exits init state, runs of scripts start k
in alphabetical order, , passes stop
parameter them.
now, centos, redhat, , fedora setup handles lot of you. specify service depend upon, , figures out startup , shutdown order. however, nothing preventing munging startup script , creating own links.
by way, speaking java programs startup , shutdown... jenkins java program that's started in similar way program. here's /etc/init.d
script got off of jenkins website:
#!/bin/bash # # startup script 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' ; } ; 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 ; } ; sleep 1 ((cnt--)) done [ $retval = 0 ] && rm -f "$lock" [ $retval = 0 ] && success $"$string" || failure $"$string" echo } status() { pid=`pid_of_jenkins` if [ -n "$pid" ]; echo "jenkins (pid $pid) running..." return 0 fi if [ -f "$lock" ]; echo $"${base} dead subsys locked" return 2 fi echo "jenkins stopped" return 3 } # see how 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
it'll give work with.
Comments
Post a Comment