Naf*_*Kay 6 networking linux ubuntu
每当计算机重新启动时,我都试图启动依赖于网络启动的服务。我有几个问题:
这可以从 /etc/init.d 脚本轻松实现吗?我试过在这里创建一个脚本(符合标准),但我真的很怀疑它甚至在启动时运行,更不用说工作了。当我手动测试它时,它可以工作。
我已经看到了新的 Upstart 服务,但就其实际运作方式而言,我完全一无所知。
如何制作一个在启动时运行的脚本,并在网络启动后运行?如果我可以在连接到无线网络后运行它,那就更好了:)
您可以将文件/etc/init用作模型。例如,这是/etc/init/mountall-net.conf:
# mountall-net - Mount network filesystems
#
# Send mountall the USR1 signal to inform it to try network filesystems
# again.
description "Mount network filesystems"
start on net-device-up
task
script
PID=$(status mountall 2>/dev/null | sed -e '/,/{s/.*,[^0-9]*//;q};d')
[ -n "$PID" ] && kill -USR1 $PID || true
end script
Run Code Online (Sandbox Code Playgroud)
这是“/etc/init/ufw.conf”:
# ufw - Uncomplicated Firewall
#
# The Uncomplicated Firewall is a front-end for iptables, to make managing a
# Netfilter firewall easier.
description "Uncomplicated firewall"
start on net-device-added INTERFACE=lo
stop on runlevel [!023456]
console output
pre-start exec /lib/ufw/ufw-init start quiet
post-stop exec /lib/ufw/ufw-init stop
Run Code Online (Sandbox Code Playgroud)
后一个文件在 中有一个符号链接/etc/init.d:
$ ls -l /etc/init.d/ufw
lrwxrwxrwx 1 root root 21 2009-11-05 00:14 /etc/init.d/ufw -> /lib/init/upstart-job
Run Code Online (Sandbox Code Playgroud)