#!/usr/bin/bash

# This script is written to avoid a deadlock on Mageia under systemd during boot.
# NetworkManager will try and restart nscd, but as it requires network.target to be
# complete, it will wait until it's ready.
# Sadly part of making network.target complete is network-up which will in turn
# call nmcli. As NM is busy waiting for the spawnprocess to complete, the nmcli
# will never return. Thus massive delays in boot are encountered.

if [ ! -x /usr/sbin/nscd ]; then
  exit 0
fi

if [ -d /run/systemd/system/ ]; then
  if /bin/systemctl --quiet is-active nscd.service; then
    /bin/systemctl restart nscd.service
    /usr/sbin/nscd -i hosts
  fi
else
  /etc/init.d/nscd condrestart
  /usr/sbin/nscd -i hosts
fi
