不想用別人封裝的程序,比如wrapper service。用自己的腳本搞定。
1.創建一個start.sh腳本,裡面運行java程序:
- -UU-:----F1 master_rest 18% L25 (Shell-script[sh])------------------------------------------------------------------------------------------------------------------------
- #!/bin/bash
- PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
- CARRIER_HOME=/home/dist/carrier
- export JAVA_HOME=/usr/jdk1.6
- export PATH="$JAVA_HOME/bin:$PATH"
- java -server -cp $CARRIER_HOME/site/master/rest/dependency/ -jar $CARRIER_HOME/site/master/rest/master-1.0.jar &
2.在/etc/init.d/中創建一個service腳本,比如master_rest
內容如下:
- # Short-Description: master
- # Description: master rest service
- ### END INIT INFO
- . /lib/lsb/init-functions
- PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
- CARRIER_HOME=/home/dist/carrier
- case "$1" in
- start)
- log_begin_msg "Starting master rest server"
- /bin/bash $CARRIER_HOME/scripts/start.sh >/dev/null 2>&1
- log_end_msg 0
- ;;
- stop)
- PID=`ps -ef | grep 'master-1.0.jar' | grep -v grep | awk '{print $2}'`
- log_begin_msg "Stopping master rest server"
- if [ ! -z "$PID" ]; then
- kill -15 $PID
- fi
- log_end_msg 0
- ;;
- restart)
- $0 stop
- $0 start
- ;;
- *)
- log_success_msg "Usage: service master_rest {start|stop|restart}"
- exit 1
- esac
- exit 0
重點注意是 , 這行命令導致終端不會輸出信息。
>/dev/null 2>&1