2016-04-24 142 views
0

我已經使用標準的bash啓動腳本來自動啓動我的Teamspeak服務器 - 完美的工作。現在我已經爲JTS3服務器模塊做了同樣的事情,問題是:這是一個jar文件,無法啓動。如果我手動運行jar/startscript,它工作得很好。在啓動時運行jar文件linux

這裏的/etc/init.d/boot.d中

#!/bin/bash 
### BEGIN INIT INFO 
# Provides:    jts3servermod 
# Required-Start:  $local_fs $network 
# Required-Stop:  $local_fs $network 
# Default-Start:  2 3 4 5 
# Default-Stop:   0 1 6 
# Description:   JTS3 Server Mod 
### END INIT INFO 


# INIT Script by www.SysADMINsLife.com 
###################################### 
# Customize values for your needs: "User"; "DIR" 

USER="ts" 
DIR="/home/ts/JTS3ServerMod" 

###### Teamspeak 3 server start/stop script ###### 

case "$1" in 
start) 
su $USER -c "${DIR}/jts3servermod_startscript.sh start" 
;; 
stop) 
su $USER -c "${DIR}/jts3servermod_startscript.sh stop" 
;; 
restart) 
su $USER -c "${DIR}/jts3servermod_startscript.sh restart" 
;; 
status) 
su $USER -c "${DIR}/jts3servermod_startscript.sh status" 
;; 
*) 
echo "Usage: {start|stop|restart|status}" >&2 
exit 1 
;; 
esac 
exit 0 
當然

它與更新的rc.d jts3servermod默認運行級別的文件夾鏈接的腳本。

的servermod startscript(jts3servermod_startscript.sh)是:

#!/bin/sh 
# JTS3ServerMod Linux start script 
# Created by Stefan "Stefan1200" Martens 
# The author of this script is not responsible for any damage or data loss! 

JAVA_COMMANDLINE_PARAMETERS="-mx30M"   # You can add java arguments here, like the -mx30M argument! 
JTS3SERVERMOD_COMMANDLINE_PARAMETERS="" # You can add JTS3ServerMod arguments here, like the -config and -log argument! 
BINARYPATH="$(pwd)"      # This have to point to the JTS3ServerMod directory! 

# Don't change the lines below, if you are not a sh script expert! 
cd "${BINARYPATH}" 
BINARYNAME="JTS3ServerMod.jar" 
ROOTUID="0" 

case "$1" in 
     java) 
       if which java >/dev/null 2>&1 ; then 
         echo "Java is already installed:" 
         java -version 
       else 
         if [ "$(id -u)" -ne "$ROOTUID" ] ; then 
           echo "Start this script as root to start the automatic installation of the Java runtime environment." 
           echo "You can also read the system requirements of the JTS3ServerMod in the readme.txt file for a manual installation of the Java runtime environment." 
           exit 6 
         else 
           read -p "Do you wish to install the Java runtime environment? (y/n) " yn 
           case $yn in 
             [Yy]*) installJava; break;; 
             *) echo "Aborted!"; exit 6;; 
           esac 
         fi 
       fi 
     ;; 
     start) 
       if ! which java >/dev/null 2>&1 ; then 
         echo "The JTS3ServerMod needs the Java runtime environment installed to run!" 
         echo "Start this script with the java argument as root to start the automatic installation of the Java runtime environment:" 
         echo "$0 java" 
         echo "You can also read the system requirements of the JTS3ServerMod in the readme.txt file for a manual installation of the Java runtime environment." 
         exit 6 
       fi 
       if [ "$(id -u)" -eq "$ROOTUID" ] ; then 
         echo "For security reasons it is prefered not to run the JTS3ServerMod as root!" 
       fi 
       if [ -e jts3servermod.pid ]; then 
if (kill -0 $(cat jts3servermod.pid) 2> /dev/null); then 
           echo "The JTS3ServerMod is already running, try restart or stop!" 
           exit 1 
         else 
           echo "jts3servermod.pid found, but no JTS3ServerMod running. Possibly your previously started JTS3ServerMod crashed!" 
           echo "Please view the logfile for details." 
           rm -f jts3servermod.pid 
         fi 
       fi 
       echo "Starting the JTS3ServerMod..." 
       if [ -e "$BINARYNAME" ]; then 
         java ${JAVA_COMMANDLINE_PARAMETERS} -jar ${BINARYNAME} ${JTS3SERVERMOD_COMMANDLINE_PARAMETERS} > /dev/null & 
         PID=$! 
         ps -p ${PID} > /dev/null 2>&1 
         if [ "$?" -ne "0" ]; then 
           echo "JTS3ServerMod could not start!" 
         else 
           echo $PID > jts3servermod.pid 
           echo "JTS3ServerMod started, for details please view the log file!" 
         fi 
       else 
         echo "Could not find the file $BINARYNAME, aborting!" 
         exit 5 
       fi 
     ;; 
     stop) 
if [ -e jts3servermod.pid ]; then 
         echo -n "Stopping the JTS3ServerMod.." 
         if (kill -TERM $(cat jts3servermod.pid) 2> /dev/null); then 
           c=1 
           while [ "$c" -le 120 ]; do 
             if (kill -0 $(cat jts3servermod.pid) 2> /dev/null); then 
               echo -n "." 
               sleep 1 
             else 
               break 
             fi 
             c=$(($c+1)) 
           done 
         fi 
         if (kill -0 $(cat jts3servermod.pid) 2> /dev/null); then 
           echo "JTS3ServerMod is not shutting down cleanly - killing!" 
           kill -KILL $(cat jts3servermod.pid) 
         else 
           echo "done" 
         fi 
         rm -f jts3servermod.pid 
       else 
         echo "No JTS3ServerMod running (jts3servermod.pid is missing)!" 
         exit 7 
       fi 
     ;; 
     restart) 
       $0 stop && $0 start || exit 1 
     ;; 
     status) 
if [ -e jts3servermod.pid ]; then 
         if (kill -0 $(cat jts3servermod.pid) 2> /dev/null); then 
           echo "JTS3ServerMod is running!" 
         else 
           echo "JTS3ServerMod seems to have died!" 
         fi 
       else 
         echo "No JTS3ServerMod running (jts3servermod.pid is missing)!" 
       fi 
     ;; 
     *) 
       echo "Usage: ${0} {start|stop|restart|status|java}" 
       exit 2 
esac 
exit 0 

我也試着寫一個自己的簡單腳本僅啓動罐子和追趕的PID並將其寫入到文件中。 這些腳本都不想在啓動過程中啓動我的.jar文件。

如您所見,第一個腳本是啓動時啓動Teamspeak服務器的模板。我只用我的Server Mod路徑和腳本替換了一些東西,並放入/etc/init.d/(當然執行了chmod 755)。

也許你們有些人有其他方法來解決這種奇怪的情況。提前感謝您的幫助!

最好的問候, Tw1x

+0

你有沒有考慮仰視的cron? – TuxForLife

+0

查找cron是什麼意思? crontab -e的輸出?在用戶,root和ts(啓動腳本的用戶)上都是空的。 – Tw1x

回答

0

我不知道這個問題是在此期間解決,但同時與同樣的問題進行試驗。我發現腳本找不到jar文件。所以我補充說:

#!/bin/sh 
# JTS3ServerMod Linux start script 
# Created by Stefan "Stefan1200" Martens 
# The author of this script is not responsible for any damage or data loss! 
cd "$(dirname "$0")" 
... 

在jts3servermod_startscript.sh的開頭確保「工作目錄」是正確的。

順便說一句 - 我的init腳本: JTS-BOT

#!/bin/sh 
### BEGIN INIT INFO 
# Provides:    jts-bot 
# Required-Start:  $local_fs $network 
# Required-Stop:  $local_fs $network 
# Default-Start:  2 3 4 5 
# Default-Stop:   0 1 6 
# Description:   JTS3-Bot for TeamSpeak 
### END INIT INFO 


USER="teamspeak" 
DIR="/home/teamspeak/JTS3ServerMod" 

###### JTS3ServerMod start/stop script ###### 

case "$1" in 
start) 
su $USER -c "${DIR}/jts3servermod_startscript.sh start" 
;; 
stop) 
su $USER -c "${DIR}/jts3servermod_startscript.sh stop" 
;; 
restart) 
su $USER -c "${DIR}/jts3servermod_startscript.sh restart" 
;; 
status) 
su $USER -c "${DIR}/jts3servermod_startscript.sh status" 
;; 
*) 
echo "Usage: -bash {start|stop|restart|status}" >&2 
exit 1 
;; 
esac 
exit 0