#!/usr/bin/sh

set -e

. /etc/tangorc

HOST=$(echo $TANGO_HOST | sed -e "s/:[[:digit:]]*//")

pstree

# These stops and starts seem to be needed, as a work around.
# The first time tango-starter starts, there is an ENOENT, even if the service
# seems active.
#
# See https://gitlab.com/tango-controls/starter/-/issues/25#note_1499130131

systemctl stop tango-starter
systemctl stop tango-accesscontrol
systemctl stop tango-db

sleep 3

systemctl start tango-db

sleep 5

systemctl start tango-accesscontrol

sleep 5

systemctl restart tango-starter

# Give *enough* time to Starter for being able to be ping'ed
sleep 10

pstree

tango_admin --ping-device dserver/Starter/${HOST}
