![无法在 upstart 作业中执行 nmcli](https://linux22.com/image/978156/%E6%97%A0%E6%B3%95%E5%9C%A8%20upstart%20%E4%BD%9C%E4%B8%9A%E4%B8%AD%E6%89%A7%E8%A1%8C%20nmcli.png)
下面的文件是默认的 network-manager.conf upstart 作业。
$ cat /etc/init/network-manager.conf
# network-manager - network connection manager
#
# The Network Manager daemon manages the system's network connections,
# automatically switching between the best available.
description "network connection manager"
start on (local-filesystems
and started dbus
and static-network-up)
stop on stopping dbus
expect fork
respawn
script
# set $LANG so that messages appearing on the GUI will be translated. See LP: 875017
if [ -r /etc/default/locale ]; then
. /etc/default/locale
export LANG LANGUAGE LC_MESSAGES LC_ALL
fi
exec NetworkManager
end script
我想执行sudo nmcli nm enable false
后网络管理器已启动,但我无法让它在 upstart 作业中工作。我尝试了两种不同的方法。
第一次尝试
$ sudo vi /etc/init/network-manager.override
# network-manager - network connection manager
#
# The Network Manager daemon manages the system's network connections,
# automatically switching between the best available.
description "network connection manager"
start on (local-filesystems
and started dbus
and static-network-up)
stop on stopping dbus
expect fork
respawn
script
# set $LANG so that messages appearing on the GUI will be translated. See LP: 875017
if [ -r /etc/default/locale ]; then
. /etc/default/locale
export LANG LANGUAGE LC_MESSAGES LC_ALL
fi
exec NetworkManager
exec /usr/bin/nmcli nm enable false <-- added this
end script
失败
$ sudo cat /var/log/upstart/network-manager.log
** (process:3453): WARNING **: Could not initialize NMClient /org/freedesktop/NetworkManager: The name org.freedesktop.NetworkManager was not provided by any .service files
** (process:3453): WARNING **: Error enabling/disabling networking: The name org.freedesktop.NetworkManager was not provided by any .service files
第二次尝试
$ sudo vi /etc/init/network-manager-disable.conf
#start on started network-manager <-- tested as well but doesn't work
start on starting network-manager
task
exec /usr/bin/nmcli nm enable false
失败
$ sudo cat /var/log/upstart/network-manager-disable.conf
** (process:2423): WARNING **: Could not initialize NMClient /org/freedesktop/NetworkManager: The name org.freedesktop.NetworkManager was not provided by any .service files
** (process:2423): WARNING **: Error enabling/disabling networking: The name org.freedesktop.NetworkManager was not provided by any .service files
sudo nmcli nm enable false
在命令行上工作正常,但在 upstart 上不行。顺便说一句,我不想要删除网络管理器,例如echo "manual" > /etc/init/network-manager.override
。
有什么建议么?
答案1
也许可以使用第二种方法,但请确保使用started network-manager
事件,然后添加一行pre-start exec sleep 2
。