OpenTTD add-ons
This page is dedicated to some stuff I wrote for easier maintenance of dedicated OpenTTD servers. If you came here looking for my public servers please go to games.pimp.lart.info.
You can get the stuff via cvs from cvs.lart.info:
cvs -d:pserver:cvs@cvs.pimp.lart.info:/cvs co ttd_addons
ttdsrv ( OpenTTD 0.3.6 dietlibc static)
ttdsrv is a wrapper around a dedicated OpenTTD-server. It works best when started from some daemon monitoring tool (like daemontools). That's what ttdsrv does:
- change to the directory containing the OpenTTD-binary and the data files
- chroot() to this directory
- drop group privileges, then drop user privileges
- create a FIFO named .ctrl, if it's not already there
- if there are old logs/errorlogs move them to logname.time()
- set up a pipe and fork()
- the child redirects stdout and stderr to logfiles, and sets up stdin to read from its end of the pipe
- the child loads the latest autosave, if any. (works only with 0.4.0)
- the parent installs sighandlers for SIGTERM and SIGCHLD. It exits on SIGCHLD, and sends a SIGTERM to the children if it catches SIGTERM (which will lead to SIGCHLD and termination, of course)
- the parent opens the control FIFO, and writes everything from the FIFO to the pipe (which provides an interface to control the server)
When running under a daemon monitoring tool ttdsrv will make sure that your server is always up, or brings the server down if you bring it down in the monitoring tool. You can use the logfile and the control FIFO to attach an external program to perform specific actions on special events (greet a joining player, restart server, ...). There are a few things which need to be implemented:
- start (and monitor) an external program to perform additional tasks as mentioned above
ttdsrv can be linked against dietlibc for small program size. It works best if the OpenTTD-server has been linked against dietlibc (you can get my binary till I found time to commit the patch needed for it to compile) -- if you're using a glibc-binary you'll have much fun preparing the chroot environment. The chroot should have the following contents (for the dietlibc binary):
- data
- a directory containing the data files
- dev
- device directory, containing nodes for null and urandom
- etc
- a directory containing the systems resolv.conf
- lang
- a directory containing the language stuff
- openttd
- the OpenTTD binary
- openttd.cfg
- the OpenTTD configuration file
You should create a new user for the ttd-server, and then start ttdsrv with `ttdsrv uid gid chroot-directory log errlog'; log is the redirected stdout, errlog the redirected stderr. Choose any name for errlog, but stick to `log' as file for the default log if you'd like to use ttdconsole.
ttdconsole
ttdconsole is a simple implementation of a console to control servers started using ttdsrv mentioned above. You just call it with the data directory as only argument. ttdconsole expects to find the logfile as `log' in the data directory.