HOWTO set up Unity cache server
Unity builds can be very slow, if they try to render assets. Running a Unity cache server.
-
install node version 10 url -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
-
install nodejs sudo apt-get install -y nodejs
-
install unity-cache-server with npm sudo npm install unity-cache-server -g
-
create user sudo adduser --system unitycache
;sudo -u unitycache bash
-
dump configuration -
create config folder -
create cache folder -
create hourly cron job to run cleanup sudo crontab -u unitycache -e
-
set up init script to run daemon -
register as a service -
firewall rule: sudo ufw allow in on docker0 from 172.17.0.0/16 to 172.17.0.0/16
-
invoke the unity build with CacheServerIPAddress host:port
$ crontab -l
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
0 * * * * /usr/bin/unity-cache-server-cleanup -P /home/unitycache/cache/ -d
cat unity-cache
#!/bin/sh
### BEGIN INIT INFO
# Provides: unity_cache_server
# Required-Start: $network $remote_fs
# Required-Stop: $network $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Unity Cache Server.
# Description: Unity Cache Server provides fast importing
# of assets that have already been processed by any member of the team.
### END INIT INFO
if [ -f /etc/init.d/functions ] ; then
# Source function library.
. /etc/init.d/functions
else
echo_success () { echo -n " [ OK ] " ; }
echo_failure () { echo -n " [FAILED] " ; }
fi
if [ -f /etc/sysconfig/network ] ; then
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ X\${NETWORKING} = Xno ] exit 0
fi
##
# UnityCacheServer startup script
##
################################################################################
## EDIT FROM HERE
################################################################################
# Installation prefix
CSUSER="unitycache"
################################################################################
## STOP EDITING HERE
################################################################################
# The path that is to be used for the script
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
CACHE_HOME="/home/unitycache"
DAEMON="nohup unity-cache-server --log-level 4 --NODE_CONFIG_DIR=${CACHE_HOME}/config -P ${CACHE_HOME}/cache &"
RETVAL=0
start () {
echo -n "Starting Unity Cache Server: "
cd $CACHE_DIR
su -s /bin/bash -l $CSUSER -c "${DAEMON}"
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo_success
echo
else
echo_failure
echo
exit 1
fi
}
stop () {
echo -n "Stopping Unity Cache Server: "
su -s /bin/bash -l $CSUSER -c "kill $(ps ax | grep unity-cache-server | grep -v grep | awk '{print $1}')"
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo_success
else
echo_failure
fi
echo
}
restart () {
stop
start
}
dostatus() {
ps ax | grep unity-cache-server | grep -v grep | awk '{print $1}'
RETVAL=$?
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
dostatus
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
esac
exit $RETVAL
Edited by Sarah Mount