#!/usr/bin/bash

cat > /root/ping-sigur.sh << 'EOF'
#!/usr/bin/env bash

HOST="127.0.0.1"
PORT="3308"
TIMEOUT=3

if timeout "$TIMEOUT" bash -c "</dev/tcp/$HOST/$PORT" 2>/dev/null; then
    exit 0
else
	systemctl restart sphinxd.service
    echo "$(hostname --fqdn) Sigur недоступен"
    exit 1
fi
EOF
chmod +x /root/ping-sigur.sh

crontab -l > /root/current_cron
cat /root/current_cron
cat >> /root/current_cron << EOF
*/10 * * * * /root/ping-sigur.sh
EOF
crontab < /root/current_cron
rm -f /root/current_cron
