|
| 1 | +System D on Ubuntu |
| 2 | +================== |
| 3 | + |
| 4 | +**IMPORTANT**: These files are written for Unity Cache Server 5.0. |
| 5 | + |
| 6 | +These files are for setting up per-project cache servers on the same machine |
| 7 | +using different ports. This way, the contents of a corrupted server can be |
| 8 | +removed without affecting all other builds. |
| 9 | + |
| 10 | +Setting up multiple instances of the same service with different configurations |
| 11 | +is called *template units* in systemd parlance. |
| 12 | + |
| 13 | + * Fedora Magazine on [Template unit |
| 14 | + files](https://fedoramagazine.org/systemd-template-unit-files/) |
| 15 | + * Digital Ocean on [Template |
| 16 | + specifiers](https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files#creating-instance-units-from-template-unit-files) |
| 17 | + * System D [full unit |
| 18 | + documentation](https://www.freedesktop.org/software/systemd/man/systemd.unit.html) |
| 19 | + |
| 20 | +Setup |
| 21 | +----- |
| 22 | + |
| 23 | +Install Node.js and git. Then check out the cache server itself and install |
| 24 | +it's dependencies: |
| 25 | + |
| 26 | + # From https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions |
| 27 | + curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - |
| 28 | + sudo apt-get install -y nodejs git |
| 29 | + |
| 30 | + # Add unitycache user + homedir |
| 31 | + adduser --system unitycacheserver |
| 32 | + |
| 33 | + # Get server code |
| 34 | + sudo -u unitycacheserver git clone https://github.com/Unity-Technologies/unity-cache-server ~unitycacheserver/unity-cache-server |
| 35 | + cd ~unitycacheserver/unity-cache-server |
| 36 | + sudo -u unitycacheserver npm --cache ~unitycacheserver/.npm install --production |
| 37 | + cd - |
| 38 | + |
| 39 | +Next up is a configuration file for each. Since The cache server does not |
| 40 | +actually accept a configuration file, we will write is as command-line |
| 41 | +arguments passed to each instance, eg. for *GAME NAME* on port 5002, we add a |
| 42 | +file named `5002-GAME-NAME.sh`: |
| 43 | + |
| 44 | + OPTIONS=--port=5002 |
| 45 | + |
| 46 | +The shell-file is read by systemd on service startup and the exported |
| 47 | +`$OPTIONS` is appended to the command-line arguments at startup. Only exception |
| 48 | +is the `--path` argument which is deduced from the base name of the file |
| 49 | +(eg. `5002-GAME-NAME` here) and set uses that as a sub-folder in |
| 50 | +unitycacheserver's home directory, eg. `--path |
| 51 | +/home/unitycacheserver/5002-GAME-NAME`, as it saves a lot of typing and |
| 52 | +copy/paste errors. |
| 53 | + |
| 54 | +Now, move all these files into the `unitycacheserver`-users' directory: |
| 55 | + |
| 56 | + sudo mv unitycacheserver/*.sh ~/unitycacheserver |
| 57 | + sudo chown -R unitycacheserver ~/unitycacheserver/*.sh |
| 58 | + |
| 59 | +Finally, we copy over the systemd-scripts and set up a service instance per |
| 60 | +server we want running: |
| 61 | + |
| 62 | + # Set up server + service-script for each |
| 63 | + cp systemd-services/* /etc/systemd/system/ |
| 64 | + |
| 65 | + # Set up a service instance per server we want |
| 66 | + for i in `ls ~unitycacheserver/*.sh`; do systemctl enable unity-cache-server@`basename $i .sh`; done |
| 67 | + |
| 68 | + # Start all servers by starting the 'parent' service |
| 69 | + systemctl start unity-cache-server |
| 70 | + |
0 commit comments