#!/bin/sh

#set -x

got_offline_services_without_plesk()
{
	set -- $OFFLINE_SERVICE
	for i in $@; do
		if [ $i != "vzpp-plesk" ]; then
			echo -n "$i "
		fi
	done
}

VZ_CONF="/etc/sysconfig/vz"
if [  -e "$VZ_CONF" ]; then
. $VZ_CONF
else
exit 0
fi

if [ "x$2" != "x" ]; then
	VEID=$2
else
	echo "Usage: $0 template_root_dir veid"
	exit
fi

if [ -z "$OFFLINE_SERVICE" ]; then
# if OFFLINE_SERVICE is not specified, read them manually
	OFFLINE_SERVICE=`ls /etc/vzredirect.d/*.conf | awk '{print(substr($1,1, length($1)-5))}'`
fi

echo "Configuring $VEID offline service(s): `got_offline_services_without_plesk`"
/usr/sbin/vzctl --skiplock set "$VEID" --save --offline_service "`got_offline_services_without_plesk`" || echo ' .. failed' 
