Difference between revisions of "Linux dedicated server/ru"
(→Init-script для запуска сервера) |
(→Init-script для запуска сервера) |
||
Line 25: | Line 25: | ||
# chkconfig 345 80 20 | # chkconfig 345 80 20 | ||
# | # | ||
− | # Startup script | + | # Startup script |
− | # Gameserver: generic for | + | # Gameserver: generic for srcds_run |
− | # Credits: Zack | + | # Credits: Zack |
− | # Version: 1.00 | + | # Version: 1.00 |
− | # | + | # |
# | # | ||
# NOTE: | # NOTE: | ||
− | # game_type variable indicates what game should be started. | + | # game_type variable indicates what game should be started. Generally, it is just prefix for ACTUAL start script. |
# Consider to make changes to this script by hand. | # Consider to make changes to this script by hand. | ||
− | + | ||
− | + | ||
− | + | ||
− | |||
#variables | #variables | ||
server_user="gameserver" | server_user="gameserver" | ||
− | server_install_path="/home/ | + | server_install_path="/home/gameserver/engine" |
− | game_name=tf2 | + | game_name="tf2" |
startup_command="$game_name-startup.sh" | startup_command="$game_name-startup.sh" | ||
RETVAL=0 | RETVAL=0 | ||
− | + | ||
# start and stop functions | # start and stop functions | ||
start() { | 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() { | stop() { | ||
− | + | PID=`ps axu | grep -v gameserver | grep 1000 | awk '{print $2}'` | |
− | + | if [ "$PID" != "" ] | |
− | + | then | |
− | + | echo "Stopping gameserver (PID $PID)..." | |
− | + | kill -9 $PID | |
− | + | sleep 2 | |
− | + | else | |
− | + | echo "Gameserver is already stopped" | |
− | + | fi | |
} | } | ||
− | + | ||
status() { | status() { | ||
− | + | PID=`ps axu | grep -v gameserver | grep 1000 | awk '{print $2}'` | |
− | + | if [ "$PID" != "" ] | |
− | + | then | |
− | + | echo "Gameserver is running and have pids $PID" | |
− | + | else | |
− | + | echo "Gameserver is stopped" | |
− | + | fi | |
} | } | ||
− | + | ||
− | + | ||
case "$1" in | case "$1" in | ||
start) | start) | ||
Line 88: | Line 87: | ||
restart) | restart) | ||
stop | stop | ||
− | + | sleep 2 | |
start | start | ||
;; | ;; | ||
status) | status) | ||
− | + | status | |
− | + | ;; | |
*) | *) | ||
echo "Usage: $0 {start|stop|restart}" | echo "Usage: $0 {start|stop|restart}" | ||
exit 1 | exit 1 | ||
esac | esac | ||
− | + | ||
exit $RETVAL | exit $RETVAL | ||
− | |||
</pre> | </pre> | ||
Revision as of 16:12, 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: generic for srcds_run # Credits: Zack # Version: 1.00 # # # NOTE: # game_type variable indicates what game should be started. Generally, it is just prefix for ACTUAL start script. # Consider to make changes to this script by hand. #variables server_user="gameserver" server_install_path="/home/gameserver/engine" 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 axu | grep -v gameserver | grep 1000 | awk '{print $2}'` if [ "$PID" != "" ] then echo "Stopping gameserver (PID $PID)..." kill -9 $PID sleep 2 else echo "Gameserver is already stopped" fi } status() { PID=`ps axu | grep -v gameserver | grep 1000 | awk '{print $2}'` if [ "$PID" != "" ] then echo "Gameserver is running and have pids $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 в вашем сетевом экране, если он у вас установлен.