NetworkManager.initd 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/openrc-run
  2. # Copyright (c) 2008 Saleem Abdulrasool <compnerd@compnerd.org>
  3. # Copyright 2013-2020 Gentoo Authors
  4. # Distributed under the terms of the GNU General Public License v2
  5. description="NetworkManager daemon. The service is marked as started only \
  6. when a network connection is established."
  7. # supervisor="supervise-daemon"
  8. # command="/usr/bin/NetworkManager"
  9. # command_args="-n"
  10. # pidfile="/run/NetworkManager/NetworkManager.pid"
  11. depend() {
  12. need dbus
  13. use logind
  14. provide net
  15. }
  16. start_pre() {
  17. checkpath -q -d -m 0755 /run/NetworkManager
  18. }
  19. start() {
  20. # If we are re-called by a dispatcher event, we want to mark the service
  21. # as started without starting the daemon again
  22. yesno "${IN_BACKGROUND}" && return 0
  23. [ -z "${INACTIVE_TIMEOUT}" ] && INACTIVE_TIMEOUT="1"
  24. ebegin "Starting NetworkManager"
  25. start-stop-daemon --start --quiet --pidfile /run/NetworkManager/NetworkManager.pid \
  26. --exec /usr/sbin/NetworkManager -- --pid-file /run/NetworkManager/NetworkManager.pid
  27. local _retval=$?
  28. eend "${_retval}"
  29. if [ "x${_retval}" = 'x0' ] && ! nm-online -t "${INACTIVE_TIMEOUT}"; then
  30. einfo "Marking NetworkManager as inactive. It will automatically be marked"
  31. einfo "as started after a network connection has been established."
  32. mark_service_inactive
  33. fi
  34. return "${_retval}"
  35. }
  36. stop() {
  37. # If we are re-called by a dispatcher event, we want to mark the service
  38. # as inactive without stopping the daemon
  39. if yesno "${IN_BACKGROUND}"; then
  40. mark_service_inactive "${SVCNAME}"
  41. return 0
  42. fi
  43. ebegin "Stopping NetworkManager"
  44. local pidfile=/run/NetworkManager/NetworkManager.pid
  45. if [ ! -e "${pidfile}" ] && [ -e /var/run/NetworkManager.pid ]; then
  46. # Try stopping the pid file used by <0.9.7
  47. pidfile=/var/run/NetworkManager.pid
  48. start-stop-daemon --stop --quiet --pidfile "${pidfile}"
  49. ret=$?
  50. [ ${ret} = 0 ] && [ -e "${pidfile}" ] && rm "${pidfile}"
  51. eend ${ret}
  52. else
  53. start-stop-daemon --stop --quiet --pidfile "${pidfile}"
  54. eend $?
  55. fi
  56. }