LoginSignup
2
1

More than 5 years have passed since last update.

[Unity]Unity Cache ServerをSystemdで管理する

Last updated at Posted at 2018-07-18

2018年07月18日時点のUnity Cache Serverはnpmでインストールすると良い感じに使えるらしいが、2017年に導入した時はzipでダウンロードして、サーバーに配置してみたい方法しかなかった気がする。

その際に、SystemdでUnity Cache Serverの起動をコントロールできるようにしたのを記録。
以下を /etc/init.d/unity-cache-server とかでおく。

#!/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
PREFIX="/opt/CacheServer"
# Username to run as
CSUSER="root"

# Arguments
ARGS="--port 8126 --path /data/CacheServer/cache5.0 --size 53687091200 --nolegacy"

################################################################################
## 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

PROG="unity_cache_server"
DAEMON_APP=$PREFIX/RunLinux.sh
DAEMON="nohup $DAEMON_APP $ARGS > /dev/null 2> /dev/null &"
RETVAL=0
PID=""

getpid() {
    PID=`ps ax | grep $PREFIX | grep -v grep | awk '{print $1}'`
}

start () {
    getpid
    if [ $PID ]; then
        echo $"$PROG (pid $PID) is already running."
        return 0
    fi

    echo -n $"Starting $PROG: "
    su -l $CSUSER -c "$DAEMON"
    RETVAL=$?
    if [ $RETVAL -eq 0 ]; then
        echo_success
        echo
    else
        echo_failure
        echo
        exit 1
    fi
}

stop () {
    getpid
    if [ ! $PID ]; then
        echo $"$PROG is not running."
        return 0
    fi
    echo -n $"Stopping $PROG: "
    su -l $CSUSER -c "kill $PID"
    RETVAL=$?
    if [ $RETVAL -eq 0 ]; then
        echo_success
    else
        echo_failure
    fi
    echo
}

restart () {
    stop
    start
}

dostatus() {
    getpid
    if [ $PID ]; then
        echo $"$PROG (pid $PID) is running."
    else
        echo $"$PROG is not running."
    fi
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
    dostatus
    ;;
  restart)
    restart
    ;;
  *)
    echo "Usage: unity_cache_server {start|stop|status|restart}"
    exit 1
esac

exit $RETVAL

あとは service/systemctl とかで操作する。

ネット上のスクリプトコピーして、カスタマイズした記憶だけはある。
ポイントはARGSでキャッシュの保存先を別途マウントしたディスク領域にしていることです。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1