Skip to content

2025-11-24 14:49

Status:

Tags:

6 - Ubuntu Automation

Creating the taserver shutdown script

If you want to turn the taserver shutdown commands into a convenient script, run the following commands:

cd ~

sudo nano shutdown_taserver.sh

Copy this into the file and save it:

#!/bin/bash
# shutdown_taserver.sh
# Stops all taserver-related processes and cleans leftover state

# Load environment if needed
source ~/taserver-env/bin/activate
export WINEARCH=win32
export WINEPREFIX=$HOME/.wine-taserver

echo "[1/8] Stopping Wine processes..."
wineserver -k
sudo wineserver -k 2>/dev/null
sleep 4

echo "[2/8] Killing taserver game server..."
pkill -f start_game_server_launcher.py 2>/dev/null
sleep 5

echo "[3/8] Killing taserver login server..."
pkill -f start_login_server.py 2>/dev/null
sleep 3

echo "[4/8] Killing taserver firewall..."
pkill -f start_taserver_firewall.py 2>/dev/null
sleep 3

echo "[5/8] Killing Xvfb..."
pkill Xvfb 2>/dev/null
sleep 4

echo "[6/8] Cleaning Wine temp directories..."
rm -rf $WINEPREFIX/drive_c/windows/temp/*
rm -rf $WINEPREFIX/drive_c/users/$USER/Temp/*
rm -rf /tmp/.wine-* 2>/dev/null

echo "[7/8] Cleaning taserver PID/log files..."
rm -f ~/taserver/data/logs/*.lock
rm -f ~/taserver/data/*.pid

echo "[8/8] Cleanup complete."
echo "You can now start taserver normally."

Then, make the script executable with:

sudo chmod +x shutdown_taserver.sh

Then, you run the script with the following command:

cd ~
./shutdown_taserver.sh

Note

Step 1 one may ask you for you password since it uses sudo. Look further in this guide for visudo edits that can circumvent this.

Creating the taserver startup script

If you want to turn the taserver startup commands into a convenient script, run the following commands:

cd ~

sudo nano startup_taserver.sh

Copy this into the file and save it:

#!/bin/bash
# startup_taserver.sh
# Starts taserver (firewall, login, game) in the proper order

# Print debugging
# echo "USER=$USER"
# echo "HOME=$HOME"
# echo "SHELL=$SHELL"
# echo "PATH=$PATH"
# echo "WINEPREFIX=$WINEPREFIX"
# echo "DISPLAY=$DISPLAY"

# Load environment
source ~/taserver-env/bin/activate
export WINEARCH=win32
export WINEPREFIX=$HOME/.wine-taserver

cd ~/taserver

echo "[1/4] Starting firewall..."
sudo /home/taadmin/taserver-env/bin/python /home/taadmin/taserver/start_taserver_firewall.py &
sleep 4

echo "[2/4] Starting login server..."
python3 start_login_server.py &
sleep 4

echo "[3/4] Starting Xvfb..."
pkill Xvfb 2>/dev/null
sleep 2
Xvfb :1 &> xvfb.out & export DISPLAY=":1"
sleep 5

echo "[4/4] Starting game server..."
python3 start_game_server_launcher.py &

echo "taserver startup complete. Check logs in ~/taserver/data/logs/"

# Print debugging
# echo "USER=$USER"
# echo "HOME=$HOME"
# echo "SHELL=$SHELL"
# echo "PATH=$PATH"
# echo "WINEPREFIX=$WINEPREFIX"
# echo "DISPLAY=$DISPLAY"

Then, make the script executable with:

sudo chmod +x startup_taserver.sh

Before running start startup script, I recommend making the following edit to be able to run the firewall script within the startup script without requiring sudo. Do that by running this command:

sudo visudo

That opens the safe sudoers editor. Never edit /etc/sudoers directly.

At the end of the file, add something like:

taadmin ALL=(ALL) NOPASSWD: /home/taadmin/taserver-env/bin/python
taadmin ALL=(ALL) NOPASSWD: /home/taadmin/taserver/start_taserver_firewall.py

Explanation:

  • taadmin → your username.
  • ALL=(ALL) → allows running as any user.
  • NOPASSWD: → don’t prompt for a password.
  • The rest → full path to the Python interpreter and the firewall script.

This ensures only this script can run with sudo without a password, not all commands.

Save and exit the file.

Note

The commands you put in your visudo need to match the exact commands in your startup script. For example, you can't use shortcuts like ~ in one and not the other. If they don't match, it will still prompt you for the password when you run whichever script doesn't exactly match what's in visudo.

Then, you run the script with the following command:

cd ~
./startup_taserver.sh

Note

If you're getting a fatal error (even just occasionally) when the game server script starts that has to do with wineconsole, try increasing the sleep timers in your startup and shutdown scripts. It's likely that they aren't providing enough time for your server to finish some steps before moving to the next step.

On second thought, maybe just try stopping/restarting it a few times. The error seems to pop up randomly for me despite increasing my sleep timers. After a few restarts it just works all of a sudden.

I'm also half-suspicious that this error only happens when I automate the startup/shutdown process, so if you're having a hard time getting past this error, try rebooting your Ubuntu machine and then manually typing the startup commands to see if that works for you.

The wineconsole error that I'm talking about in the note above looks like this:

Failed to find wpid of game server process: ['wineconsole', '/home/taadmin/tribes/Tribes_Ascend_Parting_Gifts/Binaries/Win32/TribesAscend7778.exe', 'server', '-abslog=/home/taadmin/taserver/data/logs/tagameserver7778.log', '-port=7778', '-controlport', '9002', '-noportoffset', '-tamodsconfig', '/home/taadmin/taserver/data/gamesettings/ootb/serverconfig.lua']

Creating a taserver restart script

This script just combines the shutdown_taserver.sh and startup_taserver.sh scripts into one so you can quickly initiate a taserver restart while it's already running:

cd ~

sudo nano restart_taserver.sh

Copy the following into the script and save it:

#!/bin/bash
# restart_taserver.sh
# Stops all taserver-related processes, cleans leftover state, then starts taserver (firewall, login, game) in the proper order

# Shutdown

# Load environment if needed
source ~/taserver-env/bin/activate
export WINEARCH=win32
export WINEPREFIX=$HOME/.wine-taserver

echo "[1/12] Stopping Wine processes..."
wineserver -k
sudo wineserver -k 2>/dev/null
sleep 4

echo "[2/12] Killing taserver game server..."
pkill -f start_game_server_launcher.py 2>/dev/null
sleep 5

echo "[3/12] Killing taserver login server..."
pkill -f start_login_server.py 2>/dev/null
sleep 3

echo "[4/12] Killing taserver firewall..."
pkill -f start_taserver_firewall.py 2>/dev/null
sleep 3

echo "[5/12] Killing Xvfb..."
pkill Xvfb 2>/dev/null
sleep 4

echo "[6/12] Cleaning Wine temp directories..."
rm -rf $WINEPREFIX/drive_c/windows/temp/*
rm -rf $WINEPREFIX/drive_c/users/$USER/Temp/*
rm -rf /tmp/.wine-* 2>/dev/null

echo "[7/12] Cleaning taserver PID/log files..."
rm -f ~/taserver/data/logs/*.lock
rm -f ~/taserver/data/*.pid

echo "[8/12] Cleanup complete."

# Startup

# Load environment
source ~/taserver-env/bin/activate
export WINEARCH=win32
export WINEPREFIX=$HOME/.wine-taserver

cd ~/taserver

echo "[9/12] Starting firewall..."
sudo /home/taadmin/taserver-env/bin/python /home/taadmin/taserver/start_taserver_firewall.py &
sleep 4

echo "[10/12] Starting login server..."
python3 start_login_server.py &
sleep 4

echo "[11/12] Starting Xvfb..."
pkill Xvfb 2>/dev/null
sleep 2
Xvfb :1 &> xvfb.out & export DISPLAY=":1"
sleep 5

echo "[12/12] Starting game server..."
python3 start_game_server_launcher.py &

echo "taserver startup complete. Check logs in ~/taserver/data/logs/"

Then, make the script executable with:

sudo chmod +x restart_taserver.sh

Then, you run the script with the following command:

cd ~
./restart_taserver.sh

Creating a systemd service for taserver startup (and auto-restart)

If you want taserver to automatically start when your Ubuntu server boots up (no login required) and to automatically attempt to restart when it fails, create a systemd service by following these instructions...........

Create a file like this:

sudo nano /etc/systemd/system/taserver.service

Put this in the file and save it:

[Unit]
Description=taserver (Tribes: Ascend server)
After=network.target

[Service]
Type=forking
User=taadmin
Group=taadmin
WorkingDirectory=/home/taadmin
# Run your startup script
ExecStart=/home/taadmin/startup_taserver.sh
# Run your shutdown script for stopping
ExecStop=/home/taadmin/shutdown_taserver.sh
Restart=on-failure
Environment="DISPLAY=:1"
Environment="WINEARCH=win32"
Environment="WINEPREFIX=/home/taadmin/.wine-taserver"

[Install]
WantedBy=multi-user.target

Note

  • Type=forking works because your startup script backgrounds all processes (&).
  • ExecStop points to your cleanup/shutdown script.
  • Environment ensures DISPLAY and WINEPREFIX are always set for Wine.

Reload systemd and enable the service:

sudo systemctl daemon-reload
sudo systemctl enable taserver.service   # start on boot
sudo systemctl start taserver.service    # start now

Check the service status and logs:

systemctl status taserver.service
journalctl -u taserver.service -f

That second command will show your taserver logs live, even though it’s running in the background.

Stopping or restarting the server:

sudo systemctl stop taserver.service
sudo systemctl restart taserver.service

That will run your shutdown_taserver.sh script automatically when stopping the service.

Note

By running taserver as a systemd service, you will not see the live log output on the server's console by default. The logs are still visible in the /taserver/data/logs/ directory and you can view the live output with journalctl -u taserver.service -f.

Note

You do NOT need to log into your Ubuntu server for the systemd service to start. You should be able to just reboot the Ubuntu server and walk away from it. The taserver should start up fine while the Ubuntu server sits on the login screen.

What I'm not sure about is if the systemd service will automatically restart if the server crashes or if it has that intermittent startup error with the game server. Time and testing will tell.

References