Mar 242013
 

I couldn’t find a good guide for running teamspeak3 inside of a chroot. And that’s the only way I’d be running it, given that it is a binary blob… This guide is for a Debian system, should probably work for Ubuntu, but it shouldn’t be hard to adjust to other distributions.

  1. Install jailkit. It’s not in Debian, but it provides a working packaging script that you just have to use to build the package yourself:
    # USE REGULAR USER
    apt-get install build-essential fakeroot
    # download jailkit, see the link above. Extract it.
    cd jailkit-2.15
    dpkg-buildpackage -uc -uc -rfakeroot
    sudo dpkg -i ../jailkit*.deb
    
  2. Configure the chroot, and install teamspeak 3 in it. Note that I’m assuming amd64 here.
    # AS ROOT
    mkdir -p /var/chroot/ts3
    cd /var/chroot/ts3
    
    cat << EOF >> start.sh
    #!/bin/bash
    exec ./ts3server_startscript.sh start
    EOF
    chmod +x start.sh
    
    tar xavf $TEAMSPEAKTARGZ # Replace with where you stored the teamspeak download
    adduser --system --home /var/chroot/ts3/./teamspeak3-server_linux-amd64 \
            --disabled-password --group --shell /start.sh ts3
    mkdir teamspeak3-server_linux-amd64/logs
    chown ts3:ts3 teamspeak3-server_linux-amd64 teamspeak3-server_linux-amd64/logs
    
    jk_jailuser -j $PWD ts3
    cat << EOF >> /etc/jailkit/jk_init.ini
    [ts3]
    devices = /dev/null, /dev/random, /dev/urandom, /dev/zero
    paths = /usr/lib/libstdc++.so.6, /etc/localtime
    users = root
    groups = root
    includesections = uidbasics, netbasics, basicshell
    EOF
    jk-init -v -j $PWD ts3
    
  3. Boot script:

    cat << 'EOF' >> /etc/init.d/teamspeak3
    #!/bin/bash
    ### BEGIN INIT INFO
    # Provides:          teamspeak3
    # Required-Start:    $local_fs $remote_fs $network $named
    # Required-Stop:     $local_fs $remote_fs $network $named
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # X-Interactive:     false
    # Short-Description: Start/stop teamspeak 3 server
    ### END INIT INFO
    
    shm=/var/chroot/ts3/dev/shm
    pidfile=/var/chroot/ts3/teamspeak3-server_linux-amd64/ts3server.pid
    
    case "$1" in
    	start)
    		mount -t tmpfs tmpfs $shm
    		su ts3
    		;;
    	stop)
    		echo -n "Stopping the TeamSpeak 3 server"
    		if ( kill -TERM $(cat $pidfile) 2> /dev/null ); then
    			c=1
    			while [ "$c" -le 300 ]; do
    				if ( kill -0 $(cat $pidfile) 2> /dev/null ); then
    					echo -n "."
    					sleep 1
    				else
    					break
    				fi
    				c=$((++c)) 
    			done
    		fi
    		if ( kill -0 $(cat $pidfile) 2> /dev/null ); then
    			echo "Server is not shutting down cleanly - killing"
    			kill -KILL $(cat $pidfile)
    		else
    			echo "done"
    		fi
    		rm $pidfile
    		umount $shm
    		;;
    	*)
    		echo "Usage: $0 {start|stop}"
    		;;
    esac
    EOF
    chmod +x /etc/init.d/teamspeak3
    insserv teamspeak3
    
  4. Recommended: Block outside access to server query, since it’s a telnet based protocol (unencrypted)
    iptables -A INPUT -p tcp ! -s 127.0.0.1 --dport 10011 -j REJECT
    

The point of this guide is to never run the server outside of the chroot. Also I noticed that if the environment wasn’t set up correctly, and the server ran but had strange error messages in the log and didn’t actually work, I had to delete the database file (ts3server.sqlite) and start from scratch.

That’s it, you’re ready to go. Let me know if I missed something.

Mar 112013
 

I recently started using the awesome window manager again. Running into some issues, I wanted to try out the git master version, but not replace my stable installation.

The recipe is:

  1. Build it for installation in $HOME and install it.
    cmake -DCMAKE_INSTALL_PREFIX:PATH=$HOME/opt/awesome
    make install
    
  2. Create a testing wrapper script awesome-xephyr and put it into $PATH:
    #!/bin/bash
    
    if [ -z "$AWESOME" ]; then
    AWESOME=awesome
    fi
    
    $AWESOME -k "$@" || exit 1
    
    Xephyr :1 -ac -br -noreset -screen 1152x720 &
    xephyr_pid=$!
    
    sleep 1
    
    DISPLAY=:1.0 $AWESOME "$@" &
    awesome_pid=$!
    
    echo "Press ENTER to kill Xephyr"
    read a
    kill $awesome_pid
    kill $xephyr_pid
    
  3. Run it
    #!/bin/bash
    
    # ;; means the default lua search path
    export AWESOME_PREFIX=$HOME/opt/awesome
    export RC=$HOME/.config/awesome/git.lua  # copied from .build.../awesomerc.lua and adjust the beautiful.init theme path
    
    LUA_PATH=";;$AWESOME_PREFIX/share/awesome/lib/?.lua;$AWESOME_PREFIX/share/awesome/lib/?/init.lua" \
    AWESOME=$AWESOME_PREFIX/bin/awesome \
    exec awesome-xephyr -c $RC
    

P.S. You can possibly tweak this to work without the make install directly from the .build directory.