Skip to main content
Topic solved
This topic has been marked as solved and requires no further attention.
Topic: How do I make NetworkManager not wait for a connection before it's marked active (Read 1039 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

How do I make NetworkManager not wait for a connection before it's marked active

I just switched from ConnMan to NetworkManager and so far, it's working fine, except that the init script marks it as "inactive" and doesn't unmark it until a connection is made. This seems to screw with multiple other services on default runlevel that require a network management service to start up, including stubby and ntp-client, and when I check after boot, those services are still stopped.

The Arch Wiki seems to mention this, but the instructions for how to solve it are for Systemd, whereas I'm on OpenRC. I should also maybe mention that the INACTIVE_TIMEOUT variable in both the service's init script and /etc/conf.d/NetworkManager is set to only 1 on my system and by default.

Is there a way to change this waiting behavior by editing a NetworkManager config file, or if not, how do I edit the /etc/init.d/NetworkManager init script (below)?

Code: [Select]
#!/usr/bin/openrc-run
# Copyright (c) 2008 Saleem Abdulrasool <[email protected]>
# 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
}

Re: How do I make NetworkManager not wait for a connection before it's marked active

Reply #1
In Artix, most openrc services have been "converted" from start_stop_daemon (ssd) to supervise_daemon (sd). I think stubby-openrc is one of them, so try editing its service file to include this line at the top section:
Code: [Select]
supervise_daemon_args="--respawn-delay 5 --respawn-max 0"
This way, openrc will attempt to restart stubby every 5 seconds until if finally starts. Changing respawn-max to another integer will bail out after so many tries.
Alternatively, commenting out the "need net" directive of those services or changing it to "use net" should also work.

Re: How do I make NetworkManager not wait for a connection before it's marked active

Reply #2
In Artix, most openrc services have been "converted" from start_stop_daemon (ssd) to supervise_daemon (sd). I think stubby-openrc is one of them, so try editing its service file to include this line at the top section:
Code: [Select]
supervise_daemon_args="--respawn-delay 5 --respawn-max 0"
This way, openrc will attempt to restart stubby every 5 seconds until if finally starts. Changing respawn-max to another integer will bail out after so many tries.
Alternatively, commenting out the "need net" directive of those services or changing it to "use net" should also work.

That seems to work for Stubby. However, the messages at boot actually say that ntp-client actually fails. Here's the logging of my default runlevel from the last boot in /var/log/rc.log:

Code: [Select]
syslog-ng         | * Checking your configfile (/etc/syslog-ng/syslog-ng.conf) ...
NetworkManager    | * Starting NetworkManager ...
bluetoothd        | * Starting bluetoothd ...
 [ ok ]
 [ ok ]
 [ ok ]
syslog-ng         | * Starting syslog-ng ...
 [ ok ]
acpid             | * Starting acpid ...
 [ ok ]
NetworkManager    |Connecting..............     1sConnecting...............    0s [offline]
NetworkManager    | * Marking NetworkManager as inactive. It will automatically be marked
NetworkManager    | * as started after a network connection has been established.
NetworkManager    | * WARNING: NetworkManager has started, but is inactive
stubby            | * WARNING: stubby will start when NetworkManager has started
avahi-daemon      | * Starting avahi-daemon ...
 [ ok ]
netmount          | * WARNING: netmount will start when NetworkManager has started
ntp-client        | * Setting clock via the NTP client 'ntpdate' ...
lxdm              | * Starting lxdm ...
ntp-client        |Exiting, name server cannot be used: Temporary failure in name resolution (-3) * Failed to set clock
 [ !! ]
ntp-client        | * ERROR: ntp-client failed to start
cronie            | * Starting cronie ...
 [ ok ]
 [ ok ]
virtlogd          | * Starting virtlogd ...
 [ ok ]
libvirtd          | * WARNING: libvirtd will start when NetworkManager has started
cupsd             | * Starting cupsd ...
 [ ok ]
local             | * Starting local ...
 [ ok ]

What do I do to remedy this?

Re: How do I make NetworkManager not wait for a connection before it's marked active

Reply #3
In Artix, most openrc services have been "converted" from start_stop_daemon (ssd) to supervise_daemon (sd). I think stubby-openrc is one of them, so try editing its service file to include this line at the top section:
Code: [Select]
supervise_daemon_args="--respawn-delay 5 --respawn-max 0"
This way, openrc will attempt to restart stubby every 5 seconds until if finally starts. Changing respawn-max to another integer will bail out after so many tries.
Alternatively, commenting out the "need net" directive of those services or changing it to "use net" should also work.

Also, here's my /etc/init.d/ntp-client file:

Code: [Select]
#!/usr/bin/openrc-run
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

depend() {
before cron portmap
after net
use dns logger
}

checkconfig() {
if ! type "${NTPCLIENT_CMD}" >/dev/null 2>&1 ; then
eerror "Please edit /etc/conf.d/ntp-client"
eerror "Unable to locate the client command ${NTPCLIENT_CMD}!"
return 1
fi
if [ -z "${NTPCLIENT_OPTS}" ] ; then
eerror "Please edit /etc/conf.d/ntp-client"
eerror "I need to know what server/options to use!"
return 1
fi
return 0
}

start() {
checkconfig || return $?

ebegin "Setting clock via the NTP client '${NTPCLIENT_CMD}'"
"${NTPCLIENT_CMD}" ${NTPCLIENT_OPTS}
eend $? "Failed to set clock"
}

Re: How do I make NetworkManager not wait for a connection before it's marked active

Reply #4
Unless specified otherwise, openrc scripts use s-s-d, so you should convert ntp-client to s-d instead and it'll restart until successful. But first, try changing 'use net' to 'need net' and see if that works.

 

Re: How do I make NetworkManager not wait for a connection before it's marked active

Reply #5
Unless specified otherwise, openrc scripts use s-s-d, so you should convert ntp-client to s-d instead and it'll restart until successful. But first, try changing 'use net' to 'need net' and see if that works.

Changing "after net" to "need net" in the init script seemed to work! Thanks!