Skrypt startowy HLDS by Vikus

Od HLDS.pl
Skocz do: nawigacji, wyszukiwania

Używanie

  • Uruchamia serwer HLDS
./cs_run start
  • Zatrzymuje serwer HLDS
./cs_run stop
  • Resetuje serwer HLDS
./cs_run restart
  • Sprawdza czy serwer HLDS jest uruchomiony
./cs_run status
  • Laczy sie z serwerem HLDS czyli screenem
./cs_run show

Skrypt

#!/bin/bash
 
#----------------------------------------------------------------------
# Description: 	Skrypt do uruchamiania servera Counter Strike 1.6
# Author: 	Wiktor -> wiktor.vip(at)gmail(dot)com
# Version: 	2.3
# Date:		2007.09.08
# Copyright (c) 2007 Vikus All rights reserved.
#----------------------------------------------------------------------
# Configure section:
 
DIR_HLDS="/home/cstrike/hlds_l"	# sciezke do plikow serwera HLDS
PORT="27015"			# port na jakim bedzie serwer
MP="14"				# maxymalna liczba graczy 
MAP="de_dust2"			# mapa startowa
CFG="server.cfg"		# plik konfiguracyjny do serwera
NAME="cs_server"		# nazwa dla screena
 
PARAMS="-game cstrike -insecure +port $PORT +maxplayers $MP +map $MAP exec $CFG"
 
# Dostepne wartosci ktore mozemy wykorzystac przy starcie serwera
# wystarczy dodac do zmiennej PARAMS
#
# -autoupdate			autoupdate sewera po restarcie
# -debug			tryb debugera
# -insecure			VAC wylaczony
# -nomaster			serwer nie widoczny w przegladarce (find server)
# +sv_lan 1			serwer na LAN
# +sv_password "" 		haslo dla serwera
# +mapchangecfggfile $CFG	
#
########################################################################
# Dostepne komedy:
# ------------------
# ./cs_run start	- Uruchamia serwer HLDS
# ./cs_run stop		- Zatrzymuje serwer HLDS
# ./cs_run restart	- Resetuje serwer HLDS
# ./cs_run status	- Sprawdza czy serwer HLDS jest uruchomiony
# ./cs_run show		- Laczy sie z serwerem HLDS czyli screenem
#----------------------------------------------------------------------
 
 
function color_linux() {
  RED="echo -en \\033[1;31m\c"
  GREEN="echo -en \\033[1;32m\c"
  YELLOW="echo -en \\033[1;33m\c"
  BLUE="echo -en \\033[1;34m\c"
  DARK="echo -en \\033[1;39m\c"
  NORMAL="echo -en \\033[0;39m\c"
}
 
function check_proc() {
 color_linux
  
  ps aux | grep "SCREEN.*${NAME}" | grep -v grep > /dev/null
  let R=$?
  
  if [ $R -eq 1 ]; then
	PROC=HLDS_DOWN
  else
	PROC=HLDS_UP
  fi
} # end of check_proc()
 
function progress() {
 color_linux
  
  echo ""
  for i in `seq 1 20`;  do
        ${BLUE} ; echo -n "# " ; ${NORMAL}
	sleep 0.1
  done
 
} # end of progress()
 
function start_hlds() {
 check_proc
 color_linux
 
  if [ ${PROC} = "HLDS_DOWN" ]
    then
        cd $DIR_HLDS
        screen -A -m -d -S ${NAME} ./hlds_run ${PARAMS}
	date +"%Y-%m-%d %H:%M:%S" > ${DIR_HLDS}/date.log
	
	progress
	echo ""
        ${GREEN} ; echo "* Serwer HLDS zostal uruchomiony!" ; ${NORMAL}
	${GREEN} ; echo "* Screen name: $NAME" ; ${NORMAL}
  else
	echo ""
	${RED} ; echo "* Serwer HLDS jest juz uruchomiony!" ; ${NORMAL}
	echo ""
  fi	
} # end of start_hlds()
 
function stop_hlds() {
 check_proc
 color_linux
 
  if [ ${PROC} = "HLDS_UP" ]
    then
        screen -wipe > /dev/null
        kill -9 `screen -ls | grep -w $NAME | awk -F . '{print $1}' | awk '{print $1}'`
	progress
        echo ""
        ${GREEN} ; echo "* Serwer HLDS zatrzymany!" ; ${NORMAL}
  else
	echo ""
	${RED} ; echo "* Serwer HLDS nie jest uruchomiony!" ; ${NORMAL}
	echo ""
  fi
} # end of stop_hlds()
 
function restart_hlds() {
 check_proc
 color_linux
 
  if [ ${PROC} = "HLDS_UP" ]
    then
	stop_hlds    
	start_hlds
	echo ""
	${GREEN} ; echo "* Serwer HLDS zrestartowany!" ; ${NORMAL}
  else
	echo ""
	${RED} ; echo "* Serwer HLDS nie jest uruchomiony!" ; ${NORMAL}
	echo ""
  fi
} # end of restart_hlds()
 
function show_hlds() {
 check_proc
 color_linux
 
  if [ ${PROC} = "HLDS_UP" ]
    then
	screen -r ${NAME}
  else
	echo ""
	${RED} ; echo "* Serwer HLDS nie jest uruchomiony!" ; ${NORMAL}
	echo ""
  fi
} # end of show_hlds()
 
function status_hlds() {
 check_proc
 color_linux
 
  if [ ${PROC} = "HLDS_UP" ]
    then
	echo ""
	${GREEN} ; echo "* Serwer HLDS jest uruchomiony!" ; ${NORMAL}
	${GREEN} ; echo "* Screen name: ${NAME}" ; ${NORMAL}
	check_uptime
	echo ""
  else
	echo ""
	${RED} ; echo "* Serwer HLDS nie jest uruchomiony!" ; ${NORMAL}
	echo ""
  fi
} # end of status_hlds()
 
function check_uptime() {
 
    read line < ${DIR_HLDS}/date.log
    START_DATE=`date --date="$line" +"%s"` 
    NOW_DATE=`date +"%s"`
    PERIOD=$(($NOW_DATE-$START_DATE))
 
    TT=$PERIOD
    DD=0;HH=0;MM=0;SS=0
    let DD=TT/86400
    let DD2=DD*86400
    [[ "$DD" -gt 0 ]] && let TT=TT-DD2
    let HH=TT/3600
    let HH2=HH*3600
    [[ "$HH" -gt 0 ]] && let TT=TT-HH2
    let MM=TT/60
    let MM2=MM*60
    [[ "$MM" -gt 0 ]] && let TT=TT-MM2
    let SS=TT
    TT="${DD} days ${HH} hrs ${MM} mins ${SS} secs"
 
    ${GREEN} ; echo "* UPTIME SERWERA HLDS:`${YELLOW}` ${TT}" ; ${NORMAL}
 
} # end of check_uptime()
 
 
#MAIN 
#-----------------------
color_linux
 
case "$1" in
  start)
        start_hlds
        ;;
  stop)
        stop_hlds 
        ;;
  restart)    
    	restart_hlds
	;;
  show)
	show_hlds
	;;
  status)
	status_hlds
	;;
  *)      
	echo ""
	${GREEN} ; echo "# `${BLUE}`  Dostepne  parametry:" ; ${NORMAL}
	${GREEN} ; echo "--------------------------------------" ; ${NORMAL}
	${GREEN} ; echo -e "# `${RED}` start `${GREEN}` \t- Start serwer HLDS" ; ${NORMAL}
	${GREEN} ; echo -e "# `${RED}` stop `${GREEN}` \t- Stop serwer HLDS" ; ${NORMAL}
	${GREEN} ; echo -e "# `${RED}` restart `${GREEN}` \t- Restart serwer HLDS" ; ${NORMAL}
	${GREEN} ; echo -e "# `${RED}` show `${GREEN}` \t- Polacz sie z serwerem HLDS" ; ${NORMAL}
	${GREEN} ; echo -e "# `${RED}` status `${GREEN}` \t- Status serwera HLDS" ; ${NORMAL}
	echo ""
	;;	  
esac
Osobiste
Przestrzenie nazw
Warianty
Działania
HLDS.pl - Menu:
Inne
IRC
Inne sekcje:
Znajomi:
Narzędzia