10-openrc-status 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/sh
  2. # Copyright (c) 2012 Alexandre Rostovtsev
  3. # Released under the 2-clause BSD license.
  4. # Ensures that the NetworkManager OpenRC service is marked as started and
  5. # providing net only when it has a successful connection.
  6. if [ ! -e "/run/openrc/softlevel" ]; then
  7. # OpenRC is not running
  8. exit 0
  9. fi
  10. # Ensure rc-service is in PATH
  11. PATH="${PATH}:/usr/bin:/usr/sbin"
  12. # Exit if the NetworkManager OpenRC service is not running
  13. rc-service NetworkManager status 2>&1 | grep -Eq "status: (starting|started|inactive|stopping)" || exit 0
  14. # Call rc-service in background mode so that the start/stop functions update
  15. # NetworkManager service status to started or inactive instead of actually
  16. # starting or stopping the daemon
  17. export IN_BACKGROUND=YES
  18. case "$2" in
  19. up) nm-online -t 0 -x &&
  20. ! rc-service NetworkManager status 2>&1 | grep -q started &&
  21. exec rc-service NetworkManager start ;;
  22. down) nm-online -t 0 -x ||
  23. rc-service NetworkManager status 2>&1 | grep -q stopped ||
  24. exec rc-service NetworkManager stop ;;
  25. pre-sleep) rc-service NetworkManager status 2>&1 | grep -q stopped ||
  26. exec rc-service NetworkManager stop ;;
  27. esac
  28. exit 0
  29. # vim: set ts=4: