# platform = multi_platform_rhel,multi_platform_fedora,multi_platform_ol,multi_platform_rhv,multi_platform_sle,multi_platform_ubuntu
# reboot = false
# strategy = disable
# complexity = low
# disruption = low
{{%- if init_system == "systemd" %}}

{{{ bash_instantiate_variables(VARIABLE) }}}

{{% if OPERATION == "pattern match" %}}
if ! [[ "{{{ VALUE }}}" =~ ${{{ VARIABLE }}} ]]; then
{{% else %}}
if [ ${{{ VARIABLE }}} != {{{ VALUE }}} ]; then
{{%- endif %}}
  SYSTEMCTL_EXEC='/usr/bin/systemctl'
  "$SYSTEMCTL_EXEC" stop '{{{ DAEMONNAME }}}.service'
  "$SYSTEMCTL_EXEC" disable '{{{ DAEMONNAME }}}.service'
  "$SYSTEMCTL_EXEC" mask '{{{ DAEMONNAME }}}.service'
  # Disable socket activation if we have a unit file for it
  if "$SYSTEMCTL_EXEC" -q list-unit-files {{{ DAEMONNAME }}}.socket; then
      "$SYSTEMCTL_EXEC" stop '{{{ DAEMONNAME }}}.socket'
      "$SYSTEMCTL_EXEC" mask '{{{ DAEMONNAME }}}.socket'
  fi
  # The service may not be running because it has been started and failed,
  # so let's reset the state so OVAL checks pass.
  # Service should be 'inactive', not 'failed' after reboot though.
  "$SYSTEMCTL_EXEC" reset-failed '{{{ DAEMONNAME }}}.service' || true
fi
{{%- else %}}

JINJA TEMPLATE ERROR: Unknown init system '{{{ init_system }}}'
{{%- endif %}}
