#!/bin/sh
# @description Stop Rudder from distributing new policies as a server
# @man This is useful when you want to temporarily prevent your Rudder server
# @man from doing any changes on your agents

. "${BASEDIR}/../lib/common.sh"

if is_https_only; then
  echo "HTTPS-only mode is enabled. This command only handles the CFEngine protocol, doing nothing"
  exit 1
fi

# Disable and stop the server
systemctl stop rudder-cf-serverd
systemctl disable rudder-cf-serverd

# Just in case other cf-server were running
if type killall > /dev/null 2> /dev/null; then
  killall cf-serverd 2> /dev/null || true
elif type pidof > /dev/null 2> /dev/null; then
  kill $(pidof cf-serverd 2>/dev/null) 2> /dev/null || true
else
  echo "Could not check for remaining policy server processes outside of the service"
  echo "(install 'pidof' or 'killall' to enable this check)" 
fi
