#!/bin/sh -e

if [ -z "$1" ] || ( printf %s "$1" | grep -vq '^[0-9]\+$' ) || [ -z "$2" ] || ( printf %s "$2" | grep -vq '^[0-9]\+$' ) || [ -n "$3" ]; then
    printf 'usage: %s <shard_num> <operator_uid>\n' "$0"
    exit 1
fi

shard_num="$1"
operator_uid="$2"

service_name=$(printf "ptkill.ppcdata%d.operator=%d" "$shard_num" "$operator_uid")
mkdir -v "/etc/sv/$service_name"
ln -sv "/etc/sv/ptkill.template_for_operator/run" "/etc/sv/$service_name/run" 
update-service --add "/etc/sv/$service_name"
sleep 1
sv status "$service_name"
