開機自動啟動應用程式 ON Linux

zhanglei_itput發表於2010-05-21

Linux平臺開機自動啟動resin指令碼

        之前寫過開機自動啟動oracle的指令碼,但是應用程式不熟悉,也沒寫過,現在有這個需求,所以就把oracle開機自動啟的改吧改吧,還真可以用~~呵呵
 

1. 建立啟動指令碼/etc/init.d/tomcat
# chmod +x /etc/init.d/tomcat
[root@htjcoa init.d]# more /etc/init.d/tomcat
#!/bin/bash
# Tomcat init script. for Linux.
#
# chkconfig: 345 99 10
# description: Tomcat Automatic Startup on Linux
TOMCAT_OWNER=budget
TOMCAT_HOME=/home/budget/resin
JAVA_HOME=/home/budget/jdk1.5.0_20
case "$1" in
  start)
    echo "-------------------------------------------------" >> /var/log/tomcat
    date +" %T %a %D : Starting Tomcat Application......" >> /var/log/tomcat
    su - $TOMCAT_OWNER -c "$TOMCAT_HOME/bin/httpd.sh >/home/budget/resin/log.log" >> /var/log/tomcat
    echo "Done."
    echo "-------------------------------------------------" >> /var/log/tomcat
    touch /var/lock/subsys/budget
    ;;
 
  *)
    echo "Usage: tomcat {start|stop|restart}"
    exit 1
esac

2. 開機自動啟動
    # chkconfig tomcat on
    開機關閉自動啟動
   # chkconfig tomcat off

3. more httpd.sh
[budget@htjcoa bin]$ more httpd.sh
#! /bin/sh
#
# See contrib/init.resin for /etc/rc.d/init.d startup script
#
# resin.sh can be called like apachectl
#
# resin.sh         -- execs resin in the foreground
# resin.sh start   -- starts resin in the background
# resin.sh stop    -- stops resin
# resin.sh restart -- restarts resin
#
# resin.sh will return a status code if the wrapper detects an error, but
# some errors, like bind exceptions or Java errors, are not detected.
#
# To install, you'll need to configure JAVA_HOME and RESIN_HOME and
# copy contrib/init.resin to /etc/rc.d/init.d/resin.  Then
# use "unix# /sbin/chkconfig resin on"
 
if test -n "${JAVA_HOME}"; then
  if test -z "${JAVA_EXE}"; then
    JAVA_EXE=$JAVA_HOME/bin/java
  fi
fi 
 
#
# trace script. and simlinks to find the wrapper
#
if test -z "${RESIN_HOME}"; then
  script=`/bin/ls -l $0 | awk '{ print $NF; }'`
 
  while test -h "$script"
  do
    script=`/bin/ls -l $script. awk '{ print $NF; }'`
  done
 
  bin=`dirname $script`
  RESIN_HOME="$bin/.."
fi 
 
exec $JAVA_EXE -jar ${RESIN_HOME}/lib/resin.jar $*

相關連線:http://space.itpub.net/9252210/viewspace-662886

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9252210/viewspace-663335/,如需轉載,請註明出處,否則將追究法律責任。

相關文章