summaryrefslogtreecommitdiff
path: root/nonsystemd/networkmanager/NetworkManager.initd
blob: 4829618da0327a7ca3bea1894ebb8129d34611b9 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/openrc-run
# Copyright (c) 2008 Saleem Abdulrasool <compnerd@compnerd.org>
# Copyright 2013-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

description="NetworkManager daemon. The service is marked as started only \
when a network connection is established."
# supervisor="supervise-daemon"
# command="/usr/bin/NetworkManager"
# command_args="-n"
# pidfile="/run/NetworkManager/NetworkManager.pid"

depend() {
    need dbus
    use logind
    provide net
}

start_pre() {
    checkpath -q -d -m 0755 /run/NetworkManager
}

start() {
    # If we are re-called by a dispatcher event, we want to mark the service
    # as started without starting the daemon again
    yesno "${IN_BACKGROUND}" && return 0

    [ -z "${INACTIVE_TIMEOUT}" ] && INACTIVE_TIMEOUT="1"

    ebegin "Starting NetworkManager"
    start-stop-daemon --start --quiet --pidfile /run/NetworkManager/NetworkManager.pid \
        --exec /usr/sbin/NetworkManager -- --pid-file /run/NetworkManager/NetworkManager.pid
    local _retval=$?
    eend "${_retval}"
    if [ "x${_retval}" = 'x0' ] && ! nm-online -t "${INACTIVE_TIMEOUT}"; then
        einfo "Marking NetworkManager as inactive. It will automatically be marked"
        einfo "as started after a network connection has been established."
        mark_service_inactive
    fi
    return "${_retval}"
}

stop() {
    # If we are re-called by a dispatcher event, we want to mark the service
    # as inactive without stopping the daemon
    if yesno "${IN_BACKGROUND}"; then
        mark_service_inactive "${SVCNAME}"
        return 0
    fi

    ebegin "Stopping NetworkManager"
    local pidfile=/run/NetworkManager/NetworkManager.pid
    if [ ! -e "${pidfile}" ] && [ -e /var/run/NetworkManager.pid ]; then
        # Try stopping the pid file used by <0.9.7
        pidfile=/var/run/NetworkManager.pid
        start-stop-daemon --stop --quiet --pidfile "${pidfile}"
        ret=$?
        [ ${ret} = 0 ] && [ -e "${pidfile}" ] && rm "${pidfile}"
        eend ${ret}
    else
        start-stop-daemon --stop --quiet --pidfile "${pidfile}"
        eend $?
    fi
}