A Teeworlds dedicated server with Ubuntu and autostart on boot

I installed it in Xubuntu 12.04 and in a Raspberry PI with Raspbian/Debian.
You'll not need to use 'screen' and Teeworlds will be a service in the system.


Let's go!

Install teeworlds:
sudo apt-get install teeworlds teeworlds-server

Create directory and set the firewall:
sudo mkdir -p /var/games/teeworlds
sudo ufw allow 8303 

Create the Teeworlds config file:
sudo vi /var/games/teeworlds/teeworlds_srv.cfg
Paste these lines, by example:
sv_name Ubuntu Teeworlds Server
sv_motd Welcome!
sv_gametype ctf
sv_warmup 0
sv_map ctf1
sv_max_clients 12
sv_scorelimit 1000
sv_rcon_password your_password_here
sv_timelimit 20
sv_port 8303
sv_external_port 8303
sv_max_clients 12
sv_tournament_mode 0
sv_teamdamage 0
sv_powerups 1
logfile /var/log/teeworlds-server.log
sv_register 1

Set permissions and create log file:
sudo chown root:your_user -R /var/games/teeworlds
sudo chmod 770 -R /var/games/teeworlds
sudo touch /var/log/teeworlds-server.log
sudo chown root:your_user /var/log/teeworlds-server.log 
sudo chmod 770 /var/log/teeworlds-server.log

Know your run-level:
runlevel

Paste this script:
sudo vi /etc/init.d/teeworlds-server
and change:
In Default-Start: 2 3 5 Set your current level (my run-level is 2)
In '--chuid games:games' set your normal user as --chuid your_user:your_user

#! /bin/sh -e
# Copyright (c) 2008 Stas Sushkov (stas@nerd.ro)
# Released under GPL 3.0 (http://creativecommons.org/licenses/GPL/2.0/)
# Author: Stas Sushkov, Sept. 2008
### BEGIN INIT INFO
# Provides:          teeworlds-server
# Required-Start:    $network
# Required-Stop:
# Default-Start:   2 3 5
# Default-Stop:      0 1 6
# Short-Description: teeworlds-server daemon, providing teeworlds server administration
# Description:       Teeworlds is an online multi-player plat‐form 2D shooter.
# teeworlds-server is a server for Teeworlds game.
### END INIT INFO

# Used variables
TWSERVER_BIN_DIR=/usr/games
TWSERVER_DIR=/var/games/teeworlds
TWSERVER_CONFIG=teeworlds_srv.cfg
TWSERVER_NAME=teeworlds-server
TWSERVER_OPTS="-q -f $TWSERVER_DIR/$TWSERVER_CONFIG"
TWSERVER_PIDFILE=$TWSERVER_DIR/$TWSERVER_NAME.pid

# Loading init-functions
. /lib/lsb/init-functions

# Check for missing binaries
test -x $TWSERVER_BIN_DIR/$TWSERVER_NAME || { echo "$TWSERVER_BIN_DIR/$TWSERVER_NAME not installed";
        if [ "$1" = "stop" ]; then exit 0;
 else exit 5; fi; }

# Check for existence of needed config file and read it
test -r $TWSERVER_DIR/$TWSERVER_CONFIG || { echo "$TWSERVER_DIR/$TWSERVER_CONFIG not existing";
 if [ "$1" = "stop" ]; then exit 0;
 else exit 6; fi; }

case "$1" in
 start)
  log_begin_msg "Starting Teeworlds Server..."
  umask 002
  if start-stop-daemon -v --start --background \
   --pidfile $TWSERVER_PIDFILE --make-pidfile \
   -d $TWSERVER_DIR \
   --chuid games:games \
   --exec $TWSERVER_BIN_DIR/$TWSERVER_NAME -- $TWSERVER_OPTS; then
   log_end_msg 0
  else
   log_end_msg $?
  fi
 ;;

 stop)
  log_begin_msg "Stopping Teeworlds Server..."
  if start-stop-daemon --stop \
   --pidfile $TWSERVER_PIDFILE; then
   log_end_msg 0
  else
   log_end_msg $?
  fi
 ;;

 restart|force-reload)
  "$0" stop && "$0" start
 ;;

 *)
 echo "Usage: /etc/init.d/teeworlds-server {start|stop|restart}"
  exit 1
 ;;
esac

exit 0 


Set permissions:
sudo chown root:root /etc/init.d/teeworlds-server
sudo chmod 755 /etc/init.d/teeworlds-server
 
Is all OK? (run as normal user):
/etc/init.d/teeworlds-server start
ps -ef | grep teeworlds 
cat /var/log/teeworlds-server.log
/etc/init.d/teeworlds-server stop

Set the autostart on boot:
sudo update-rc.d teeworlds-server defaults

Now, just enter your IP in the Host address in Teeworlds game and you'll connect to your map.
Thanks to Stas for the info :) Cheers!

2 comments:

  1. Out of curiosity, would this all be possible with a juju charm?

    ReplyDelete
    Replies
    1. Hi! I don't know. I never used it. I'm sorry.

      Delete