summaryrefslogtreecommitdiff
path: root/net-misc/networkmanager/files/10-openrc-status-r4
blob: e195ccc196874e92314343f0cee14118c449f41d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/sh
# Copyright (c) 2012 Alexandre Rostovtsev
# Released under the 2-clause BSD license.

# Ensures that the NetworkManager OpenRC service is marked as started and
# providing net only when it has a successful connection.

if [ ! -e "/run/openrc/softlevel" ]; then
	# OpenRC is not running
	exit 0
fi

# Ensure rc-service is in PATH
PATH="${PATH}:@EPREFIX@/sbin:@EPREFIX@/usr/sbin"

# Exit if the NetworkManager OpenRC service is not running
rc-service NetworkManager status 2>&1 | grep -Eq "status: (starting|started|inactive|stopping)" || exit 0

# Call rc-service in background mode so that the start/stop functions update
# NetworkManager service status to started or inactive instead of actually
# starting or stopping the daemon
export IN_BACKGROUND=YES

case "$2" in
	up) nm-online -t 0 -x &&
		! rc-service NetworkManager status 2>&1 | grep -q started &&
		exec rc-service NetworkManager start ;;
	down) nm-online -t 0 -x ||
		rc-service NetworkManager status 2>&1 | grep -q stopped ||
		exec rc-service NetworkManager stop ;;
	pre-sleep) rc-service NetworkManager status 2>&1 | grep -q stopped ||
		exec rc-service NetworkManager stop ;;
esac
exit 0
# vim: set ts=4: