Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - AnimaTow

Pages: [1]
1
Hihi

ich habe mir mal die arbeit gemacht ein Init.d Script zu Schreiben.
Mit Extra Funktionen, Updatecheck or Upgrade..

JTS3ServerMod Init.d Multi Tool Version 1.16

Beschreibung:

Das Init.d Script hat folgene Optionen..

/etc/init.d/jts3servermod start          ## Startet den Server.
/etc/init.d/jts3servermod stop           ## Stopt den Server.
/etc/init.d/jts3servermod restart        ## Restartet den Server
/etc/init.d/jts3servermod precheck       ## Checkt Kompatibilitaet des Servers.
/etc/init.d/jts3servermod jsupgrade      ## JTS3ServerMod Upgrade
/etc/init.d/jts3servermod jsuptdatecheck ## Checkt ob eine neue Version verfuegbar ist.
/etc/init.d/jts3servermod cronupgrade    ## Upgrade Cron Job fuer AutoUpdate Chack und Upgrade
/etc/init.d/jts3servermod scriptinfo     ## Informationen Über das Script

Installation:

Downloade das init.d Script

wget ftp://ftp.os-up.com/incoming/teamspeak3/JTS3ServerMod/init.d/jts3servermod -O /etc/init.d/jts3servermod
cd /etc/init.d/
chmod +x jts3servermod
update-rc.d jts3servermod defaults

Bitte beachtet das ihr erst die Optionen Bearbeitet bevor ihr den server startet!!

Bearbeite die Init Optionen in der datei /etc/init.d/jts3servermod
nano /etc/init.d/jts3servermod

## Optionen Start JTS3ServerMod
TITLE='JTS3ServerMod'                           # Name für den Server
DAEMONSCRIPT='JTS3ServerMod.jar'                # Bot Server Java Script
TS3BOT='/home/jts3servermod'                           # Ordner zum Teamspeak3 Bot
USER='jts3servermod'                                   # Benuter Start des Servers
USERG='jts3servermod'                                  # Benutergruppe Start des Servers
OPT=''                        # Script Start Optionen
JSOPT='-mx30M -jar'                             # Java Start Optionen
JAVASYSTEM='/usr/bin/java'                      # Java Path
LOGFILE='/var/log/jts3servermod.log'                   # Logfile location and file
## Optionen Ende JTS3ServerMod

Erstelle Log Datei
touch /var/log/jts3servermod.log

Die Upgrade funkion ist noch beta ich werde die tage nochmal dran arbeiten und mal schauen was man besser machen kann....

sollte jemand verbesserungs vorschlege haben würde ich mich sehr drüber freuen


Souce Code v1.16
Code: [Select]

#!/bin/sh
## JTS3ServerMod Inet.d Master Script v1.16 by Projekt OsUp www.os-up.com
## Optionen Start JTS3ServerMod
TITLE='JTS3ServerMod'                           # Name für den Server
DAEMONSCRIPT='JTS3ServerMod.jar'                # Bot Server Java Script
JTS3PATH='/home/ts3bot'                         # Ordner zum Teamspeak3 Bot
USER='ts3bot'                                   # Benuter Start des Servers
USERG='ts3bot'                                  # Benutergruppe Start des Servers
OPT=''       # Script Start Optionen
JSOPT='-mx30M -jar'                             # Java Start Optionen
JAVASYSTEM='/usr/bin/java'                      # Java Path
LOGFILE='/var/log/jts3servermode.log'           # Logfile location and file
## Optionen Ende JTS3ServerMod

## Optionen Start Upgrade
QUELLE_UPGRADETYPE='stable'
QUELLE_JTS3ServerMod='ftp://ftp.os-up.com:21/incoming/teamspeak3/JTS3ServerMod/JTS3ServerMod.version'
#QUELLE_JTS3ServerMod='http://home.arcor.de/stefan-1983/projects/JTS3ServerMod.version'
## Optionen Start Upgrade

## Ab hier Nichts mehr ändern ##
precheck () {
# Check ob sudo Vorhanden ist
if [ ! -x /usr/bin/sudo ]; then
  echo ""
  echo "Sudo ist nicht installert. Bitte Installiere Sudo und versuch es nochmal."
  echo "$(date +"%b %a %d  %H:%M:%S"): You do not have Sudo installed." >> $LOGFILE
  echo ""
  exit 1
fi

# Checking for awk
if [ ! -x /usr/bin/awk ]; then
  echo ""
  echo "Awk ist nicht installert. Bitte Installiere Awk und versuch es nochmal."
  echo "$(date +"%b %a %d  %H:%M:%S"): You do not have awk installed." >> $LOGFILE
  echo ""
  exit 1
fi

# Checking for java
if [ ! -x $JAVASYSTEM ]; then
  echo ""
  echo "Java ist nicht installert. Bitte Installiere Java und versuch es nochmal."
  echo "$(date +"%b %a %d  %H:%M:%S"): You do not have java installed." >> $LOGFILE
  echo ""
  exit 1
fi

# Checking for JTS3ServerMod
if [ ! -f $JTS3PATH/$DAEMONSCRIPT ]; then
  echo ""
  echo "Das Java datei ist nicht vorhanden : $JTS3PATH/$DAEMONSCRIPT ?/"
  echo "Ist die Config richtig Eingestellt?"
  echo "$(date +"%b %a %d  %H:%M:%S"): Can't find /" >> $LOGFILE
  exit 1
fi
echo
echo "Alles OK"
echo "Sie können den server Starten mit."
echo "/etc/init.d/jts3servermod start"
echo
}

service_start() {
TEST=$(ps ax | grep $DAEMONSCRIPT | grep -v export | grep -v grep | wc -l)

# Server ist nicht gestartet Pid datei ist aber vorhanden
if [ "$TEST" = "0" ] && [ ! -f $JTS3PATH/JTS3ServerMod.pid ]; then
  echo
  echo "Starting $TITLE"
  echo "$(date +"%b %a %d  %H:%M:%S"): Starting $TITLE" >> $LOGFILE
  cd $JTS3PATH
  su $USER -c "$JAVASYSTEM $JSOPT $DAEMONSCRIPT $OPT" >> $LOGFILE 2>&1 &
  sleep 1
  sudo -u $USER ps ax | grep -v grep | grep $DAEMONSCRIPT | grep -v export | awk '{print $1}' > $JTS3PATH/JTS3ServerMod.pid
  chown $USER:$USERG $JTS3PATH/JTS3ServerMod.pid
  echo "$TITLE Process ID gespeichert in $JTS3PATH/JTS3ServerMod.pid"
  echo "$TITLE started."
  echo "$(date +"%b %a %d  %H:%M:%S"): $TITLE started" >> $LOGFILE
  echo
  exit 1
fi

# Server ist nicht gestartet Pid datei ist Nicht vorhanden
if [ "$TEST" = "0" ] && [ -f $JTS3PATH/JTS3ServerMod.pid ]; then
  echo
  echo "Server not running but pid-file present"
  echo "Loesche Pid Datei"
  echo "$(date +"%b %a %d  %H:%M:%S"): Server ist nicht gestartet Pid datei ist Nicht vorhanden" >> $LOGFILE
  echo "$(date +"%b %a %d  %H:%M:%S"): Removing pid-file" >> $LOGFILE
  rm $JTS3PATH/JTS3ServerMod.pid
  echo "Old pid file removed"
  echo "$(date +"%b %a %d  %H:%M:%S"): Old pid file removed" >> $LOGFILE
  echo
  echo "Starting $TITLE"
  echo "$(date +"%b %a %d  %H:%M:%S"): Starting $TITLE" >> $LOGFILE
  cd $JTS3PATH
  su $USER -c "$JAVASYSTEM $JSOPT $DAEMONSCRIPT $OPT" >> $LOGFILE 2>&1 &
  sleep 1
  sudo -u $USER ps ax | grep -v grep | grep $DAEMONSCRIPT | grep -v export | grep -v export | awk '{print $1}' > $JTS3PATH/JTS3ServerMod.pid
  chown $USER:$USERG $JTS3PATH/JTS3ServerMod.pid
  echo "$TITLE screen process ID written to $JTS3PATH/JTS3ServerMod.pid"
  echo "$TITLE started."
  echo "$(date +"%b %a %d  %H:%M:%S"): $TITLE started" >> $LOGFILE
  echo
fi

# Server running and no pid file-found, creates a new one!
if [ "$TEST" = "1" ] && [ ! -f $JTS3PATH/JTS3ServerMod.pid ]; then
  echo
  echo "Server is running but no pid file. Creating a new pid file!!"
  echo "$(date +"%b %a %d  %H:%M:%S"): Server is running but no pid file. Creating a new pid file!!" >> $LOGFILE
  sudo -u $USER ps ax | grep -v grep | grep $DAEMONSCRIPT | grep -v export | awk '{print $1'} > $JTS3PATH/JTS3ServerMod.pid
  chown $USER:$USERG $JTS3PATH/JTS3ServerMod.pid
  echo
  echo "$TITLE is running and new pid-file created"
  echo "$(date +"%b %a %d  %H:%M:%S"): $TITLE is running and new pid-file created" >> $LOGFILE
  echo
fi

# Server ist gestartet und Pid Datei wurde gefunden.
if [ "$TEST" = "1" ] && [ -f $JTS3PATH/JTS3ServerMod.pid ]; then
  echo
  echo "$TITLE Gestartet!!"
  echo "$(date +"%b %a %d  %H:%M:%S"): $TITLE Gestartet!!" >> $LOGFILE
  echo
fi
}

service_stop() {
TEST1=$(ps ax | grep -v grep | grep $DAEMONSCRIPT | grep -v export | wc -l)

# Server is not running and no pid-file found
if [ "$TEST1" = "0" ] && [ ! -f $JTS3PATH/JTS3ServerMod.pid ]; then
  echo
  echo "$TITLE is not running!!"
  echo "$(date +"%b %a %d  %H:%M:%S"): $TITLE is not running!!" >> $LOGFILE
  echo
fi

# Server is not running and pid-file found
if [ "$TEST1" = "0" ] && [ -f $JTS3PATH/JTS3ServerMod.pid ]; then
  echo
  echo "Server is not running but pid-file is present"
  echo "Removing pid-file"
  echo "$(date +"%b %a %d  %H:%M:%S"): Server is not running but pid-file is present" >> $LOGFILE
  echo "$(date +"%b %a %d  %H:%M:%S"): Removing pid-file" >> $LOGFILE
  rm $JTS3PATH/JTS3ServerMod.pid
  echo
  echo "Pid Datei Geloescht."
  echo "$(date +"%b %a %d  %H:%M:%S"): Pid file removed" >> $LOGFILE
  echo
fi

# Server is running but no pid-file found
if [ "$TEST1" = "2" ] && [ ! -f $JTS3PATH/JTS3ServerMod.pid ]; then
  echo
  echo "$TITLE is running but no pid file found."
  echo "Stopping $TITLE"
  echo "$(date +"%b %a %d  %H:%M:%S"): $TITLE is running but no pid file found." >> $LOGFILE
  echo "$(date +"%b %a %d  %H:%M:%S"): Stopping $TITLE" >> $LOGFILE
  sudo -u $USER ps ax | grep -v grep | grep $DAEMONSCRIPT | grep -v export | awk '{print $1'} > $JTS3PATH/JTS3ServerMod.pid
  chown $USER:$USERG $JTS3PATH/JTS3ServerMod.pid
  for id in $(sed -n '1p' $JTS3PATH/JTS3ServerMod.pid)
  do
kill -TERM $id
  echo "Killing process ID $id"
  echo "Removing $TITLE pid file"
  rm -rf $JTS3PATH/JTS3ServerMod.pid
  break
  done
  echo "$TITLE stopped"
  echo "$(date +"%b %a %d  %H:%M:%S"): $TITLE stopped" >> $LOGFILE
  echo
fi

# Server running and pid-file found
if [ "$TEST1" = "2" ] && [ -f $JTS3PATH/JTS3ServerMod.pid ]; then
  echo
  echo "Stopping $TITLE"
  echo "$(date +"%b %a %d  %H:%M:%S"): Stopping $TITLE" >> $LOGFILE
  for id in $(sed -n '1p' $JTS3PATH/JTS3ServerMod.pid)
  do
kill -TERM $id
  echo "Beende Prozess ID: $id"
  echo "Loesche $JTS3PATH/JTS3ServerMod.pid"
  rm -rf $JTS3PATH/JTS3ServerMod.pid
  break
  done
  echo "$TITLE Beendet"
  echo "$(date +"%b %a %d  %H:%M:%S"): $TITLE Beendet" >> $LOGFILE
  echo
fi
}

jsupgrade () {
echo
echo "JTS3ServerMod Upgrade ....."
echo

if [ $QUELLE_UPGRADETYPE == 'stable' ]
    then
echo "stable"
wget $QUELLE_JTS3ServerMod -O $JTS3PATH/.jsversionquelle
UPGRADEQUELLE=$(sed -n '1p' $JTS3PATH/.jsversionquelle)

rm $JTS3PATH/.jsupgradeurl
rm $JTS3PATH/.jsupgradeversion
rm $JTS3PATH/.jsupgradetype
rm $JTS3PATH/.jsupgradedateiname

echo $(echo $(echo $UPGRADEQUELLE | awk 'BEGIN {FS = ";"} {print $3}') | tr -d "[:space:]" > $JTS3PATH/.jsupgradeurl )
echo $(echo $(echo $UPGRADEQUELLE | awk 'BEGIN {FS = ";"} {print $2}') > $JTS3PATH/.jsupgradeversion )
echo $(echo $(echo $UPGRADEQUELLE | awk 'BEGIN {FS = ";"} {print $1}') | tr -d "[:space:]" > $JTS3PATH/.jsupgradetype )
echo $(echo JTS3ServerMod_$(cat $JTS3PATH/.jsupgradeurl | awk 'BEGIN {FS = "/JTS3ServerMod_"} {print $2}') | tr -d "[:space:]" > $JTS3PATH/.jsupgradedateiname )

  elif [ $QUELLE_UPGRADETYPE == 'beta' ]
    then
echo "beta"
wget $QUELLE_JTS3ServerMod -O $JTS3PATH/.jsversionquelle
UPGRADEQUELLE=$(sed -n '2p' $JTS3PATH/.jsversionquelle)

rm $JTS3PATH/.jsupgradeurl
rm $JTS3PATH/.jsupgradeversion
rm $JTS3PATH/.jsupgradetype
rm $JTS3PATH/.jsupgradedateiname

echo $(echo $(echo $UPGRADEQUELLE | awk 'BEGIN {FS = ";"} {print $3}') | tr -d "[:space:]" > $JTS3PATH/.jsupgradeurl )
echo $(echo $(echo $UPGRADEQUELLE | awk 'BEGIN {FS = ";"} {print $2}') > $JTS3PATH/.jsupgradeversion )
echo $(echo $(echo $UPGRADEQUELLE | awk 'BEGIN {FS = ";"} {print $1}') | tr -d "[:space:]" > $JTS3PATH/.jsupgradetype )
echo $(echo $(cat $JTS3PATH/.jsupgradeurl | awk 'BEGIN {FS = "/JTS3ServerMod_"} {print $2}') | tr -d "[:space:]" > $JTS3PATH/.jsupgradedateiname )

  else
echo "Fehlerhafte Upgrade versions angabe in der Configuration."
fi


if [ "$(cat $JTS3PATH/.jsupgradeversion)" == "$(cat $JTS3PATH/.jsversion)" ]
then
echo "Sie haben bereits die Neuste Version Installiert.."
echo "###################################"
echo "##"
echo "##"
echo "Locale JTS3ServerMod.jar Version: $(cat $JTS3PATH/.jsversion)"
echo "Quelle JTS3ServerMod.jar Version: $(cat $JTS3PATH/.jsupgradeversion)"
echo "##"
echo "##"
echo "###################################"
else
echo "Upgrade wert Vorberietet.."
echo "###################################"
echo "##"
echo "JTS3ServerMod Stop"
        service_stop
        sleep 5
echo "##"
echo "###################################"

echo "Erstelle Temp Verzeichniss.."
echo "###################################"
echo "##"
mkdir $JTS3PATH/temp/
echo "##"
echo "###################################"

echo "Downloade Upgrade....."
echo "###################################"
echo "##"
cd $JTS3PATH/temp/
wget $(sed 'N;s/-\n//;P;D;' $JTS3PATH/.jsupgradeurl | tr -d "[:space:]")
echo "##"
echo "###################################"

echo "Entpacke JTS3ServerMod.jar....."
echo "###################################"
echo "##"
unzip -d $JTS3PATH/temp $(cat $JTS3PATH/.jsupgradedateiname) JTS3ServerMod/JTS3ServerMod.jar
echo "##"
echo "###################################"

echo "Überschreibe JTS3ServerMod.jar....."
echo "###################################"
echo "##"
cp $JTS3PATH/temp/JTS3ServerMod/JTS3ServerMod.jar $JTS3PATH/JTS3ServerMod.jar
chown $USER:$USERG $JTS3PATH/JTS3ServerMod.jar
echo "##"
echo "###################################"

echo "Lösche Temp Dateien....."
echo "###################################"
echo "##"
cd $JTS3PATH/
rm -rf $JTS3PATH/temp/
echo "##"
echo "###################################"

echo "Aktualesiere Locale Verions Informationen....."
echo "###################################"
echo "##"
rm $JTS3PATH/.jsversion
echo $(cat $JTS3PATH/.jsupgradeversion) >> $JTS3PATH/.jsversion
chown $USER:$USERG $JTS3PATH/.jsversion
echo "##"
echo "###################################"

echo "JTS3ServerMod wurde aktualesiert."
echo "###################################"
echo "##"
echo "Aktuele JTS3ServerMod.jar Version:"
echo $(cat $JTS3PATH/.jsversion)
echo "##"
echo "###################################"

echo "Info.."
echo "###################################"
echo "##"
echo "Starten die den Server Neu"
echo "/etc/init.d/jts3servermod start"
echo "##"
echo "###################################"
fi
}

jsuptdatecheck () {
echo
echo "Check Update..."
if [ ! -f $JTS3PATH/.jsversion ]; then
  echo ""
  echo "Versions Check Fehler: die datei $JTS3PATH/.jsversion ist nicht vorhanden.. /n bitte Upgrade damit die datei angelegt wert. "
  echo "$(date +"%b %a %d  %H:%M:%S"): Versions Check Fehler: die datei $JTS3PATH/.jsversion ist nicht vorhanden.. /n bitte Upgrade damit die datei angelegt wert.  /" >> $LOGFILE
  exit 1
fi

if [ $QUELLE_UPGRADETYPE == 'stable' ]
    then
echo "stable"
wget $QUELLE_JTS3ServerMod -O $JTS3PATH/.jsversionquelle
export UPGRADEQUELLE=$(sed -n '1p' $JTS3PATH/.jsversionquelle)
export UPGRADEQUELLEVERSION=$(echo $UPGRADEQUELLESTABLE | awk 'BEGIN {FS = ";"} {print $2}')
  elif [ $QUELLE_UPGRADETYPE == 'beta' ]
    then
echo "beta"
wget $QUELLE_JTS3ServerMod -O $JTS3PATH/.jsversionquelle
export UPGRADEQUELLE=$(sed -n '2p' $JTS3PATH/.jsversionquelle)
export UPGRADEQUELLEVERSION=$(echo $UPGRADEQUELLEBETA | awk 'BEGIN {FS = ";"} {print $2}')
  else
echo "Fehlerhafte Upgrade version"
fi

if [ "$(cat $JTS3PATH/.jsupgradeversion)" == "$(cat $JTS3PATH/.jsversion)" ]
then
echo Sie haben die Neuste version.
else
echo
echo "Es ist eine Neues Update verfuegbar."
echo "Sie Koennen jetzt ein Upgade Starten."
echo "###################################"
echo "##"
echo "##"
echo "Locale JTS3ServerMod.jar Version: $(cat $JTS3PATH/.jsversion)"
echo "Quelle JTS3ServerMod.jar Version: $(cat $JTS3PATH/.jsupgradeversion)"
echo "##"
echo "##"
echo "###################################"
echo "/etc/init.d/jts3servermod jsupgrade"
echo
fi

}

scriptinfo () {
echo
echo "JTS3ServerMod Multi Init.d Script ....."
echo
echo "Programmierer: AnimaTow (Stephan Broeker)"
       echo "Website: http://www.os-up.com"
echo
echo "JTS3ServerMod Projekt"
echo "Programmierer: Stefan1200"
echo "Website: http://stefan1200.bplaced.net/"
       echo "Download Seite http://addons.teamspeak.com/"
echo
}

cronupgrade () {
  echo "$(date +"%b %a %d  %H:%M:%S"): Cron Job Upgrade Start." >> $LOGFILE
wget $QUELLE_JTS3ServerMod/.jsversion -O $JTS3PATH/.jsversionquelle
export JSVERSIONQUELLE=$(cat $JTS3PATH/.jsversionquelle)
    export JSVERSIONLOCAL=$(cat $JTS3PATH/.jsversion)
  echo "$(date +"%b %a %d  %H:%M:%S"): Quellen Version: $JSVERSIONQUELLE" >> $LOGFILE
  echo "$(date +"%b %a %d  %H:%M:%S"): Locale Version: $JSVERSIONLOCAL" >> $LOGFILE
    if [ "$JSVERSIONLOCAL" == "$JSVERSIONQUELLE" ]
    then
      echo "$(date +"%b %a %d  %H:%M:%S"): Cron Job Upgrade Neuste Version Vohanden." >> $LOGFILE
    else
        service_stop
        sleep 5
    wget $QUELLE_JTS3ServerMod/JTS3ServerMod.jar -O $JTS3PATH/JTS3ServerMod.jar
    wget $QUELLE_JTS3ServerMod/.jsversion -O $JTS3PATH/.jsversion
    service_start
      echo "$(date +"%b %a %d  %H:%M:%S"): Cron Job Upgrade auf Neuste Version: $JSVERSIONQUELLE Geupdatet." >> $LOGFILE
    fi
}

case "$1" in
    'start')
        service_start
    ;;
    'stop')
        service_stop
    ;;
    'restart')
        service_stop
        sleep 5
        service_start
    ;;
    'precheck')
        precheck
    ;;
    'jsupgrade')
        jsupgrade
    ;;
    'jsuptdatecheck')
        jsuptdatecheck
    ;;
    'scriptinfo')
        scriptinfo
    ;;
    'cronupgrade')
        cronupgrade
    ;;
*)
        echo "/etc/init.d/jts3servermod start          ## Startet den Server."
        echo "/etc/init.d/jts3servermod stop           ## Stopt den Server."
        echo "/etc/init.d/jts3servermod restart        ## Restartet den Server"
        echo "/etc/init.d/jts3servermod precheck       ## Checkt Kompatibilitaet des Servers."
        echo "/etc/init.d/jts3servermod jsupgrade      ## JTS3ServerMod Upgradet"
        echo "/etc/init.d/jts3servermod jsuptdatecheck ## Ceckt ob eine neue Version verfuegbar ist."
        echo "/etc/init.d/jts3servermod cronupgrade    ## Upgrade Cron Job fue AutoUpdate Chack und Upgrade"
        echo "/etc/init.d/jts3servermod scriptinfo     ## Informationen Über das Script"
esac





in der neuen version 1.16 habe ich die upgrade funktion überarbeitet....


Liebe Grüße und viel Spass....

AnimaTow

Update: 28.2.2011 12:00

Pages: [1]