Difference between revisions of "Linux dedicated server/ru"
(→Init-script для запуска сервера) |
|||
Line 19: | Line 19: | ||
== Init-script для запуска сервера == | == Init-script для запуска сервера == | ||
+ | |||
+ | <pre> | ||
+ | #!/bin/bash | ||
+ | # | ||
+ | # chkconfig 345 80 20 | ||
+ | # | ||
+ | # Startup script | ||
+ | # Gameserver: | ||
+ | # Credits: Zack | ||
+ | # Version: 1.00 | ||
+ | # | ||
+ | # | ||
+ | # NOTE: | ||
+ | # game_type variable indicates what game should be started. | ||
+ | # Although this script have this variable, different gametypes cannot be started with it. | ||
+ | # Consider to make changes to this script by hand. | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | #variables | ||
+ | server_user="gameserver" | ||
+ | server_install_path="/home/server" | ||
+ | game_name=tf2 | ||
+ | startup_command="$game_name-startup.sh" | ||
+ | RETVAL=0 | ||
+ | |||
+ | |||
+ | # start and stop functions | ||
+ | start() { | ||
+ | echo "Gameserver will be running under user $server_user" | ||
+ | echo "Starting gameserver..." | ||
+ | chown -R $server_user:$server_user $server_install_path | ||
+ | su - $server_user -c "$server_install_path/$startup_command > /dev/null 2>&1 &" | ||
+ | RETVAL=$? | ||
+ | return $RETVAL | ||
+ | } | ||
+ | |||
+ | stop() { | ||
+ | PID=`ps ax | grep ucc-bin | grep -v grep | awk '{print $1}'` | ||
+ | if [ "$PID" != "" ] | ||
+ | then | ||
+ | echo "Stopping gameserver (PID $PID)..." | ||
+ | kill -9 $PID | ||
+ | sleep 2 | ||
+ | else | ||
+ | echo "Gameserver is already stopped" | ||
+ | fi | ||
+ | } | ||
+ | |||
+ | status() { | ||
+ | PID=`ps ax | grep ucc-bin |grep -v grep | awk '{print $1}'` | ||
+ | if [ "$PID" != "" ] | ||
+ | then | ||
+ | echo "Gameserver is running and have pid $PID" | ||
+ | else | ||
+ | echo "Gameserver is stopped" | ||
+ | fi | ||
+ | } | ||
+ | |||
+ | |||
+ | case "$1" in | ||
+ | start) | ||
+ | start | ||
+ | ;; | ||
+ | stop) | ||
+ | stop | ||
+ | ;; | ||
+ | restart) | ||
+ | stop | ||
+ | sleep 2 | ||
+ | start | ||
+ | ;; | ||
+ | status) | ||
+ | status | ||
+ | ;; | ||
+ | *) | ||
+ | echo "Usage: $0 {start|stop|restart}" | ||
+ | exit 1 | ||
+ | esac | ||
+ | |||
+ | exit $RETVAL | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | |||
+ | *В директории с сервером лежит скрипт для запуска сервера, который вызывает инит скрипт. Пример скрипта: | ||
+ | <pre> | ||
+ | #!/bin/bash | ||
+ | |||
+ | if [ "$1" != "" ]; then | ||
+ | MAP=$1 | ||
+ | else | ||
+ | MAP='mvm_mannworks' | ||
+ | fi | ||
+ | |||
+ | cd /home/gameserver/engine/team-fortress/orangebox/ | ||
+ | ./srcds_run -game tf -maxplayers 32 +map $MAP | ||
+ | </pre> | ||
== Замечания == | == Замечания == |
Revision as of 16:08, 13 January 2013
Установка
Напишите в терминале строки находящиеся ниже
sudo apt-get install lib32gcc1 (for 64-bit platform) wget http://www.steampowered.com/download/hldsupdatetool.bin chmod +x hldsupdatetool.bin ./hldsupdatetool.bin type yes ./steam ./steam -command update -game tf -dir .
Запуск
cd orangebox ./srcds_run -game tf +map cp_badlands
Init-script для запуска сервера
#!/bin/bash # # chkconfig 345 80 20 # # Startup script # Gameserver: # Credits: Zack # Version: 1.00 # # # NOTE: # game_type variable indicates what game should be started. # Although this script have this variable, different gametypes cannot be started with it. # Consider to make changes to this script by hand. #variables server_user="gameserver" server_install_path="/home/server" game_name=tf2 startup_command="$game_name-startup.sh" RETVAL=0 # start and stop functions start() { echo "Gameserver will be running under user $server_user" echo "Starting gameserver..." chown -R $server_user:$server_user $server_install_path su - $server_user -c "$server_install_path/$startup_command > /dev/null 2>&1 &" RETVAL=$? return $RETVAL } stop() { PID=`ps ax | grep ucc-bin | grep -v grep | awk '{print $1}'` if [ "$PID" != "" ] then echo "Stopping gameserver (PID $PID)..." kill -9 $PID sleep 2 else echo "Gameserver is already stopped" fi } status() { PID=`ps ax | grep ucc-bin |grep -v grep | awk '{print $1}'` if [ "$PID" != "" ] then echo "Gameserver is running and have pid $PID" else echo "Gameserver is stopped" fi } case "$1" in start) start ;; stop) stop ;; restart) stop sleep 2 start ;; status) status ;; *) echo "Usage: $0 {start|stop|restart}" exit 1 esac exit $RETVAL
- В директории с сервером лежит скрипт для запуска сервера, который вызывает инит скрипт. Пример скрипта:
#!/bin/bash if [ "$1" != "" ]; then MAP=$1 else MAP='mvm_mannworks' fi cd /home/gameserver/engine/team-fortress/orangebox/ ./srcds_run -game tf -maxplayers 32 +map $MAP
Замечания
- Выделенный сервер не требует прав суперпользователя (root) для установки и запуска. Рассмотрите установку отдельной учётной записи пользователя для выделенного сервера (hlds).
- Если ваш сервер использует 64-битную (AMD64) версию Linux, возможно вам понадобится установить некоторые пакеты для 32-битной поддержки (binary compatibility). Если у вас установлен дистрибутив Debian, просто напишите в терминале sudo aptitude install ia32-libs, это должно помочь.
- server.cfg находится в папке orangebox/tf/cfg. Для информации по настройке сервера посмотрите Dedicated server configuration.
- Не забудьте открыть порты 27000-27015 в вашем сетевом экране, если он у вас установлен.